33import java .nio .file .Path ;
44import java .nio .file .Paths ;
55import java .util .Arrays ;
6+ import java .util .Date ;
7+ import java .util .HashSet ;
68import java .util .List ;
9+ import java .util .Set ;
710
811public class GitUtil {
912
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+
1031 public static Boolean clone (String repoName , String usrName , Path targetDir ) {
1132
1233 if (targetDir .toFile ().exists ()) {
@@ -32,9 +53,28 @@ public static Boolean clone(String repoName, String usrName, Path targetDir) {
3253 public static List <String > getAllCommitsSha (Path repoDir ) {
3354
3455 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+
3673 ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , repoDir , 0 );
3774 if (pr .exitCode == 0 ) {
75+ if ("" .equals (pr .out .trim ())) {
76+ return null ;
77+ }
3878 return Arrays .asList (pr .out .replace ("\" " , "" ).split ("\n " ));
3979 } else {
4080 FileUtil .writeStr2File (pr .out , Paths .get (repoDir .toString (), "getAllCommitsSha_out.txt" ));
0 commit comments