Skip to content

Commit 64ee7dd

Browse files
author
Christof Tinnes
committed
Merge branch 'mining' of github.com:VariantSync/DiffDetective into mining
2 parents e11f6fa + d749c8b commit 64ee7dd

29 files changed

Lines changed: 225 additions & 67 deletions

docs/datasets/emacs.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Project name | Domain | Source code available (**y**es/**n**o)? | Is it a git repository (**y**es/**n**o)? | Repository URL | Clone URL | Estimated number of commits
2+
---|-------------------------|-----------------------------------------|-----------------------------------|--------------------------------------------------------------|------------------------------------------------------------------|---
3+
emacs | text editor | y | y | https://github.com/emacs-mirror/emacs | https://github.com/emacs-mirror/emacs.git | 153,926

runPostprocessing.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
java -cp "target/diffdetective-1.0.0-jar-with-dependencies.jar" org.variantsync.diffdetective.mining.postprocessing.MiningPostprocessing "results/fsg/difftrees_pilot/all_results" "results/compositeCandidates"
2+
echo "runPostprocessing.sh DONE"

runPreprocessing.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
java -cp "mining/lib/DiffDetective-1.0.0-jar-with-dependencies.jar" mining.DiffTreeMiner
1+
java -cp "target/diffdetective-1.0.0-jar-with-dependencies.jar" org.variantsync.diffdetective.mining.DiffTreeMiner
22
echo "runPreprocessing.sh DONE"

src/main/java/org/variantsync/diffdetective/analysis/AnalysisResult.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,15 @@ public AnalysisResult() {
8383
}
8484

8585
public AnalysisResult(final String repoName) {
86-
this(repoName, 0, 0, 0, 0, 0, 0, 0, CommitProcessTime.Unknown(repoName, Long.MAX_VALUE), CommitProcessTime.Unknown(repoName, Long.MIN_VALUE), new DiffTreeSerializeDebugData(), new ExplainedFilterSummary());
86+
this(
87+
repoName,
88+
0, 0, 0, 0,
89+
0,
90+
0, 0,
91+
CommitProcessTime.Unknown(repoName, Long.MAX_VALUE),
92+
CommitProcessTime.Unknown(repoName, Long.MIN_VALUE),
93+
new DiffTreeSerializeDebugData(),
94+
new ExplainedFilterSummary());
8795
}
8896

8997
public AnalysisResult(

src/main/java/org/variantsync/diffdetective/analysis/HistoryAnalysis.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public record HistoryAnalysis(
3333
public static final int COMMITS_TO_PROCESS_PER_THREAD_DEFAULT = 1000;
3434

3535
@Deprecated
36-
public static void mine(
36+
public static void analyze(
3737
final Repository repo,
3838
final Path outputDir,
3939
final DiffTreeLineGraphExportOptions exportOptions,
@@ -73,7 +73,7 @@ public static void mine(
7373
exportMetadata(outputDir, totalResult);
7474
}
7575

76-
public static void mineAsync(
76+
public static void analyzeAsync(
7777
final Repository repo,
7878
final Path outputDir,
7979
final CommitHistoryAnalysisTaskFactory taskFactory,
@@ -85,7 +85,7 @@ public static void mineAsync(
8585

8686
// prepare tasks
8787
final int nThreads = Diagnostics.INSTANCE.run().getNumberOfAvailableProcessors();
88-
Logger.info(">>> Scheduling asynchronous mining on " + nThreads + " threads.");
88+
Logger.info(">>> Scheduling asynchronous analysis on " + nThreads + " threads.");
8989
clock.start();
9090
final InvocationCounter<RevCommit, RevCommit> numberOfTotalCommits = InvocationCounter.justCount();
9191
final Iterator<CommitHistoryAnalysisTask> tasks = new MappedIterator<>(
@@ -102,7 +102,7 @@ public static void mineAsync(
102102
Logger.info("<<< done in " + clock.printPassedSeconds());
103103

104104
final TaskCompletionMonitor commitSpeedMonitor = new TaskCompletionMonitor(0, TaskCompletionMonitor.LogProgress("commits"));
105-
Logger.info(">>> Run mining");
105+
Logger.info(">>> Run Analysis");
106106
clock.start();
107107
commitSpeedMonitor.start();
108108
try (final ScheduledTasksIterator<AnalysisResult> threads = new ScheduledTasksIterator<>(tasks, nThreads)) {
@@ -144,7 +144,7 @@ public void runAsync() {
144144
final Path repoOutputDir = outputDir.resolve(repo.getRepositoryName());
145145
/// Don't repeat work we already did:
146146
if (!Files.exists(repoOutputDir.resolve(TOTAL_RESULTS_FILE_NAME))) {
147-
mineAsync(repo, repoOutputDir, whatToDo, commitsToProcessPerThread);
147+
analyzeAsync(repo, repoOutputDir, whatToDo, commitsToProcessPerThread);
148148
// mine(repo, repoOutputDir, ExportOptions(repo), MiningStrategy());
149149

150150
postProcessingOnRepositoryOutputDir.accept(repoOutputDir);

src/main/java/org/variantsync/diffdetective/datasets/DefaultDatasets.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
public class DefaultDatasets {
1111
public final static Path DEFAULT_DATASETS_FILE = Path.of("docs", "datasets.md");
12+
public final static Path EMACS = Path.of("docs", "datasets", "emacs.md");
1213

1314
public static List<DatasetDescription> loadDefaultDatasets() {
1415
return loadDatasets(DEFAULT_DATASETS_FILE);

src/main/java/org/variantsync/diffdetective/diff/difftree/DiffNode.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ public boolean insertAfterChild(final DiffNode child, int index) {
335335

336336
public boolean addBeforeChild(final DiffNode child) {
337337
if (!child.isAdd()) {
338+
if (child.beforeParent != null) {
339+
throw new IllegalArgumentException("Given child " + child + " already has a before parent (" + child.beforeParent + ")!");
340+
}
341+
338342
addWithoutDuplicates(beforeChildren, child);
339343
addWithoutDuplicates(childOrder, child);
340344
child.setBeforeParent(this);
@@ -345,6 +349,10 @@ public boolean addBeforeChild(final DiffNode child) {
345349

346350
public boolean addAfterChild(final DiffNode child) {
347351
if (!child.isRem()) {
352+
if (child.afterParent != null) {
353+
throw new IllegalArgumentException("Given child " + child + " already has an after parent (" + child.afterParent + ")!");
354+
}
355+
348356
addWithoutDuplicates(afterChildren, child);
349357
addWithoutDuplicates(childOrder, child);
350358
child.setAfterParent(this);

src/main/java/org/variantsync/diffdetective/diff/difftree/parse/MultiLineMacroParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ ParseResult consume(
100100

101101
return ParseResult.SUCCESS;
102102
} else {
103+
// We either found the ending line of a multiline macro or just a plain line outside of a macro.
103104
final boolean inBeforeMLMacro = beforeMLMacro != null;
104105
final boolean inAfterMLMacro = afterMLMacro != null;
105106

@@ -110,7 +111,7 @@ ParseResult consume(
110111
&& inAfterMLMacro
111112
&& diffType == DiffType.NON
112113
&& beforeMLMacro.equals(afterMLMacro)) {
113-
// We have one single end line for to equal multi line macros -> Merge the nodes.
114+
// We have one single end line for two equal multi line macros -> Merge the nodes.
114115
final DiffNode mlNode = finalizeMLMacro(
115116
lineNo,
116117
line,

src/main/java/org/variantsync/diffdetective/diff/difftree/parse/MultilineMacro.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,22 @@ public boolean equals(Object o) {
7272
if (this == o) return true;
7373
if (o == null || getClass() != o.getClass()) return false;
7474
MultilineMacro that = (MultilineMacro) o;
75-
return startLine == that.startLine && lines.equals(that.lines) && diffType == that.diffType;
75+
return startLine.equals(that.startLine) && lines.equals(that.lines) && diffType == that.diffType;
7676
}
7777

7878
@Override
7979
public int hashCode() {
8080
return Objects.hash(lines, diffType, startLine);
8181
}
82+
83+
@Override
84+
public String toString() {
85+
return "MultilineMacro{" +
86+
"lines=" + lines +
87+
", beforeParent=" + beforeParent +
88+
", afterParent=" + afterParent +
89+
", startLine=" + startLine +
90+
", diffType=" + diffType +
91+
'}';
92+
}
8293
}

src/main/java/org/variantsync/diffdetective/diff/difftree/render/DiffTreeRenderer.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,36 +73,50 @@ public boolean render(PatchDiff patchDiff, final Path directory, final RenderOpt
7373
return render(patchDiff.getDiffTree(), patchDiff, directory, options);
7474
}
7575

76+
public boolean render(PatchDiff patchDiff, final Path directory, final RenderOptions options, final DiffTreeLineGraphExportOptions exportOptions) {
77+
return render(patchDiff.getDiffTree(), patchDiff, directory, options, exportOptions);
78+
}
79+
7680
public boolean render(final DiffTree tree, final GitPatch patch, final Path directory, final RenderOptions options) {
7781
final String treeAndFileName =
7882
patch.getFileName()
7983
+ LineGraphConstants.TREE_NAME_SEPARATOR
8084
+ patch.getCommitHash();
81-
return render(tree, treeAndFileName, directory, options);
85+
return render(tree, treeAndFileName, directory, options, options.toLineGraphOptions());
86+
}
87+
88+
public boolean render(final DiffTree tree, final GitPatch patch, final Path directory, final RenderOptions options, final DiffTreeLineGraphExportOptions exportOptions) {
89+
final String treeAndFileName =
90+
patch.getFileName()
91+
+ LineGraphConstants.TREE_NAME_SEPARATOR
92+
+ patch.getCommitHash();
93+
return render(tree, treeAndFileName, directory, options, exportOptions);
8294
}
8395

8496
public boolean render(final DiffTree tree, final String treeAndFileName, final Path directory) {
8597
return render(tree, treeAndFileName, directory, RenderOptions.DEFAULT);
8698
}
8799

88100
public boolean render(final DiffTree tree, final String treeAndFileName, final Path directory, RenderOptions options) {
89-
return render(tree, treeAndFileName, directory, options,
101+
return render(tree, treeAndFileName, directory, options, options.toLineGraphOptions());
102+
}
103+
104+
public boolean render(final DiffTree tree, final String treeAndFileName, final Path directory, RenderOptions options, final DiffTreeLineGraphExportOptions exportOptions) {
105+
return render(tree, treeAndFileName, directory, options, exportOptions,
90106
(treeName, treeSource) -> LineGraphConstants.LG_TREE_HEADER + " " + treeAndFileName + LineGraphConstants.TREE_NAME_SEPARATOR + "0"
91107
);
92108
}
93109

94110
public boolean renderWithTreeFormat(final DiffTree tree, final String treeAndFileName, final Path directory, RenderOptions options) {
95-
return render(tree, treeAndFileName, directory, options,
111+
return render(tree, treeAndFileName, directory, options, options.toLineGraphOptions(),
96112
(treeName, treeSource) -> options.treeFormat().toLineGraphLine(treeSource)
97113
);
98114
}
99115

100-
private boolean render(final DiffTree tree, final String treeAndFileName, final Path directory, RenderOptions options, BiFunction<String, DiffTreeSource, String> treeHeader) {
101-
final DiffTreeLineGraphExportOptions lgoptions = new DiffTreeLineGraphExportOptions(options.format(), options.treeFormat(), options.nodeFormat(), options.edgeFormat());
102-
116+
private boolean render(final DiffTree tree, final String treeAndFileName, final Path directory, RenderOptions options, DiffTreeLineGraphExportOptions exportOptions, BiFunction<String, DiffTreeSource, String> treeHeader) {
103117
final Path tempFile = directory.resolve(treeAndFileName + ".lg");
104118

105-
final Pair<DiffTreeSerializeDebugData, String> result = LineGraphExport.toLineGraphFormat(tree, lgoptions);
119+
final Pair<DiffTreeSerializeDebugData, String> result = LineGraphExport.toLineGraphFormat(tree, exportOptions);
106120
Assert.assertNotNull(result);
107121
final String lg = treeHeader.apply(treeAndFileName, tree.getSource()) + StringUtils.LINEBREAK + result.second();
108122

0 commit comments

Comments
 (0)