Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/AnnotateFacility.java @ 543:1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 15 Feb 2013 15:52:03 +0100 |
parents | a71a05ec11bc |
children | 7f5998a9619d |
comparison
equal
deleted
inserted
replaced
542:a71a05ec11bc | 543:1e95f48d9886 |
---|---|
81 // String[] lines(); | 81 // String[] lines(); |
82 // byte[] data(); | 82 // byte[] data(); |
83 } | 83 } |
84 | 84 |
85 public interface AddBlock extends Block { | 85 public interface AddBlock extends Block { |
86 int insertedAt(); // line index in the old file | |
86 int firstAddedLine(); | 87 int firstAddedLine(); |
87 int totalAddedLines(); | 88 int totalAddedLines(); |
88 String[] addedLines(); | 89 String[] addedLines(); |
89 } | 90 } |
90 public interface DeleteBlock extends Block { | 91 public interface DeleteBlock extends Block { |
92 int removedAt(); // line index in the new file | |
91 int firstRemovedLine(); | 93 int firstRemovedLine(); |
92 int totalRemovedLines(); | 94 int totalRemovedLines(); |
93 String[] removedLines(); | 95 String[] removedLines(); |
94 } | 96 } |
95 public interface ChangeBlock extends AddBlock, DeleteBlock { | 97 public interface ChangeBlock extends AddBlock, DeleteBlock { |
103 insp = inspector; | 105 insp = inspector; |
104 } | 106 } |
105 | 107 |
106 @Override | 108 @Override |
107 protected void changed(int s1From, int s1To, int s2From, int s2To) { | 109 protected void changed(int s1From, int s1To, int s2From, int s2To) { |
108 insp.changed(new BlockImpl2(seq1, seq2, s1From, s1To-s1From, s2From, s2To - s2From)); | 110 insp.changed(new BlockImpl2(seq1, seq2, s1From, s1To-s1From, s2From, s2To - s2From, s1From, s2From)); |
109 } | 111 } |
110 | 112 |
111 @Override | 113 @Override |
112 protected void added(int s1InsertPoint, int s2From, int s2To) { | 114 protected void added(int s1InsertPoint, int s2From, int s2To) { |
113 insp.added(new BlockImpl2(null, seq2, -1, -1, s2From, s2To - s2From)); | 115 insp.added(new BlockImpl2(null, seq2, -1, -1, s2From, s2To - s2From, s1InsertPoint, -1)); |
114 } | 116 } |
115 | 117 |
116 @Override | 118 @Override |
117 protected void deleted(int s1From, int s1To) { | 119 protected void deleted(int s2DeletePoint, int s1From, int s1To) { |
118 insp.deleted(new BlockImpl2(seq1, null, s1From, s1To - s1From, -1, -1)); | 120 insp.deleted(new BlockImpl2(seq1, null, s1From, s1To - s1From, -1, -1, -1, s2DeletePoint)); |
119 } | 121 } |
120 | 122 |
121 @Override | 123 @Override |
122 protected void unchanged(int s1From, int s2From, int length) { | 124 protected void unchanged(int s1From, int s2From, int length) { |
123 insp.same(new BlockImpl(seq2, s2From, length)); | 125 insp.same(new BlockImpl(seq2, s2From, length)); |
149 private final ChunkSequence newSeq; | 151 private final ChunkSequence newSeq; |
150 private final int s1Start; | 152 private final int s1Start; |
151 private final int s1Len; | 153 private final int s1Len; |
152 private final int s2Start; | 154 private final int s2Start; |
153 private final int s2Len; | 155 private final int s2Len; |
154 | 156 private final int s1InsertPoint; |
155 public BlockImpl2(ChunkSequence s1, ChunkSequence s2, int s1Start, int s1Len, int s2Start, int s2Len) { | 157 private final int s2DeletePoint; |
158 | |
159 public BlockImpl2(ChunkSequence s1, ChunkSequence s2, int s1Start, int s1Len, int s2Start, int s2Len, int s1InsertPoint, int s2DeletePoint) { | |
156 oldSeq = s1; | 160 oldSeq = s1; |
157 newSeq = s2; | 161 newSeq = s2; |
158 this.s1Start = s1Start; | 162 this.s1Start = s1Start; |
159 this.s1Len = s1Len; | 163 this.s1Len = s1Len; |
160 this.s2Start = s2Start; | 164 this.s2Start = s2Start; |
161 this.s2Len = s2Len; | 165 this.s2Len = s2Len; |
166 this.s1InsertPoint = s1InsertPoint; | |
167 this.s2DeletePoint = s2DeletePoint; | |
168 } | |
169 | |
170 public int insertedAt() { | |
171 return s1InsertPoint; | |
162 } | 172 } |
163 | 173 |
164 public int firstAddedLine() { | 174 public int firstAddedLine() { |
165 return s2Start; | 175 return s2Start; |
166 } | 176 } |
169 return s2Len; | 179 return s2Len; |
170 } | 180 } |
171 | 181 |
172 public String[] addedLines() { | 182 public String[] addedLines() { |
173 return generateLines(totalAddedLines(), firstAddedLine()); | 183 return generateLines(totalAddedLines(), firstAddedLine()); |
184 } | |
185 | |
186 public int removedAt() { | |
187 return s2DeletePoint; | |
174 } | 188 } |
175 | 189 |
176 public int firstRemovedLine() { | 190 public int firstRemovedLine() { |
177 return s1Start; | 191 return s1Start; |
178 } | 192 } |
186 } | 200 } |
187 | 201 |
188 private String[] generateLines(int count, int startFrom) { | 202 private String[] generateLines(int count, int startFrom) { |
189 String[] rv = new String[count]; | 203 String[] rv = new String[count]; |
190 for (int i = 0; i < count; i++) { | 204 for (int i = 0; i < count; i++) { |
191 rv[i] = String.format("LINE %d", startFrom + i); | 205 rv[i] = String.format("LINE %d", startFrom + i+1); |
192 } | 206 } |
193 return rv; | 207 return rv; |
194 } | 208 } |
195 } | 209 } |
196 } | 210 } |