Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestBlame.java @ 549:83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 19 Feb 2013 21:17:39 +0100 |
parents | ab21ac7dd833 |
children | 45751456b471 |
comparison
equal
deleted
inserted
replaced
548:ab21ac7dd833 | 549:83afa680555d |
---|---|
25 import java.io.PrintStream; | 25 import java.io.PrintStream; |
26 import java.util.Arrays; | 26 import java.util.Arrays; |
27 import java.util.regex.Pattern; | 27 import java.util.regex.Pattern; |
28 | 28 |
29 import org.junit.Assert; | 29 import org.junit.Assert; |
30 import org.junit.Rule; | |
30 import org.junit.Test; | 31 import org.junit.Test; |
32 import org.tmatesoft.hg.console.Bundle.Dump; | |
31 import org.tmatesoft.hg.internal.AnnotateFacility; | 33 import org.tmatesoft.hg.internal.AnnotateFacility; |
32 import org.tmatesoft.hg.internal.AnnotateFacility.AddBlock; | 34 import org.tmatesoft.hg.internal.AnnotateFacility.AddBlock; |
35 import org.tmatesoft.hg.internal.AnnotateFacility.Block; | |
33 import org.tmatesoft.hg.internal.AnnotateFacility.ChangeBlock; | 36 import org.tmatesoft.hg.internal.AnnotateFacility.ChangeBlock; |
34 import org.tmatesoft.hg.internal.AnnotateFacility.DeleteBlock; | 37 import org.tmatesoft.hg.internal.AnnotateFacility.DeleteBlock; |
35 import org.tmatesoft.hg.internal.AnnotateFacility.EqualBlock; | 38 import org.tmatesoft.hg.internal.AnnotateFacility.EqualBlock; |
36 import org.tmatesoft.hg.internal.AnnotateFacility.LineDescriptor; | 39 import org.tmatesoft.hg.internal.AnnotateFacility.LineDescriptor; |
37 import org.tmatesoft.hg.internal.IntMap; | 40 import org.tmatesoft.hg.internal.IntMap; |
43 * | 46 * |
44 * @author Artem Tikhomirov | 47 * @author Artem Tikhomirov |
45 * @author TMate Software Ltd. | 48 * @author TMate Software Ltd. |
46 */ | 49 */ |
47 public class TestBlame { | 50 public class TestBlame { |
51 | |
52 @Rule | |
53 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); | |
48 | 54 |
49 | 55 |
50 @Test | 56 @Test |
51 public void testSingleParentBlame() throws Exception { | 57 public void testSingleParentBlame() throws Exception { |
52 HgRepository repo = new HgLookup().detectFromWorkingDir(); | 58 HgRepository repo = new HgLookup().detectFromWorkingDir(); |
70 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; | 76 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; |
71 HgDataFile df = repo.getFileNode(fname); | 77 HgDataFile df = repo.getFileNode(fname); |
72 OutputParser.Stub op = new OutputParser.Stub(); | 78 OutputParser.Stub op = new OutputParser.Stub(); |
73 ExecHelper eh = new ExecHelper(op, null); | 79 ExecHelper eh = new ExecHelper(op, null); |
74 | 80 |
75 for (int startChangeset : new int[] { 539, 541/*, TIP */}) { | 81 for (int startChangeset : new int[] { TIP, /*539, 541/ *, TIP */}) { |
76 FileAnnotateInspector fa = new FileAnnotateInspector(); | 82 FileAnnotateInspector fa = new FileAnnotateInspector(); |
77 new AnnotateFacility().annotate(df, startChangeset, fa); | 83 new AnnotateFacility().annotate(df, startChangeset, fa); |
78 | 84 |
79 | 85 |
80 op.reset(); | 86 op.reset(); |
84 assertTrue("[sanity]", hgAnnotateLines.length > 0); | 90 assertTrue("[sanity]", hgAnnotateLines.length > 0); |
85 assertEquals("Number of lines reported by native annotate and our impl", hgAnnotateLines.length, fa.lineRevisions.length); | 91 assertEquals("Number of lines reported by native annotate and our impl", hgAnnotateLines.length, fa.lineRevisions.length); |
86 | 92 |
87 for (int i = 0; i < fa.lineRevisions.length; i++) { | 93 for (int i = 0; i < fa.lineRevisions.length; i++) { |
88 int hgAnnotateRevIndex = Integer.parseInt(hgAnnotateLines[i].substring(0, hgAnnotateLines[i].indexOf(':'))); | 94 int hgAnnotateRevIndex = Integer.parseInt(hgAnnotateLines[i].substring(0, hgAnnotateLines[i].indexOf(':'))); |
89 assertEquals(String.format("Revision mismatch for line %d", i+1), hgAnnotateRevIndex, fa.lineRevisions[i]); | 95 errorCollector.assertEquals(String.format("Revision mismatch for line %d", i+1), hgAnnotateRevIndex, fa.lineRevisions[i]); |
90 } | 96 } |
91 } | 97 } |
92 } | 98 } |
93 | 99 |
94 private static String[] splitLines(CharSequence seq) { | 100 private static String[] splitLines(CharSequence seq) { |
114 } while (lineStart < seq.length()); | 120 } while (lineStart < seq.length()); |
115 assert ix == lineCount; | 121 assert ix == lineCount; |
116 return rv; | 122 return rv; |
117 } | 123 } |
118 | 124 |
119 private void leftovers() throws Exception { | 125 |
126 private void aaa() throws Exception { | |
120 HgRepository repo = new HgLookup().detectFromWorkingDir(); | 127 HgRepository repo = new HgLookup().detectFromWorkingDir(); |
121 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; | 128 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; |
122 final int checkChangeset = 539; | 129 final int checkChangeset = 539; |
123 HgDataFile df = repo.getFileNode(fname); | 130 HgDataFile df = repo.getFileNode(fname); |
124 AnnotateFacility af = new AnnotateFacility(); | 131 AnnotateFacility af = new AnnotateFacility(); |
132 DiffOutInspector dump = new DiffOutInspector(System.out); | |
133 System.out.println("541 -> 543"); | |
134 af.annotateChange(df, 543, dump); | |
135 System.out.println("539 -> 541"); | |
136 af.annotateChange(df, 541, dump); | |
125 System.out.println("536 -> 539"); | 137 System.out.println("536 -> 539"); |
126 af.annotateChange(df, checkChangeset, new DiffOutInspector(System.out)); | 138 af.annotateChange(df, checkChangeset, dump); |
127 System.out.println("531 -> 536"); | 139 System.out.println("531 -> 536"); |
128 af.annotateChange(df, 536, new DiffOutInspector(System.out)); | 140 af.annotateChange(df, 536, dump); |
129 System.out.println(" -1 -> 531"); | 141 System.out.println(" -1 -> 531"); |
130 af.annotateChange(df, 531, new DiffOutInspector(System.out)); | 142 af.annotateChange(df, 531, dump); |
131 | 143 |
144 FileAnnotateInspector fai = new FileAnnotateInspector(); | |
145 af.annotate(df, TIP, fai); | |
146 for (int i = 0; i < fai.lineRevisions.length; i++) { | |
147 System.out.printf("%3d: LINE %d\n", fai.lineRevisions[i], i+1); | |
148 } | |
149 } | |
150 | |
151 private void bbb() throws Exception { | |
152 HgRepository repo = new HgLookup().detectFromWorkingDir(); | |
153 final String fname = "src/org/tmatesoft/hg/repo/HgManifest.java"; | |
154 final int checkChangeset = 415; | |
155 HgDataFile df = repo.getFileNode(fname); | |
156 AnnotateFacility af = new AnnotateFacility(); | |
157 DiffOutInspector dump = new DiffOutInspector(System.out); | |
158 System.out.println("413 -> 415"); | |
159 af.diff(df, 413, 415, dump); | |
160 System.out.println("408 -> 415"); | |
161 af.diff(df, 408, 415, dump); | |
162 System.out.println("Combined (with merge):"); | |
163 dump.needRevisions(true); | |
164 af.annotateChange(df, checkChangeset, dump); | |
165 } | |
166 | |
167 private void leftovers() throws Exception { | |
132 IntMap<String> linesOld = new IntMap<String>(100), linesNew = new IntMap<String>(100); | 168 IntMap<String> linesOld = new IntMap<String>(100), linesNew = new IntMap<String>(100); |
133 System.out.println("Changes to old revision:"); | 169 System.out.println("Changes to old revision:"); |
134 for (int i = linesOld.firstKey(), x = linesOld.lastKey(); i < x; i++) { | 170 for (int i = linesOld.firstKey(), x = linesOld.lastKey(); i < x; i++) { |
135 if (linesOld.containsKey(i)) { | 171 if (linesOld.containsKey(i)) { |
136 System.out.println(linesOld.get(i)); | 172 System.out.println(linesOld.get(i)); |
148 public static void main(String[] args) throws Exception { | 184 public static void main(String[] args) throws Exception { |
149 // System.out.println(Arrays.equals(new String[0], splitLines(""))); | 185 // System.out.println(Arrays.equals(new String[0], splitLines(""))); |
150 // System.out.println(Arrays.equals(new String[] { "abc" }, splitLines("abc"))); | 186 // System.out.println(Arrays.equals(new String[] { "abc" }, splitLines("abc"))); |
151 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc"))); | 187 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc"))); |
152 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc\n"))); | 188 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc\n"))); |
153 new TestBlame().testFileAnnotate(); | 189 new TestBlame().bbb(); |
154 } | 190 } |
155 | 191 |
156 static class DiffOutInspector implements AnnotateFacility.BlockInspector { | 192 static class DiffOutInspector implements AnnotateFacility.BlockInspector { |
157 private final PrintStream out; | 193 private final PrintStream out; |
194 private boolean dumpRevs; | |
158 | 195 |
159 DiffOutInspector(PrintStream ps) { | 196 DiffOutInspector(PrintStream ps) { |
160 out = ps; | 197 out = ps; |
161 } | 198 } |
162 | 199 |
200 public void needRevisions(boolean dumpRevs) { | |
201 // Note, true makes output incompatible with 'hg diff' | |
202 this.dumpRevs = dumpRevs; | |
203 } | |
204 | |
205 private void printRevs(Block b) { | |
206 if (dumpRevs) { | |
207 out.printf("[%3d -> %3d] ", b.originChangesetIndex(), b.targetChangesetIndex()); | |
208 } | |
209 } | |
210 | |
163 public void same(EqualBlock block) { | 211 public void same(EqualBlock block) { |
164 // nothing | 212 // nothing |
165 } | 213 } |
166 | 214 |
167 public void deleted(DeleteBlock block) { | 215 public void deleted(DeleteBlock block) { |
216 printRevs(block); | |
168 out.printf("@@ -%d,%d +%d,0 @@\n", block.firstRemovedLine() + 1, block.totalRemovedLines(), block.removedAt()); | 217 out.printf("@@ -%d,%d +%d,0 @@\n", block.firstRemovedLine() + 1, block.totalRemovedLines(), block.removedAt()); |
169 // String[] lines = block.removedLines(); | 218 // String[] lines = block.removedLines(); |
170 // assert lines.length == block.totalRemovedLines(); | 219 // assert lines.length == block.totalRemovedLines(); |
171 // for (int i = 0, ln = block.firstRemovedLine(); i < lines.length; i++, ln++) { | 220 // for (int i = 0, ln = block.firstRemovedLine(); i < lines.length; i++, ln++) { |
172 // linesOld.put(ln, String.format("%3d:---:%s", ln, lines[i])); | 221 // linesOld.put(ln, String.format("%3d:---:%s", ln, lines[i])); |
174 } | 223 } |
175 | 224 |
176 public void changed(ChangeBlock block) { | 225 public void changed(ChangeBlock block) { |
177 // deleted(block); | 226 // deleted(block); |
178 // added(block); | 227 // added(block); |
228 printRevs(block); | |
179 out.printf("@@ -%d,%d +%d,%d @@\n", block.firstRemovedLine() + 1, block.totalRemovedLines(), block.firstAddedLine() + 1, block.totalAddedLines()); | 229 out.printf("@@ -%d,%d +%d,%d @@\n", block.firstRemovedLine() + 1, block.totalRemovedLines(), block.firstAddedLine() + 1, block.totalAddedLines()); |
180 } | 230 } |
181 | 231 |
182 public void added(AddBlock block) { | 232 public void added(AddBlock block) { |
233 printRevs(block); | |
183 out.printf("@@ -%d,0 +%d,%d @@\n", block.insertedAt(), block.firstAddedLine() + 1, block.totalAddedLines()); | 234 out.printf("@@ -%d,0 +%d,%d @@\n", block.insertedAt(), block.firstAddedLine() + 1, block.totalAddedLines()); |
184 // String[] addedLines = block.addedLines(); | 235 // String[] addedLines = block.addedLines(); |
185 // assert addedLines.length == block.totalAddedLines(); | 236 // assert addedLines.length == block.totalAddedLines(); |
186 // for (int i = 0, ln = block.firstAddedLine(), x = addedLines.length; i < x; i++, ln++) { | 237 // for (int i = 0, ln = block.firstAddedLine(), x = addedLines.length; i < x; i++, ln++) { |
187 // linesNew.put(ln, String.format("%3d:+++:%s", ln, addedLines[i])); | 238 // linesNew.put(ln, String.format("%3d:+++:%s", ln, addedLines[i])); |