Skip to content

Commit cf93b89

Browse files
committed
update from larc1
1 parent 6bd7101 commit cf93b89

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

lib/utils/DiffUtil.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public static List<Integer> getChangedLineNumListInOldVersion(String diffStr) {
2929
return changedLineNumList;
3030
}
3131

32-
3332
/**
3433
* the mode can only be "add" or "delete"
34+
*
3535
* @param diffStr
3636
* @param mode
3737
* @return
@@ -47,7 +47,13 @@ public static int getChangedLineCount(String diffStr, String mode) {
4747
}
4848
for (String line : diffStr.split("\n")) {
4949
if (line.startsWith(symbol) && !line.startsWith("---") && !line.startsWith("+++")) {
50-
count++;
50+
// if the line is comment
51+
if (line.substring(1).trim().startsWith("*") || line.substring(1).trim().startsWith("/*")
52+
|| line.substring(1).trim().startsWith("//")) {
53+
continue;
54+
} else {
55+
count++;
56+
}
5157
}
5258
}
5359
return count;

lib/utils/FileUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public boolean accept(File current, String name) {
5252
return directories;
5353
}
5454

55-
public static String readFile2Str(String fpath) {
55+
public static String readFile2Str(Path fpath) {
5656
String content = "";
5757
try {
58-
content = new String(Files.readAllBytes(Paths.get(fpath)));
58+
content = new String(Files.readAllBytes(fpath));
5959
} catch (IOException e) {
6060
System.out.printf("%s not found!", fpath);
6161
e.printStackTrace();

lib/utils/GitUtil.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
public class GitUtil {
1212

13-
public static Boolean clone(String repoName, String usrName, Path targetDir) {
13+
public static Boolean clone(String usrName, String repoName, Path targetDir) {
1414

1515
if (targetDir.toFile().exists()) {
1616
FileUtil.deleteDirectory(targetDir.toFile());
1717
}
1818
targetDir.toFile().mkdirs();
1919

20-
String cmd = "timeout 600 git clone https://github.com/" + repoName + "/" + usrName + " " + targetDir;
20+
String cmd = "timeout 600 git clone https://github.com/" + usrName + "/" + repoName + " " + targetDir;
2121

2222
ProcessUtil.ProcessReporter pr = ProcessUtil.executeCMD(cmd, null, targetDir, 0);
2323
if (pr.exitCode == 0) {
@@ -174,9 +174,6 @@ public static Boolean checkout(Path repoDir, String com, Boolean ifForce) {
174174
}
175175

176176
String defaultBranchNameString = getDefaultBranch(repoDir);
177-
if (defaultBranchNameString == null || defaultBranchNameString == "") {
178-
defaultBranchNameString = "master";
179-
}
180177

181178
String checkoutCMD = null;
182179
if (com == null) { // checkout latest if null
@@ -208,8 +205,13 @@ private static String getDefaultBranch(Path gitDirPath) {
208205
// TODO Auto-generated method stub
209206
String cmdString = "git symbolic-ref refs/remotes/origin/HEAD";
210207
ProcessUtil.ProcessReporter pr = ProcessUtil.executeCMD(cmdString, null, gitDirPath, 0);
208+
211209
// output refs/remotes/origin/master
212-
return pr.out.trim().split("refs/remotes/origin/")[1].trim();
210+
if (pr.out.trim().contains("refs/remotes/origin/")) {
211+
return pr.out.trim().split("refs/remotes/origin/")[1].trim();
212+
} else {
213+
return "master";
214+
}
213215

214216
}
215217

lib/utils/ProcessUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public static ProcessReporter executeCMD(String cmd, String[] envp, Path workDir
7777
}
7878
} catch (Exception e) {
7979
TimeUtil.printCurTimewithMsg(pr.toString());
80+
TimeUtil.printCurTimewithMsg("WorkingDir " + workDir.toString());
8081
e.printStackTrace();
8182
}
8283

0 commit comments

Comments
 (0)