|
1 | 1 | package org.variantsync.diffdetective.variation.diff.view; |
2 | 2 |
|
3 | | -import org.eclipse.jgit.diff.*; |
| 3 | +import org.eclipse.jgit.diff.DiffAlgorithm; |
4 | 4 | import org.tinylog.Logger; |
5 | | -import org.variantsync.diffdetective.diff.git.GitDiffer; |
6 | 5 | import org.variantsync.diffdetective.diff.result.DiffParseException; |
7 | 6 | import org.variantsync.diffdetective.experiments.views.Main; |
8 | 7 | import org.variantsync.diffdetective.util.Assert; |
|
11 | 10 | import org.variantsync.diffdetective.variation.Label; |
12 | 11 | import org.variantsync.diffdetective.variation.diff.*; |
13 | 12 | import org.variantsync.diffdetective.variation.diff.bad.BadVDiff; |
14 | | -import org.variantsync.diffdetective.variation.diff.parse.VariationDiffParser; |
| 13 | +import org.variantsync.diffdetective.variation.diff.construction.JGitDiff; |
15 | 14 | import org.variantsync.diffdetective.variation.tree.VariationTree; |
16 | 15 | import org.variantsync.diffdetective.variation.tree.VariationTreeNode; |
17 | 16 | import org.variantsync.diffdetective.variation.tree.view.TreeView; |
18 | 17 | import org.variantsync.diffdetective.variation.tree.view.relevance.Relevance; |
19 | 18 | import org.variantsync.functjonal.Cast; |
20 | 19 |
|
21 | | -import java.io.*; |
| 20 | +import java.io.IOException; |
22 | 21 | import java.lang.reflect.Array; |
23 | | -import java.nio.charset.StandardCharsets; |
24 | 22 | import java.util.*; |
25 | 23 | import java.util.function.BiPredicate; |
26 | 24 |
|
@@ -72,72 +70,15 @@ public static <L extends Label> BiPredicate<Time, Projection<L>> computeWhenNode |
72 | 70 | * @throws DiffParseException When the text-based diff could not be parsed to a variation diff. |
73 | 71 | */ |
74 | 72 | private static <L extends Label> VariationDiff<DiffLinesLabel> naive(final VariationDiff<L> d, final Relevance rho, final String[] projectionViewText) throws IOException, DiffParseException { |
75 | | -// Logger.info("q = " + q); |
76 | | - final RawText[] text = new RawText[] { |
77 | | - new RawText(projectionViewText[Time.BEFORE.ordinal()].getBytes()), |
78 | | - new RawText(projectionViewText[Time.AFTER.ordinal()].getBytes()) |
79 | | - }; |
80 | | - |
81 | | - // MYERS or HISTOGRAM |
82 | | - final DiffAlgorithm diffAlgorithm = DiffAlgorithm.getAlgorithm(DiffAlgorithm.SupportedAlgorithm.MYERS); |
83 | | - final RawTextComparator comparator = RawTextComparator.DEFAULT; |
84 | | - final EditList diff = diffAlgorithm.diff( |
85 | | - comparator, |
86 | | - text[Time.BEFORE.ordinal()], |
87 | | - text[Time.AFTER.ordinal()] |
88 | | - ); |
89 | | - |
90 | | - String textDiff; |
91 | | - { |
92 | | - final ByteArrayOutputStream os = new ByteArrayOutputStream(); |
93 | | - |
94 | | - /* |
95 | | - Using our own formatter without diff headers (paired with a maximum context (?)) |
96 | | - caused the formatter to crash due to index out of bounds exceptions. |
97 | | - So I guess there is a hidden assumption in the DiffFormatter that expects the header |
98 | | - to be there. |
99 | | -
|
100 | | - As a fix, we also use our own construction of embedding patches into the before file to obtain a full diff. |
101 | | - */ |
102 | | - // final DiffFormatter formatter = makeFormatterWithoutHeader(os); |
103 | | - // formatter.setContext(Integer.MAX_VALUE); // FULL DIFF |
104 | | - final DiffFormatter formatter = new DiffFormatter(os); |
105 | | - |
106 | | - formatter.setDiffAlgorithm(diffAlgorithm); |
107 | | - formatter.setDiffComparator(comparator); |
108 | | - formatter.setOldPrefix(""); |
109 | | - formatter.setNewPrefix(""); |
110 | | - |
111 | | - formatter.format( |
112 | | - diff, |
113 | | - text[Time.BEFORE.ordinal()], |
114 | | - text[Time.AFTER.ordinal()]); |
115 | | - formatter.flush(); |
116 | | - textDiff = os.toString(StandardCharsets.UTF_8); |
117 | | - formatter.close(); |
118 | | - os.close(); |
119 | | - |
120 | | -// Logger.info("Initial Diff\n" + textDiff); |
121 | | - |
122 | | - textDiff = GitDiffer.getFullDiff( |
123 | | - new BufferedReader(new StringReader(projectionViewText[Time.BEFORE.ordinal()])), |
124 | | - new BufferedReader(new StringReader(textDiff)) |
125 | | - ); |
126 | | - |
127 | | - //textDiff = textDiff.replace("\\ No newline at end of file\n", ""); |
128 | | - //textDiff = HUNK_HEADER_REGEX.matcher(textDiff).replaceAll(""); |
129 | | - } |
130 | | -// Logger.info("Full Diff\n" + textDiff); |
131 | 73 | final VariationDiff<DiffLinesLabel> view; |
132 | 74 | try { |
133 | | - view = VariationDiffParser.createVariationDiff(textDiff, Main.VARIATION_DIFF_PARSE_OPTIONS); |
| 75 | + view = JGitDiff.diff(projectionViewText[0], projectionViewText[1], DiffAlgorithm.SupportedAlgorithm.MYERS, Main.VARIATION_DIFF_PARSE_OPTIONS); |
134 | 76 | } catch (DiffParseException e) { |
135 | 77 | Logger.error(""" |
136 | 78 | Could not parse diff obtained with query {} at {}: |
137 | 79 | Diff: |
138 | 80 | """, |
139 | 81 | d.getSource(), rho); |
140 | | - System.out.println(textDiff); |
141 | 82 | throw e; |
142 | 83 | } |
143 | 84 | view.setSource(new ViewSource<>(d, rho)); |
|
0 commit comments