comparison src/org/tmatesoft/hg/internal/AnnotateFacility.java @ 551:4ea0351ca878

Better (precise) name for diff facility, tests
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 20 Feb 2013 18:19:52 +0100
parents 83afa680555d
children 45751456b471
comparison
equal deleted inserted replaced
550:c1478cc31f45 551:4ea0351ca878
18 18
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; 19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
20 import static org.tmatesoft.hg.repo.HgRepository.TIP; 20 import static org.tmatesoft.hg.repo.HgRepository.TIP;
21 21
22 import org.tmatesoft.hg.core.Nodeid; 22 import org.tmatesoft.hg.core.Nodeid;
23 import org.tmatesoft.hg.internal.PatchGenerator.LineSequence; 23 import org.tmatesoft.hg.internal.DiffHelper.LineSequence;
24 import org.tmatesoft.hg.repo.HgDataFile; 24 import org.tmatesoft.hg.repo.HgDataFile;
25 import org.tmatesoft.hg.repo.HgInvalidStateException; 25 import org.tmatesoft.hg.repo.HgInvalidStateException;
26 import org.tmatesoft.hg.util.CancelledException; 26 import org.tmatesoft.hg.util.CancelledException;
27 27
28 /** 28 /**
39 public void diff(HgDataFile df, int csetRevIndex1, int csetRevIndex2, BlockInspector insp) { 39 public void diff(HgDataFile df, int csetRevIndex1, int csetRevIndex2, BlockInspector insp) {
40 int fileRevIndex1 = fileRevIndex(df, csetRevIndex1); 40 int fileRevIndex1 = fileRevIndex(df, csetRevIndex1);
41 int fileRevIndex2 = fileRevIndex(df, csetRevIndex2); 41 int fileRevIndex2 = fileRevIndex(df, csetRevIndex2);
42 LineSequence c1 = lines(df, fileRevIndex1); 42 LineSequence c1 = lines(df, fileRevIndex1);
43 LineSequence c2 = lines(df, fileRevIndex2); 43 LineSequence c2 = lines(df, fileRevIndex2);
44 PatchGenerator<LineSequence> pg = new PatchGenerator<LineSequence>(); 44 DiffHelper<LineSequence> pg = new DiffHelper<LineSequence>();
45 pg.init(c1, c2); 45 pg.init(c1, c2);
46 pg.findMatchingBlocks(new BlameBlockInspector(insp, csetRevIndex1, csetRevIndex2)); 46 pg.findMatchingBlocks(new BlameBlockInspector(insp, csetRevIndex1, csetRevIndex2));
47 } 47 }
48 48
49 /** 49 /**
84 if (fileParentRevs[0] != NO_REVISION && fileParentRevs[1] != NO_REVISION) { 84 if (fileParentRevs[0] != NO_REVISION && fileParentRevs[1] != NO_REVISION) {
85 LineSequence p1Lines = lines(df, fileParentRevs[0]); 85 LineSequence p1Lines = lines(df, fileParentRevs[0]);
86 LineSequence p2Lines = lines(df, fileParentRevs[1]); 86 LineSequence p2Lines = lines(df, fileParentRevs[1]);
87 int p1ClogIndex = df.getChangesetRevisionIndex(fileParentRevs[0]); 87 int p1ClogIndex = df.getChangesetRevisionIndex(fileParentRevs[0]);
88 int p2ClogIndex = df.getChangesetRevisionIndex(fileParentRevs[1]); 88 int p2ClogIndex = df.getChangesetRevisionIndex(fileParentRevs[1]);
89 PatchGenerator<LineSequence> pg = new PatchGenerator<LineSequence>(); 89 DiffHelper<LineSequence> pg = new DiffHelper<LineSequence>();
90 pg.init(p2Lines, fileRevLines); 90 pg.init(p2Lines, fileRevLines);
91 EqualBlocksCollector p2MergeCommon = new EqualBlocksCollector(); 91 EqualBlocksCollector p2MergeCommon = new EqualBlocksCollector();
92 pg.findMatchingBlocks(p2MergeCommon); 92 pg.findMatchingBlocks(p2MergeCommon);
93 // 93 //
94 pg.init(p1Lines); 94 pg.init(p1Lines);
107 int soleParent = fileParentRevs[0] == NO_REVISION ? fileParentRevs[1] : fileParentRevs[0]; 107 int soleParent = fileParentRevs[0] == NO_REVISION ? fileParentRevs[1] : fileParentRevs[0];
108 assert soleParent != NO_REVISION; 108 assert soleParent != NO_REVISION;
109 LineSequence parentLines = lines(df, soleParent); 109 LineSequence parentLines = lines(df, soleParent);
110 110
111 int parentChangesetRevIndex = df.getChangesetRevisionIndex(soleParent); 111 int parentChangesetRevIndex = df.getChangesetRevisionIndex(soleParent);
112 PatchGenerator<LineSequence> pg = new PatchGenerator<LineSequence>(); 112 DiffHelper<LineSequence> pg = new DiffHelper<LineSequence>();
113 pg.init(parentLines, fileRevLines); 113 pg.init(parentLines, fileRevLines);
114 pg.findMatchingBlocks(new BlameBlockInspector(insp, parentChangesetRevIndex, csetRevIndex)); 114 pg.findMatchingBlocks(new BlameBlockInspector(insp, parentChangesetRevIndex, csetRevIndex));
115 } 115 }
116 } 116 }
117 117
192 int totalLines(); 192 int totalLines();
193 } 193 }
194 194
195 195
196 196
197 static class BlameBlockInspector extends PatchGenerator.DeltaInspector<LineSequence> { 197 static class BlameBlockInspector extends DiffHelper.DeltaInspector<LineSequence> {
198 private final BlockInspector insp; 198 private final BlockInspector insp;
199 private final int csetOrigin; 199 private final int csetOrigin;
200 private final int csetTarget; 200 private final int csetTarget;
201 private EqualBlocksCollector p2MergeCommon; 201 private EqualBlocksCollector p2MergeCommon;
202 private int csetMergeParent; 202 private int csetMergeParent;
441 } 441 }
442 return String.format("@@ -%d,%d +%d,%d @@", firstRemovedLine(), totalRemovedLines(), firstAddedLine(), totalAddedLines()); 442 return String.format("@@ -%d,%d +%d,%d @@", firstRemovedLine(), totalRemovedLines(), firstAddedLine(), totalAddedLines());
443 } 443 }
444 } 444 }
445 445
446 static class EqualBlocksCollector implements PatchGenerator.MatchInspector<LineSequence> { 446 static class EqualBlocksCollector implements DiffHelper.MatchInspector<LineSequence> {
447 private final IntVector matches = new IntVector(10*3, 2*3); 447 private final IntVector matches = new IntVector(10*3, 2*3);
448 448
449 public void begin(LineSequence s1, LineSequence s2) { 449 public void begin(LineSequence s1, LineSequence s2) {
450 } 450 }
451 451