@@ -34,13 +34,16 @@ public class FastPCAnalysis implements Analysis.Hooks, PCAnalysis {
3434 private final ConcurrentHashMap <Long , ThreadBatch > threadBatches ;
3535 private final Set <String > failedCommits ;
3636 private final boolean printEnabled ;
37+
38+ private final boolean ignorePCChanges ;
3739 private final Path resultsRoot ;
3840
39- public FastPCAnalysis (boolean printEnabled , Path resultsRoot ) {
41+ public FastPCAnalysis (boolean printEnabled , Path resultsRoot , boolean ignorePCChanges ) {
4042 this .printEnabled = printEnabled ;
4143 this .resultsRoot = resultsRoot ;
4244 this .threadBatches = new ConcurrentHashMap <>();
4345 this .failedCommits = ConcurrentHashMap .newKeySet ();
46+ this .ignorePCChanges = ignorePCChanges ;
4447 try {
4548 Files .createDirectories (resultsRoot );
4649 } catch (IOException e ) {
@@ -49,9 +52,19 @@ public FastPCAnalysis(boolean printEnabled, Path resultsRoot) {
4952 }
5053 }
5154
52- private record ThreadBatch (HashMap <String , GroundTruth > groundTruthMapBefore ,
53- HashMap <String , GroundTruth > groundTruthMapAfter ) {
54-
55+ /**
56+ * Prints the given ground truth to console.
57+ *
58+ * @param groundTruth GT to print
59+ * @param commitName The id of the commit for which the GT has been calculated
60+ */
61+ private static void print (GroundTruth groundTruth , String commitName ) {
62+ System .out .println ();
63+ System .out .printf ("***************** %s ******************" , commitName );
64+ System .out .println ();
65+ for (String file : groundTruth .fileGTs ().keySet ()) {
66+ System .out .println (groundTruth .get (file ));
67+ }
5568 }
5669
5770 @ Override
@@ -77,7 +90,7 @@ public void endCommit(Analysis analysis) {
7790 FastPCAnalysis .numProcessed ++;
7891 if (FastPCAnalysis .numProcessed % 1_000 == 0 ) {
7992 Logger .info ("End Processing of Commit ({}): {}" , FastPCAnalysis .numProcessed ,
80- commit .name ());
93+ commit .name ());
8194 }
8295 }
8396
@@ -94,9 +107,9 @@ public void endCommit(Analysis analysis) {
94107
95108 // Complete all new or updated file ground truths
96109 GroundTruth groundTruthBefore = groundTruthMapBefore .getOrDefault (commit .getName (),
97- new GroundTruth (new HashMap <>(), new HashSet <>()));
110+ new GroundTruth (new HashMap <>(), new HashSet <>()));
98111 GroundTruth groundTruthAfter = groundTruthMapAfter .getOrDefault (commit .getName (),
99- new GroundTruth (new HashMap <>(), new HashSet <>()));
112+ new GroundTruth (new HashMap <>(), new HashSet <>()));
100113 if (groundTruthBefore .isEmpty () && groundTruthAfter .isEmpty ()) {
101114 // Return early and do not save any data, if the ground truths are both empty.
102115 // In this case, no changes have been analyzed, and we are not interested in the commit's
@@ -134,7 +147,7 @@ public void endCommit(Analysis analysis) {
134147 String matchingAsCSVAfter = groundTruthAfter .asMatchingCsvString ();
135148
136149 Serde .writeToFile (commitSaveDir .resolve (CODE_VARIABILITY_CSV_BEFORE ),
137- pcAsCSVBefore );
150+ pcAsCSVBefore );
138151 Serde .writeToFile (commitSaveDir .resolve (CODE_VARIABILITY_CSV_AFTER ),
139152 pcAsCSVAfter );
140153
@@ -146,10 +159,10 @@ public void endCommit(Analysis analysis) {
146159 Serde .writeToFile (commitSaveDir .resolve (COMMIT_MESSAGE_FILE ), commit .getFullMessage ());
147160
148161 Optional <String > parentIds = Arrays .stream (commit .getParents ()).map (RevCommit ::getName )
149- .reduce ((s , s2 ) -> s + " " + s2 );
162+ .reduce ((s , s2 ) -> s + " " + s2 );
150163 parentIds .ifPresentOrElse (
151- s -> Serde .writeToFile (commitSaveDir .resolve (COMMIT_PARENTS_FILE ), s ),
152- () -> Serde .writeToFile (commitSaveDir .resolve (COMMIT_PARENTS_FILE ), "" ));
164+ s -> Serde .writeToFile (commitSaveDir .resolve (COMMIT_PARENTS_FILE ), s ),
165+ () -> Serde .writeToFile (commitSaveDir .resolve (COMMIT_PARENTS_FILE ), "" ));
153166
154167 synchronized (FastPCAnalysis .class ) {
155168 Serde .appendText (resultsRoot .resolve (SUCCESS_COMMIT_FILE ), commit .getName () + "\n " );
@@ -186,11 +199,11 @@ public boolean analyzeVariationDiff(Analysis analysis) {
186199 HashMap <String , GroundTruth > groundTruthMapAfter = currentBatch .groundTruthMapAfter ;
187200
188201 GroundTruth groundTruthBefore = groundTruthMapBefore .computeIfAbsent (
189- analysis .getCurrentCommit ().getName (),
190- commit -> new GroundTruth (new HashMap <>(), new HashSet <>()));
202+ analysis .getCurrentCommit ().getName (),
203+ commit -> new GroundTruth (new HashMap <>(), new HashSet <>()));
191204 GroundTruth groundTruthAfter = groundTruthMapAfter .computeIfAbsent (
192- analysis .getCurrentCommit ().getName (),
193- commit -> new GroundTruth (new HashMap <>(), new HashSet <>()));
205+ analysis .getCurrentCommit ().getName (),
206+ commit -> new GroundTruth (new HashMap <>(), new HashSet <>()));
194207 // Show.diff(analysis.getCurrentVariationDiff()).showAndAwait();
195208 // Get the ground truth for this file
196209 String fileNameBefore = analysis .getCurrentPatch ().getFileName (Time .BEFORE );
@@ -206,26 +219,26 @@ public boolean analyzeVariationDiff(Analysis analysis) {
206219 fileGTBefore = null ;
207220 } else {
208221 fileGTBefore = (FileGT .Mutable ) groundTruthBefore .computeIfAbsent (fileNameBefore ,
209- k -> new FileGT .Mutable (fileNameBefore ));
222+ k -> new FileGT .Mutable (fileNameBefore ));
210223 }
211224 final FileGT .Mutable fileGTAfter ;
212225 if (changeType == DiffEntry .ChangeType .DELETE ) {
213226 fileGTAfter = null ;
214227 } else {
215228 fileGTAfter = (FileGT .Mutable ) groundTruthAfter .computeIfAbsent (fileNameAfter ,
216- k -> new FileGT .Mutable (fileNameAfter ));
229+ k -> new FileGT .Mutable (fileNameAfter ));
217230 }
218231
219232 analysis .getCurrentVariationDiff ().forAll (node -> {
220233 try {
221234 // Logger.debug("Node: {}", node);
222235 // If the file is not completely new, we consider the before case
223236 if (!(changeType == DiffEntry .ChangeType .ADD )) {
224- PCAnalysis .analyzeNode (fileGTBefore , node , Time .BEFORE );
237+ PCAnalysis .analyzeNode (fileGTBefore , node , Time .BEFORE , ignorePCChanges );
225238 }
226239 if (!(changeType == DiffEntry .ChangeType .DELETE )) {
227240 // If the file has not been deleted, we consider the after case
228- PCAnalysis .analyzeNode (fileGTAfter , node , Time .AFTER );
241+ PCAnalysis .analyzeNode (fileGTAfter , node , Time .AFTER , ignorePCChanges );
229242 }
230243 } catch (MatchingException e ) {
231244 Logger .error ("unhandled exception while analyzing {} -> {} for commit {}." ,
@@ -240,20 +253,9 @@ public boolean analyzeVariationDiff(Analysis analysis) {
240253 return true ;
241254 }
242255
256+ private record ThreadBatch (HashMap <String , GroundTruth > groundTruthMapBefore ,
257+ HashMap <String , GroundTruth > groundTruthMapAfter ) {
243258
244- /**
245- * Prints the given ground truth to console.
246- *
247- * @param groundTruth GT to print
248- * @param commitName The id of the commit for which the GT has been calculated
249- */
250- private static void print (GroundTruth groundTruth , String commitName ) {
251- System .out .println ();
252- System .out .printf ("***************** %s ******************" , commitName );
253- System .out .println ();
254- for (String file : groundTruth .fileGTs ().keySet ()) {
255- System .out .println (groundTruth .get (file ));
256- }
257259 }
258260
259261}
0 commit comments