comparison src/org/tmatesoft/hg/internal/AnnotateFacility.java @ 546:cd78e8b9d7bc

File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 18 Feb 2013 19:19:48 +0100
parents 15b406c7cd9d
children ab21ac7dd833
comparison
equal deleted inserted replaced
545:15b406c7cd9d 546:cd78e8b9d7bc
33 public class AnnotateFacility { 33 public class AnnotateFacility {
34 34
35 /** 35 /**
36 * Annotates changes of the file against its parent(s) 36 * Annotates changes of the file against its parent(s)
37 */ 37 */
38 public void annotateChange(HgDataFile df, int changesetRevisionIndex, Inspector insp) { 38 public void annotateChange(HgDataFile df, int changesetRevisionIndex, BlockInspector insp) {
39 // TODO detect if file is text/binary (e.g. looking for chars < ' ' and not \t\r\n\f 39 // TODO detect if file is text/binary (e.g. looking for chars < ' ' and not \t\r\n\f
40 Nodeid fileRev = df.getRepo().getManifest().getFileRevision(changesetRevisionIndex, df.getPath()); 40 Nodeid fileRev = df.getRepo().getManifest().getFileRevision(changesetRevisionIndex, df.getPath());
41 int fileRevIndex = df.getRevisionIndex(fileRev); 41 int fileRevIndex = df.getRevisionIndex(fileRev);
42 int[] fileRevParents = new int[2]; 42 int[] fileRevParents = new int[2];
43 df.parents(fileRevIndex, fileRevParents, null, null); 43 df.parents(fileRevIndex, fileRevParents, null, null);
74 throw ise; 74 throw ise;
75 } 75 }
76 } 76 }
77 77
78 @Callback 78 @Callback
79 public interface Inspector { 79 public interface BlockInspector {
80 void same(EqualBlock block); 80 void same(EqualBlock block);
81 void added(AddBlock block); 81 void added(AddBlock block);
82 void changed(ChangeBlock block); 82 void changed(ChangeBlock block);
83 void deleted(DeleteBlock block); 83 void deleted(DeleteBlock block);
84 } 84 }
85 85
86 @Callback 86 @Callback
87 public interface InspectorEx extends Inspector { // XXX better name 87 public interface BlockInspectorEx extends BlockInspector { // XXX better name
88 // XXX perhaps, shall pass object instead of separate values for future extension? 88 // XXX perhaps, shall pass object instead of separate values for future extension?
89 void start(int originLineCount, int targetLineCount); 89 void start(int originLineCount, int targetLineCount);
90 void done(); 90 void done();
91 } 91 }
92 92
118 int totalRemovedLines(); 118 int totalRemovedLines();
119 String[] removedLines(); 119 String[] removedLines();
120 } 120 }
121 public interface ChangeBlock extends AddBlock, DeleteBlock { 121 public interface ChangeBlock extends AddBlock, DeleteBlock {
122 } 122 }
123
124 @Callback
125 public interface LineInspector {
126 void line(int lineNumber, int changesetRevIndex, LineDescriptor ld);
127 }
128
129 public interface LineDescriptor {
130 int totalLines();
131 }
132
133
123 134
124 static class BlameBlockInspector extends PatchGenerator.DeltaInspector<LineSequence> { 135 static class BlameBlockInspector extends PatchGenerator.DeltaInspector<LineSequence> {
125 private final Inspector insp; 136 private final BlockInspector insp;
126 private final int csetP1; 137 private final int csetP1;
127 private final int csetTarget; 138 private final int csetTarget;
128 139
129 public BlameBlockInspector(Inspector inspector, int parentCset1, int targetCset) { 140 public BlameBlockInspector(BlockInspector inspector, int parentCset1, int targetCset) {
130 assert inspector != null; 141 assert inspector != null;
131 insp = inspector; 142 insp = inspector;
132 csetP1 = parentCset1; 143 csetP1 = parentCset1;
133 csetTarget = targetCset; 144 csetTarget = targetCset;
134 } 145 }
135 146
136 @Override 147 @Override
137 public void begin(LineSequence s1, LineSequence s2) { 148 public void begin(LineSequence s1, LineSequence s2) {
138 super.begin(s1, s2); 149 super.begin(s1, s2);
139 if (insp instanceof InspectorEx) { 150 if (insp instanceof BlockInspectorEx) {
140 ((InspectorEx) insp).start(s1.chunkCount() - 1, s2.chunkCount() - 1); 151 ((BlockInspectorEx) insp).start(s1.chunkCount() - 1, s2.chunkCount() - 1);
141 } 152 }
142 } 153 }
143 154
144 @Override 155 @Override
145 public void end() { 156 public void end() {
146 super.end(); 157 super.end();
147 if(insp instanceof InspectorEx) { 158 if(insp instanceof BlockInspectorEx) {
148 ((InspectorEx) insp).done(); 159 ((BlockInspectorEx) insp).done();
149 } 160 }
150 } 161 }
151 162
152 @Override 163 @Override
153 protected void changed(int s1From, int s1To, int s2From, int s2To) { 164 protected void changed(int s1From, int s1To, int s2From, int s2To) {