Parcourir la source

Added option to omit diffing lines

By providing the -olt option on startup the algorithm will omit the diffinglines
when saving the commits. This is due to a number of repositories has had very
a lot of commits which made this needed. The lines are not needed when running
with the simplebugfinder but when running with the distancefinder.
ossv il y a 5 ans
Parent
commit
3a6478af51

+ 23 - 3
code/szz/src/main/java/diff/DiffingLines.java

@@ -38,6 +38,8 @@ import org.eclipse.jgit.storage.pack.PackConfig;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 
+import util.Configuration;
+
 /**
  * A diff class that gives the diffing lines between two revisions.
  *
@@ -47,6 +49,8 @@ public class DiffingLines {
 
   private int customContext;
 
+  private boolean omitLineText;
+
   private Repository repo = null;
 
   public class DiffLines {
@@ -89,6 +93,9 @@ public class DiffingLines {
     }
 
     this.customContext = customContext;
+
+    Configuration conf = Configuration.getInstance();
+    this.omitLineText = conf.getOmitLineText();
   }
 
   /**
@@ -164,16 +171,29 @@ public class DiffingLines {
             String[] info = null;
 
             if (firstIndex < first.getBeginA() || last + 1 < i) {
-                info = new String[]{Integer.toString(firstIndex), old.getString(firstIndex)};
+                if (this.omitLineText) {
+                  info = new String[]{Integer.toString(firstIndex), Integer.toString(firstIndex)};
+                } else {
+                  info = new String[]{Integer.toString(firstIndex), old.getString(firstIndex)};
+                }
                 lines.insertions.add(info);
+                
                 firstIndex+=1;
                 secondIndex+=1;
             } else if (firstIndex < first.getEndA()) {
-                info = new String[]{Integer.toString(firstIndex), old.getString(firstIndex)};
+                if (this.omitLineText) {
+                  info = new String[]{Integer.toString(firstIndex), Integer.toString(firstIndex)};
+                } else {
+                  info = new String[]{Integer.toString(firstIndex), old.getString(firstIndex)};
+                }
                 lines.deletions.add(info);
                 firstIndex+=1;
             } else if (secondIndex < first.getEndB()) {
-                info = new String[]{Integer.toString(secondIndex), present.getString(secondIndex)};
+                if (this.omitLineText) {
+                  info = new String[]{Integer.toString(secondIndex), Integer.toString(secondIndex)};
+                } else {
+                  info = new String[]{Integer.toString(secondIndex), present.getString(secondIndex)};
+                }
                 lines.insertions.add(info);
                 secondIndex+=1;
             }

+ 19 - 0
code/szz/src/main/java/util/Configuration.java

@@ -48,6 +48,8 @@ public class Configuration {
   private String resPath = "results";
   private String partialFixPattern = "fix";
 
+  private boolean omitLineText = false;
+
   public String helpHeader = "Commandline options for the SZZ algorithm.";
   public String helpFooter = "The results will be produced in ./results";
 
@@ -122,6 +124,10 @@ public class Configuration {
       instance.setPartialFixPattern(cmd.getOptionValue("p"));
     }
 
+    if (cmd.hasOption("olt")) {
+      instance.setOmitLineText(true);
+    }
+
     return instance;
   }
 
@@ -197,6 +203,14 @@ public class Configuration {
     this.partialFixPattern = pattern;
   }
 
+  public boolean getOmitLineText() {
+    return this.omitLineText;
+  }
+
+  protected void setOmitLineText(boolean omitLineText) {
+    this.omitLineText = omitLineText;
+  }
+
   private static Options getCMDOptions() {
     Options options = new Options();
 
@@ -238,6 +252,11 @@ public class Configuration {
     partialFixPatternOption.setRequired(false);
     options.addOption(partialFixPatternOption);
 
+    Option omitLineTextOption =
+        new Option("olt", false, "Only output the line numbers in the annotation graph.");
+    omitLineTextOption.setRequired(false);
+    options.addOption(omitLineTextOption);
+
     return options;
   }
 }