forked from reposense/RepoSense
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitLog.java
More file actions
53 lines (42 loc) · 2.17 KB
/
GitLog.java
File metadata and controls
53 lines (42 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package reposense.git;
import static reposense.system.CommandRunner.runCommand;
import java.nio.file.Path;
import java.nio.file.Paths;
import reposense.model.Author;
import reposense.model.RepoConfiguration;
/**
* Contains git log related functionalities.
* Git log is responsible to obtain the commit logs and the authors' info.
*/
public class GitLog {
public static final String COMMIT_INFO_DELIMITER = "(?m)^>>>COMMIT INFO<<<\\n";
private static final String PRETTY_FORMAT_STRING =
"\">>>COMMIT INFO<<<%n%H|%n|%aN|%n|%aE|%n|%cI|%n|%s|%n|%w(0,4,4)%b%w(0,0,0)\"";
/**
* Returns the git commit log info of {@code Author}, in the repository specified in {@code config}.
*/
public static String get(RepoConfiguration config, Author author) {
Path rootPath = Paths.get(config.getRepoRoot());
String command = "git log --no-merges -i ";
command += GitUtil.convertToGitDateRangeArgs(config.getSinceDate(), config.getUntilDate());
command += " --pretty=format:" + PRETTY_FORMAT_STRING + " --shortstat";
command += GitUtil.convertToFilterAuthorArgs(author);
command += GitUtil.convertToGitFormatsArgs(config.getFileTypeManager().getFormats());
command += GitUtil.convertToGitExcludeGlobArgs(rootPath.toFile(), author.getIgnoreGlobList());
return runCommand(rootPath, command);
}
/**
* Returns the git commit log info of {@code Author}, with the files changed, in the repository specified in
* {@code config}.
*/
public static String getWithFiles(RepoConfiguration config, Author author) {
Path rootPath = Paths.get(config.getRepoRoot());
String command = "git log --no-merges -i ";
command += GitUtil.convertToGitDateRangeArgs(config.getSinceDate(), config.getUntilDate());
command += " --pretty=format:" + PRETTY_FORMAT_STRING + " --stat";
command += GitUtil.convertToFilterAuthorArgs(author);
command += GitUtil.convertToGitFormatsArgs(config.getFileTypeManager().getFormats());
command += GitUtil.convertToGitExcludeGlobArgs(rootPath.toFile(), author.getIgnoreGlobList());
return runCommand(rootPath, command);
}
}