comparison src/org/tmatesoft/hg/internal/AnnotateFacility.java @ 544:7f5998a9619d

Refactor PatchGenerator to be generic and welcome sequence of any nature
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 15 Feb 2013 16:48:54 +0100
parents 1e95f48d9886
children 15b406c7cd9d
comparison
equal deleted inserted replaced
543:1e95f48d9886 544:7f5998a9619d
18 18
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; 19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
20 20
21 import org.tmatesoft.hg.core.Nodeid; 21 import org.tmatesoft.hg.core.Nodeid;
22 import org.tmatesoft.hg.internal.PatchGenerator.ChunkSequence; 22 import org.tmatesoft.hg.internal.PatchGenerator.ChunkSequence;
23 import org.tmatesoft.hg.internal.PatchGenerator.LineSequence;
23 import org.tmatesoft.hg.repo.HgDataFile; 24 import org.tmatesoft.hg.repo.HgDataFile;
24 import org.tmatesoft.hg.repo.HgInvalidStateException; 25 import org.tmatesoft.hg.repo.HgInvalidStateException;
25 import org.tmatesoft.hg.repo.HgRepository; 26 import org.tmatesoft.hg.repo.HgRepository;
26 import org.tmatesoft.hg.util.CancelledException; 27 import org.tmatesoft.hg.util.CancelledException;
27 28
31 * @author TMate Software Ltd. 32 * @author TMate Software Ltd.
32 */ 33 */
33 @Experimental(reason="work in progress") 34 @Experimental(reason="work in progress")
34 public class AnnotateFacility { 35 public class AnnotateFacility {
35 36
36 public void annotate(HgDataFile df, int changestRevisionIndex, Inspector insp) { 37 /**
38 * Annotates changes of the file against its parent(s)
39 */
40 public void annotateChange(HgDataFile df, int changestRevisionIndex, Inspector insp) {
37 Nodeid fileRev = df.getRepo().getManifest().getFileRevision(changestRevisionIndex, df.getPath()); 41 Nodeid fileRev = df.getRepo().getManifest().getFileRevision(changestRevisionIndex, df.getPath());
38 int fileRevIndex = df.getRevisionIndex(fileRev); 42 int fileRevIndex = df.getRevisionIndex(fileRev);
39 int[] fileRevParents = new int[2]; 43 int[] fileRevParents = new int[2];
40 df.parents(fileRevIndex, fileRevParents, null, null); 44 df.parents(fileRevIndex, fileRevParents, null, null);
41 if (fileRevParents[0] != NO_REVISION && fileRevParents[1] != NO_REVISION) { 45 if (fileRevParents[0] != NO_REVISION && fileRevParents[1] != NO_REVISION) {
51 try { 55 try {
52 ByteArrayChannel c1, c2; 56 ByteArrayChannel c1, c2;
53 df.content(soleParent, c1 = new ByteArrayChannel()); 57 df.content(soleParent, c1 = new ByteArrayChannel());
54 df.content(fileRevIndex, c2 = new ByteArrayChannel()); 58 df.content(fileRevIndex, c2 = new ByteArrayChannel());
55 int parentChangesetRevIndex = df.getChangesetRevisionIndex(soleParent); 59 int parentChangesetRevIndex = df.getChangesetRevisionIndex(soleParent);
56 PatchGenerator pg = new PatchGenerator(); 60 PatchGenerator<LineSequence> pg = new PatchGenerator<LineSequence>();
57 pg.init(c1.toArray(), c2.toArray()); 61 pg.init(LineSequence.newlines(c1.toArray()), LineSequence.newlines(c2.toArray()));
58 pg.findMatchingBlocks(new BlameBlockInspector(insp)); 62 pg.findMatchingBlocks(new BlameBlockInspector(insp));
59 } catch (CancelledException ex) { 63 } catch (CancelledException ex) {
60 // TODO likely it was bad idea to throw cancelled exception from content() 64 // TODO likely it was bad idea to throw cancelled exception from content()
61 // deprecate and provide alternative? 65 // deprecate and provide alternative?
62 HgInvalidStateException ise = new HgInvalidStateException("ByteArrayChannel never throws CancelledException"); 66 HgInvalidStateException ise = new HgInvalidStateException("ByteArrayChannel never throws CancelledException");
95 String[] removedLines(); 99 String[] removedLines();
96 } 100 }
97 public interface ChangeBlock extends AddBlock, DeleteBlock { 101 public interface ChangeBlock extends AddBlock, DeleteBlock {
98 } 102 }
99 103
100 static class BlameBlockInspector extends PatchGenerator.DeltaInspector { 104 static class BlameBlockInspector extends PatchGenerator.DeltaInspector<LineSequence> {
101 private final Inspector insp; 105 private final Inspector insp;
102 106
103 public BlameBlockInspector(Inspector inspector) { 107 public BlameBlockInspector(Inspector inspector) {
104 assert inspector != null; 108 assert inspector != null;
105 insp = inspector; 109 insp = inspector;