comparison test/org/tmatesoft/hg/test/TestBlame.java @ 556:e55f17a7a195

AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 22 Feb 2013 20:21:24 +0100
parents e623aa2ca526
children b9e5ac26dd83
comparison
equal deleted inserted replaced
555:e623aa2ca526 556:e55f17a7a195
30 30
31 import org.junit.Assert; 31 import org.junit.Assert;
32 import org.junit.Rule; 32 import org.junit.Rule;
33 import org.junit.Test; 33 import org.junit.Test;
34 import org.tmatesoft.hg.core.HgIterateDirection; 34 import org.tmatesoft.hg.core.HgIterateDirection;
35 import org.tmatesoft.hg.internal.AnnotateFacility;
36 import org.tmatesoft.hg.internal.AnnotateFacility.AddBlock;
37 import org.tmatesoft.hg.internal.AnnotateFacility.Block;
38 import org.tmatesoft.hg.internal.AnnotateFacility.BlockData;
39 import org.tmatesoft.hg.internal.AnnotateFacility.ChangeBlock;
40 import org.tmatesoft.hg.internal.AnnotateFacility.DeleteBlock;
41 import org.tmatesoft.hg.internal.AnnotateFacility.EqualBlock;
42 import org.tmatesoft.hg.internal.FileAnnotation; 35 import org.tmatesoft.hg.internal.FileAnnotation;
43 import org.tmatesoft.hg.internal.FileAnnotation.LineDescriptor; 36 import org.tmatesoft.hg.internal.FileAnnotation.LineDescriptor;
44 import org.tmatesoft.hg.internal.FileAnnotation.LineInspector; 37 import org.tmatesoft.hg.internal.FileAnnotation.LineInspector;
45 import org.tmatesoft.hg.internal.IntVector; 38 import org.tmatesoft.hg.internal.IntVector;
39 import org.tmatesoft.hg.repo.HgBlameFacility;
46 import org.tmatesoft.hg.repo.HgDataFile; 40 import org.tmatesoft.hg.repo.HgDataFile;
47 import org.tmatesoft.hg.repo.HgLookup; 41 import org.tmatesoft.hg.repo.HgLookup;
48 import org.tmatesoft.hg.repo.HgRepository; 42 import org.tmatesoft.hg.repo.HgRepository;
43 import org.tmatesoft.hg.repo.HgBlameFacility.AddBlock;
44 import org.tmatesoft.hg.repo.HgBlameFacility.Block;
45 import org.tmatesoft.hg.repo.HgBlameFacility.BlockData;
46 import org.tmatesoft.hg.repo.HgBlameFacility.ChangeBlock;
47 import org.tmatesoft.hg.repo.HgBlameFacility.DeleteBlock;
48 import org.tmatesoft.hg.repo.HgBlameFacility.EqualBlock;
49 49
50 /** 50 /**
51 * 51 *
52 * @author Artem Tikhomirov 52 * @author Artem Tikhomirov
53 * @author TMate Software Ltd. 53 * @author TMate Software Ltd.
63 HgRepository repo = new HgLookup().detectFromWorkingDir(); 63 HgRepository repo = new HgLookup().detectFromWorkingDir();
64 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; 64 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java";
65 final int checkChangeset = 539; 65 final int checkChangeset = 539;
66 HgDataFile df = repo.getFileNode(fname); 66 HgDataFile df = repo.getFileNode(fname);
67 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 67 ByteArrayOutputStream bos = new ByteArrayOutputStream();
68 new AnnotateFacility().annotateSingleRevision(df, checkChangeset, new DiffOutInspector(new PrintStream(bos))); 68 new HgBlameFacility().annotateSingleRevision(df, checkChangeset, new DiffOutInspector(new PrintStream(bos)));
69 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+"); 69 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+");
70 ExecHelper eh = new ExecHelper(gp, null); 70 ExecHelper eh = new ExecHelper(gp, null);
71 eh.run("hg", "diff", "-c", String.valueOf(checkChangeset), "-U", "0", fname); 71 eh.run("hg", "diff", "-c", String.valueOf(checkChangeset), "-U", "0", fname);
72 // 72 //
73 String[] apiResult = splitLines(bos.toString()); 73 String[] apiResult = splitLines(bos.toString());
104 104
105 @Test 105 @Test
106 public void testComplexHistoryAnnotate() throws Exception { 106 public void testComplexHistoryAnnotate() throws Exception {
107 HgRepository repo = Configuration.get().find("test-annotate"); 107 HgRepository repo = Configuration.get().find("test-annotate");
108 HgDataFile df = repo.getFileNode("file1"); 108 HgDataFile df = repo.getFileNode("file1");
109 AnnotateFacility af = new AnnotateFacility(); 109 HgBlameFacility af = new HgBlameFacility();
110 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 110 ByteArrayOutputStream bos = new ByteArrayOutputStream();
111 DiffOutInspector dump = new DiffOutInspector(new PrintStream(bos)); 111 DiffOutInspector dump = new DiffOutInspector(new PrintStream(bos));
112 af.annotate(df, TIP, dump, HgIterateDirection.OldToNew); 112 af.annotate(df, TIP, dump, HgIterateDirection.OldToNew);
113 LinkedList<String> apiResult = new LinkedList<String>(Arrays.asList(splitLines(bos.toString()))); 113 LinkedList<String> apiResult = new LinkedList<String>(Arrays.asList(splitLines(bos.toString())));
114 114
115 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+"); 115 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+");
116 ExecHelper eh = new ExecHelper(gp, repo.getWorkingDir()); 116 ExecHelper eh = new ExecHelper(gp, repo.getWorkingDir());
117 System.out.println(Arrays.toString(dump.getReportedTargetRevisions()));
118 for (int cs : dump.getReportedTargetRevisions()) { 117 for (int cs : dump.getReportedTargetRevisions()) {
119 gp.reset(); 118 gp.reset();
120 eh.run("hg", "diff", "-c", String.valueOf(cs), "-U", "0", df.getPath().toString()); 119 eh.run("hg", "diff", "-c", String.valueOf(cs), "-U", "0", df.getPath().toString());
121 for (String expected : splitLines(gp.result())) { 120 for (String expected : splitLines(gp.result())) {
122 if (!apiResult.remove(expected)) { 121 if (!apiResult.remove(expected)) {
156 private void aaa() throws Exception { 155 private void aaa() throws Exception {
157 HgRepository repo = new HgLookup().detectFromWorkingDir(); 156 HgRepository repo = new HgLookup().detectFromWorkingDir();
158 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; 157 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java";
159 final int checkChangeset = 539; 158 final int checkChangeset = 539;
160 HgDataFile df = repo.getFileNode(fname); 159 HgDataFile df = repo.getFileNode(fname);
161 AnnotateFacility af = new AnnotateFacility(); 160 HgBlameFacility af = new HgBlameFacility();
162 DiffOutInspector dump = new DiffOutInspector(System.out); 161 DiffOutInspector dump = new DiffOutInspector(System.out);
163 System.out.println("541 -> 543"); 162 System.out.println("541 -> 543");
164 af.annotateSingleRevision(df, 543, dump); 163 af.annotateSingleRevision(df, 543, dump);
165 System.out.println("539 -> 541"); 164 System.out.println("539 -> 541");
166 af.annotateSingleRevision(df, 541, dump); 165 af.annotateSingleRevision(df, 541, dump);
181 private void bbb() throws Exception { 180 private void bbb() throws Exception {
182 HgRepository repo = new HgLookup().detectFromWorkingDir(); 181 HgRepository repo = new HgLookup().detectFromWorkingDir();
183 final String fname = "src/org/tmatesoft/hg/repo/HgManifest.java"; 182 final String fname = "src/org/tmatesoft/hg/repo/HgManifest.java";
184 final int checkChangeset = 415; 183 final int checkChangeset = 415;
185 HgDataFile df = repo.getFileNode(fname); 184 HgDataFile df = repo.getFileNode(fname);
186 AnnotateFacility af = new AnnotateFacility(); 185 HgBlameFacility af = new HgBlameFacility();
187 DiffOutInspector dump = new DiffOutInspector(System.out); 186 DiffOutInspector dump = new DiffOutInspector(System.out);
188 // System.out.println("413 -> 415"); 187 // System.out.println("413 -> 415");
189 // af.diff(df, 413, 415, dump); 188 // af.diff(df, 413, 415, dump);
190 // System.out.println("408 -> 415"); 189 // System.out.println("408 -> 415");
191 // af.diff(df, 408, 415, dump); 190 // af.diff(df, 408, 415, dump);
197 } 196 }
198 197
199 private void ccc() throws Exception { 198 private void ccc() throws Exception {
200 HgRepository repo = new HgLookup().detect("/home/artem/hg/junit-test-repos/test-annotate/"); 199 HgRepository repo = new HgLookup().detect("/home/artem/hg/junit-test-repos/test-annotate/");
201 HgDataFile df = repo.getFileNode("file1"); 200 HgDataFile df = repo.getFileNode("file1");
202 AnnotateFacility af = new AnnotateFacility(); 201 HgBlameFacility af = new HgBlameFacility();
203 DiffOutInspector dump = new DiffOutInspector(System.out); 202 DiffOutInspector dump = new DiffOutInspector(System.out);
204 dump.needRevisions(true); 203 dump.needRevisions(true);
205 af.annotate(df, TIP, dump, HgIterateDirection.OldToNew); 204 af.annotate(df, TIP, dump, HgIterateDirection.OldToNew);
206 System.out.println(); 205 System.out.println();
207 af.annotate(df, TIP, new LineDumpInspector(true), HgIterateDirection.NewToOld); 206 af.annotate(df, TIP, new LineDumpInspector(true), HgIterateDirection.NewToOld);
221 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc"))); 220 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc")));
222 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc\n"))); 221 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc\n")));
223 new TestBlame().ccc(); 222 new TestBlame().ccc();
224 } 223 }
225 224
226 private static class DiffOutInspector implements AnnotateFacility.BlockInspector { 225 private static class DiffOutInspector implements HgBlameFacility.BlockInspector {
227 private final PrintStream out; 226 private final PrintStream out;
228 private boolean dumpRevs; 227 private boolean dumpRevs;
229 private IntVector reportedRevisionPairs = new IntVector(); 228 private IntVector reportedRevisionPairs = new IntVector();
230 229
231 DiffOutInspector(PrintStream ps) { 230 DiffOutInspector(PrintStream ps) {
324 } 323 }
325 lineRevisions[lineNumber] = changesetRevIndex; 324 lineRevisions[lineNumber] = changesetRevIndex;
326 } 325 }
327 } 326 }
328 327
329 private static class LineDumpInspector implements AnnotateFacility.BlockInspector { 328 private static class LineDumpInspector implements HgBlameFacility.BlockInspector {
330 329
331 private final boolean lineByLine; 330 private final boolean lineByLine;
332 331
333 public LineDumpInspector(boolean lineByLine) { 332 public LineDumpInspector(boolean lineByLine) {
334 this.lineByLine = lineByLine; 333 this.lineByLine = lineByLine;