Skip to content

Commit 259ba1e

Browse files
committed
fix: the parse bug but not really
I could prevent the bug by setting ignoreEmptyLines to false upon parsing. I still do not know what the bug actually is and documented where I found it in the code for now.
1 parent 1d186cc commit 259ba1e

3 files changed

Lines changed: 40 additions & 37 deletions

File tree

src/main/java/org/variantsync/diffdetective/experiments/views/Main.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,50 @@
33
import org.variantsync.diffdetective.AnalysisRunner;
44
import org.variantsync.diffdetective.analysis.Analysis;
55
import org.variantsync.diffdetective.analysis.FilterAnalysis;
6-
import org.variantsync.diffdetective.analysis.PreprocessingAnalysis;
76
import org.variantsync.diffdetective.analysis.StatisticsAnalysis;
87
import org.variantsync.diffdetective.datasets.PatchDiffParseOptions;
98
import org.variantsync.diffdetective.datasets.Repository;
109
import org.variantsync.diffdetective.variation.diff.filter.DiffTreeFilter;
1110
import org.variantsync.diffdetective.variation.diff.parse.DiffTreeParseOptions;
12-
import org.variantsync.diffdetective.variation.diff.transform.CutNonEditedSubtrees;
11+
import org.variantsync.diffdetective.variation.tree.view.query.ArtifactQuery;
1312

1413
import java.io.IOException;
1514
import java.nio.file.Path;
1615
import java.nio.file.Paths;
16+
import java.util.ArrayList;
1717
import java.util.List;
1818

1919
public class Main {
20+
/*
21+
* There is a bug in DiffView::naive when ignoreEmptyLines is set to true under
22+
* some very rare circumstances that I do not know so far. The bug occurred for
23+
* repo: emacs
24+
* commit: 2254b6c09cff8f3a83684fd159289d0e305b0e7d
25+
* patch: "src/alloc.c"
26+
* view_naive
27+
* with the following query.
28+
* What is weird that the parsing only failed when running the analyses but not when extracting the diff to a unit
29+
* test and parsing it there.
30+
* Maybe it has something to do with linebreak or whitespace characters?
31+
*/
32+
private static final ArtifactQuery bugQuery = new ArtifactQuery(" /* Check both of the above conditions, for symbols. */");
33+
public static DiffTreeParseOptions DIFFTREE_PARSE_OPTIONS =
34+
new DiffTreeParseOptions(
35+
true,
36+
false
37+
);
38+
2039
public static Analysis AnalysisFactory(Repository repo, Path repoOutputDir) {
2140
return new Analysis(
2241
"Views Analysis",
23-
List.of(
24-
new PreprocessingAnalysis(new CutNonEditedSubtrees(true)),
42+
new ArrayList<>(List.of(
43+
// new PreprocessingAnalysis(new CutNonEditedSubtrees(true)),
2544
new FilterAnalysis( // filters unwanted trees
2645
DiffTreeFilter.notEmpty()
2746
),
2847
new ViewAnalysis(),
2948
new StatisticsAnalysis()
30-
),
49+
)),
3150
repo,
3251
repoOutputDir
3352
);
@@ -36,23 +55,22 @@ public static Analysis AnalysisFactory(Repository repo, Path repoOutputDir) {
3655
public static void main(String[] args) throws IOException {
3756
final AnalysisRunner.Options defaultOptions = AnalysisRunner.Options.DEFAULT(args);
3857
final AnalysisRunner.Options analysisOptions = new AnalysisRunner.Options(
39-
defaultOptions.repositoriesDirectory(),
58+
Paths.get("..", "DiffDetectiveReplicationDatasets"),
4059
Paths.get("results", "views", "current"),
4160
defaultOptions.datasetsFile(),
4261
repo -> new PatchDiffParseOptions(
4362
PatchDiffParseOptions.DiffStoragePolicy.DO_NOT_REMEMBER,
44-
new DiffTreeParseOptions(
45-
true,
46-
false
47-
)
63+
DIFFTREE_PARSE_OPTIONS
4864
),
4965
defaultOptions.getFilterForRepo(),
5066
true,
5167
false
5268
);
5369

54-
AnalysisRunner.run(analysisOptions, (repository, path) ->
55-
Analysis.forEachCommit(() -> AnalysisFactory(repository, path))
56-
);
70+
AnalysisRunner.run(analysisOptions, (repository, path) -> {
71+
//1b424533675341a2090b79a6ffc420ac6b179ce7
72+
// Analysis.forSinglePatch("2254b6c09cff8f3a83684fd159289d0e305b0e7d", "src/alloc.c", AnalysisFactory(repository, path));
73+
Analysis.forEachCommit(() -> AnalysisFactory(repository, path));
74+
});
5775
}
5876
}

src/main/java/org/variantsync/diffdetective/variation/diff/view/DiffView.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import org.tinylog.Logger;
55
import org.variantsync.diffdetective.diff.git.GitDiffer;
66
import org.variantsync.diffdetective.diff.result.DiffParseException;
7+
import org.variantsync.diffdetective.experiments.views.Main;
78
import org.variantsync.diffdetective.util.Assert;
89
import org.variantsync.diffdetective.util.CollectionUtils;
910
import org.variantsync.diffdetective.variation.diff.*;
1011
import org.variantsync.diffdetective.variation.diff.bad.BadVDiff;
11-
import org.variantsync.diffdetective.variation.diff.parse.DiffTreeParseOptions;
1212
import org.variantsync.diffdetective.variation.diff.parse.DiffTreeParser;
1313
import org.variantsync.diffdetective.variation.tree.VariationTree;
1414
import org.variantsync.diffdetective.variation.tree.VariationTreeNode;
@@ -19,7 +19,6 @@
1919
import java.nio.charset.StandardCharsets;
2020
import java.util.*;
2121
import java.util.function.BiPredicate;
22-
import java.util.function.Consumer;
2322
import java.util.regex.Pattern;
2423

2524
public class DiffView {
@@ -106,31 +105,18 @@ Using our own formatter without diff headers (paired with a maximum context (?))
106105
// Logger.info("Full Diff\n" + textDiff);
107106
final DiffTree view;
108107
try {
109-
view = DiffTreeParser.createDiffTree(textDiff,
110-
new DiffTreeParseOptions(
111-
true,
112-
true
113-
));
108+
view = DiffTreeParser.createDiffTree(textDiff, Main.DIFFTREE_PARSE_OPTIONS);
114109
} catch (DiffParseException e) {
115110
Logger.error("""
116-
Could not parse diff obtained with query {}:
117-
Text before:
118-
{}
119-
120-
Text after:
121-
{}
122-
111+
Could not parse diff obtained with query {} at {}:
123112
Diff:
124-
{}
125113
""",
126-
q,
127-
projectionViewText[0],
128-
projectionViewText[1],
129-
textDiff);
114+
d.getSource(), q);
115+
System.out.println(textDiff);
130116
throw e;
131117
}
132118
view.setSource(new ViewSource(d, q));
133-
// Logger.info("success");
119+
134120
return view;
135121
}
136122

src/test/resources/badvdiff/emacsbug1.diff

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929
do { \
3030
if (!c_symbol_p (ptr)) \
3131
{ \
32-
CHECK_ALLOCATED (); \
33-
CHECK_LIVE (live_symbol_p); \
32+
CHECK_ALLOCATED (); \
33+
CHECK_LIVE (live_symbol_p); \
3434
} \
3535
} while (0) \
3636

37-
#endif
38-
37+
#endif

0 commit comments

Comments
 (0)