comparison test/org/tmatesoft/hg/test/TestBlame.java @ 555:e623aa2ca526

Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 22 Feb 2013 19:03:25 +0100
parents a5fd757d1b5d
children e55f17a7a195
comparison
equal deleted inserted replaced
554:a5fd757d1b5d 555:e623aa2ca526
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; 35 import org.tmatesoft.hg.internal.AnnotateFacility;
36 import org.tmatesoft.hg.internal.IntVector;
37 import org.tmatesoft.hg.internal.AnnotateFacility.AddBlock; 36 import org.tmatesoft.hg.internal.AnnotateFacility.AddBlock;
38 import org.tmatesoft.hg.internal.AnnotateFacility.Block; 37 import org.tmatesoft.hg.internal.AnnotateFacility.Block;
39 import org.tmatesoft.hg.internal.AnnotateFacility.BlockData; 38 import org.tmatesoft.hg.internal.AnnotateFacility.BlockData;
40 import org.tmatesoft.hg.internal.AnnotateFacility.ChangeBlock; 39 import org.tmatesoft.hg.internal.AnnotateFacility.ChangeBlock;
41 import org.tmatesoft.hg.internal.AnnotateFacility.DeleteBlock; 40 import org.tmatesoft.hg.internal.AnnotateFacility.DeleteBlock;
42 import org.tmatesoft.hg.internal.AnnotateFacility.EqualBlock; 41 import org.tmatesoft.hg.internal.AnnotateFacility.EqualBlock;
43 import org.tmatesoft.hg.internal.AnnotateFacility.LineDescriptor; 42 import org.tmatesoft.hg.internal.FileAnnotation;
43 import org.tmatesoft.hg.internal.FileAnnotation.LineDescriptor;
44 import org.tmatesoft.hg.internal.FileAnnotation.LineInspector;
45 import org.tmatesoft.hg.internal.IntVector;
44 import org.tmatesoft.hg.repo.HgDataFile; 46 import org.tmatesoft.hg.repo.HgDataFile;
45 import org.tmatesoft.hg.repo.HgLookup; 47 import org.tmatesoft.hg.repo.HgLookup;
46 import org.tmatesoft.hg.repo.HgRepository; 48 import org.tmatesoft.hg.repo.HgRepository;
47 49
48 /** 50 /**
61 HgRepository repo = new HgLookup().detectFromWorkingDir(); 63 HgRepository repo = new HgLookup().detectFromWorkingDir();
62 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; 64 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java";
63 final int checkChangeset = 539; 65 final int checkChangeset = 539;
64 HgDataFile df = repo.getFileNode(fname); 66 HgDataFile df = repo.getFileNode(fname);
65 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 67 ByteArrayOutputStream bos = new ByteArrayOutputStream();
66 new AnnotateFacility().annotateChange(df, checkChangeset, new DiffOutInspector(new PrintStream(bos))); 68 new AnnotateFacility().annotateSingleRevision(df, checkChangeset, new DiffOutInspector(new PrintStream(bos)));
67 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+"); 69 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+");
68 ExecHelper eh = new ExecHelper(gp, null); 70 ExecHelper eh = new ExecHelper(gp, null);
69 eh.run("hg", "diff", "-c", String.valueOf(checkChangeset), "-U", "0", fname); 71 eh.run("hg", "diff", "-c", String.valueOf(checkChangeset), "-U", "0", fname);
70 // 72 //
71 String[] apiResult = splitLines(bos.toString()); 73 String[] apiResult = splitLines(bos.toString());
81 OutputParser.Stub op = new OutputParser.Stub(); 83 OutputParser.Stub op = new OutputParser.Stub();
82 ExecHelper eh = new ExecHelper(op, null); 84 ExecHelper eh = new ExecHelper(op, null);
83 85
84 for (int startChangeset : new int[] { 539, 541 /*, TIP */}) { 86 for (int startChangeset : new int[] { 539, 541 /*, TIP */}) {
85 FileAnnotateInspector fa = new FileAnnotateInspector(); 87 FileAnnotateInspector fa = new FileAnnotateInspector();
86 new AnnotateFacility().annotate(df, startChangeset, fa); 88 FileAnnotation.annotate(df, startChangeset, fa);
87 89
88 90
89 op.reset(); 91 op.reset();
90 eh.run("hg", "annotate", "-r", startChangeset == TIP ? "tip" : String.valueOf(startChangeset), fname); 92 eh.run("hg", "annotate", "-r", startChangeset == TIP ? "tip" : String.valueOf(startChangeset), fname);
91 93
157 final int checkChangeset = 539; 159 final int checkChangeset = 539;
158 HgDataFile df = repo.getFileNode(fname); 160 HgDataFile df = repo.getFileNode(fname);
159 AnnotateFacility af = new AnnotateFacility(); 161 AnnotateFacility af = new AnnotateFacility();
160 DiffOutInspector dump = new DiffOutInspector(System.out); 162 DiffOutInspector dump = new DiffOutInspector(System.out);
161 System.out.println("541 -> 543"); 163 System.out.println("541 -> 543");
162 af.annotateChange(df, 543, dump); 164 af.annotateSingleRevision(df, 543, dump);
163 System.out.println("539 -> 541"); 165 System.out.println("539 -> 541");
164 af.annotateChange(df, 541, dump); 166 af.annotateSingleRevision(df, 541, dump);
165 System.out.println("536 -> 539"); 167 System.out.println("536 -> 539");
166 af.annotateChange(df, checkChangeset, dump); 168 af.annotateSingleRevision(df, checkChangeset, dump);
167 System.out.println("531 -> 536"); 169 System.out.println("531 -> 536");
168 af.annotateChange(df, 536, dump); 170 af.annotateSingleRevision(df, 536, dump);
169 System.out.println(" -1 -> 531"); 171 System.out.println(" -1 -> 531");
170 af.annotateChange(df, 531, dump); 172 af.annotateSingleRevision(df, 531, dump);
171 173
172 FileAnnotateInspector fai = new FileAnnotateInspector(); 174 FileAnnotateInspector fai = new FileAnnotateInspector();
173 af.annotate(df, 541, fai); 175 FileAnnotation.annotate(df, 541, fai);
174 for (int i = 0; i < fai.lineRevisions.length; i++) { 176 for (int i = 0; i < fai.lineRevisions.length; i++) {
175 System.out.printf("%3d: LINE %d\n", fai.lineRevisions[i], i+1); 177 System.out.printf("%3d: LINE %d\n", fai.lineRevisions[i], i+1);
176 } 178 }
177 } 179 }
178 180
205 af.annotate(df, TIP, new LineDumpInspector(true), HgIterateDirection.NewToOld); 207 af.annotate(df, TIP, new LineDumpInspector(true), HgIterateDirection.NewToOld);
206 System.out.println(); 208 System.out.println();
207 af.annotate(df, TIP, new LineDumpInspector(false), HgIterateDirection.NewToOld); 209 af.annotate(df, TIP, new LineDumpInspector(false), HgIterateDirection.NewToOld);
208 System.out.println(); 210 System.out.println();
209 FileAnnotateInspector fa = new FileAnnotateInspector(); 211 FileAnnotateInspector fa = new FileAnnotateInspector();
210 af.annotate(df, TIP, fa); 212 FileAnnotation.annotate(df, TIP, fa);
211 for (int i = 0; i < fa.lineRevisions.length; i++) { 213 for (int i = 0; i < fa.lineRevisions.length; i++) {
212 System.out.printf("%d: LINE %d\n", fa.lineRevisions[i], i+1); 214 System.out.printf("%d: LINE %d\n", fa.lineRevisions[i], i+1);
213 } 215 }
214 } 216 }
215 217
307 lineStart = ++lineEnd; 309 lineStart = ++lineEnd;
308 } while (lineStart < seq.length()); 310 } while (lineStart < seq.length());
309 } 311 }
310 } 312 }
311 313
312 private static class FileAnnotateInspector implements AnnotateFacility.LineInspector { 314 private static class FileAnnotateInspector implements LineInspector {
313 private int[] lineRevisions; 315 private int[] lineRevisions;
314 316
315 FileAnnotateInspector() { 317 FileAnnotateInspector() {
316 } 318 }
317 319