3
3
import java .nio .file .Path ;
4
4
import java .nio .file .Paths ;
5
5
import java .util .Arrays ;
6
+ import java .util .Date ;
7
+ import java .util .HashSet ;
6
8
import java .util .List ;
9
+ import java .util .Set ;
7
10
8
11
public class GitUtil {
9
12
13
+ public static void main (String [] args ) {
14
+ Path repoDir = Paths .get ("/data/bowen/data/PTBench-Data/data/2019/quarkusio#gizmo/raw_github" );
15
+ Set <String > mergeSet = new HashSet <>();
16
+ Set <String > bugComs = new HashSet <String >(getComsWithSingleWordMatch (repoDir , "bug" ));
17
+ System .out .println ("# bug coms " + String .valueOf (bugComs .size ()));
18
+ mergeSet .addAll (bugComs );
19
+ Set <String > BugComs = new HashSet <String >(getComsWithSingleWordMatch (repoDir , "Bug" ));
20
+ System .out .println ("# Bug coms " + String .valueOf (BugComs .size ()));
21
+ mergeSet .addAll (BugComs );
22
+ Set <String > fixComs = new HashSet <String >(getComsWithSingleWordMatch (repoDir , "fix" ));
23
+ System .out .println ("# fix coms " + String .valueOf (fixComs .size ()));
24
+ mergeSet .addAll (fixComs );
25
+ Set <String > FixComs = new HashSet <String >(getComsWithSingleWordMatch (repoDir , "Fix" ));
26
+ System .out .println ("# Fix coms " + String .valueOf (FixComs .size ()));
27
+ mergeSet .addAll (FixComs );
28
+ System .out .println ("# merge coms " + String .valueOf (mergeSet .size ()));
29
+ }
30
+
10
31
public static Boolean clone (String repoName , String usrName , Path targetDir ) {
11
32
12
33
if (targetDir .toFile ().exists ()) {
@@ -32,9 +53,28 @@ public static Boolean clone(String repoName, String usrName, Path targetDir) {
32
53
public static List <String > getAllCommitsSha (Path repoDir ) {
33
54
34
55
String cmd = "timeout 300 git --no-pager log --all --pretty=format:\" %H\" " ;
35
-
56
+
57
+ ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , repoDir , 0 );
58
+ if (pr .exitCode == 0 ) {
59
+ return Arrays .asList (pr .out .replace ("\" " , "" ).split ("\n " ));
60
+ } else {
61
+ FileUtil .writeStr2File (pr .out , Paths .get (repoDir .toString (), "getAllCommitsSha_out.txt" ));
62
+ FileUtil .writeStr2File (pr .err , Paths .get (repoDir .toString (), "getAllCommitsSha_err.txt" ));
63
+ // System.out.println("cmd " + cmd + "\n");
64
+ // System.out.println("report \n" + pr.toString());
65
+ return null ;
66
+ }
67
+ }
68
+
69
+ public static List <String > getComsWithSingleWordMatch (Path repoDir , String word ) {
70
+
71
+ String cmd = "timeout 300 git --no-pager log --all --pretty=format:\" %H\" --grep=" + word .trim ();
72
+
36
73
ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , repoDir , 0 );
37
74
if (pr .exitCode == 0 ) {
75
+ if ("" .equals (pr .out .trim ())) {
76
+ return null ;
77
+ }
38
78
return Arrays .asList (pr .out .replace ("\" " , "" ).split ("\n " ));
39
79
} else {
40
80
FileUtil .writeStr2File (pr .out , Paths .get (repoDir .toString (), "getAllCommitsSha_out.txt" ));
0 commit comments