comparison test/org/tmatesoft/hg/test/TestAuxUtilities.java @ 520:1ee452f31187

Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 21 Dec 2012 21:20:26 +0100
parents e74580e24feb
children 45751456b471
comparison
equal deleted inserted replaced
519:934037edbea0 520:1ee452f31187
145 if (shallStop) { 145 if (shallStop) {
146 throw new CancelledException(); 146 throw new CancelledException();
147 } 147 }
148 } 148 }
149 } 149 }
150
151 static class CancelAtValue {
152 public int lastSeen;
153 public final int stopValue;
154 protected final CancelImpl cancelImpl = new CancelImpl();
155
156 protected CancelAtValue(int value) {
157 stopValue = value;
158 }
159
160 protected void nextValue(int value) {
161 lastSeen = value;
162 if (value == stopValue) {
163 cancelImpl.stop();
164 }
165 }
166 }
150 167
151 @Test 168 @Test
152 public void testChangelogCancelSupport() throws Exception { 169 public void testChangelogCancelSupport() throws Exception {
153 HgRepository repository = Configuration.get().find("branches-1"); // any repo with more revisions 170 HgRepository repository = Configuration.get().find("branches-1"); // any repo with more revisions
154 class InspectorImplementsCancel implements HgChangelog.Inspector, CancelSupport { 171 class InspectorImplementsCancel extends CancelAtValue implements HgChangelog.Inspector, CancelSupport {
155 public final int when2stop;
156 public int lastVisitet = 0;
157 private final CancelImpl cancelImpl = new CancelImpl();
158 172
159 public InspectorImplementsCancel(int limit) { 173 public InspectorImplementsCancel(int limit) {
160 when2stop = limit; 174 super(limit);
161 } 175 }
162 176
163 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { 177 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
164 lastVisitet = revisionNumber; 178 nextValue(revisionNumber);
165 if (revisionNumber == when2stop) {
166 cancelImpl.stop();
167 }
168 } 179 }
169 180
170 public void checkCancelled() throws CancelledException { 181 public void checkCancelled() throws CancelledException {
171 cancelImpl.checkCancelled(); 182 cancelImpl.checkCancelled();
172 } 183 }
173 }; 184 };
174 class InspectorImplementsAdaptable implements HgChangelog.Inspector, Adaptable { 185 class InspectorImplementsAdaptable extends CancelAtValue implements HgChangelog.Inspector, Adaptable {
175 public final int when2stop;
176 public int lastVisitet = 0;
177 private final CancelImpl cancelImpl = new CancelImpl();
178
179 public InspectorImplementsAdaptable(int limit) { 186 public InspectorImplementsAdaptable(int limit) {
180 when2stop = limit; 187 super(limit);
181 } 188 }
182 189
183 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { 190 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
184 lastVisitet = revisionNumber; 191 nextValue(revisionNumber);
185 if (revisionNumber == when2stop) { 192 }
186 cancelImpl.stop(); 193
187 }
188 }
189 public <T> T getAdapter(Class<T> adapterClass) { 194 public <T> T getAdapter(Class<T> adapterClass) {
190 if (CancelSupport.class == adapterClass) { 195 if (CancelSupport.class == adapterClass) {
191 return adapterClass.cast(cancelImpl); 196 return adapterClass.cast(cancelImpl);
192 } 197 }
193 return null; 198 return null;
194 } 199 }
195
196 } 200 }
197 // 201 //
198 InspectorImplementsCancel insp1; 202 InspectorImplementsCancel insp1;
199 repository.getChangelog().all(insp1= new InspectorImplementsCancel(2)); 203 repository.getChangelog().all(insp1= new InspectorImplementsCancel(2));
200 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); 204 Assert.assertEquals(insp1.stopValue, insp1.lastSeen);
201 repository.getChangelog().all(insp1 = new InspectorImplementsCancel(12)); 205 repository.getChangelog().all(insp1 = new InspectorImplementsCancel(12));
202 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); 206 Assert.assertEquals(insp1.stopValue, insp1.lastSeen);
203 // 207 //
204 InspectorImplementsAdaptable insp2; 208 InspectorImplementsAdaptable insp2;
205 repository.getChangelog().all(insp2= new InspectorImplementsAdaptable(3)); 209 repository.getChangelog().all(insp2= new InspectorImplementsAdaptable(3));
206 Assert.assertEquals(insp2.when2stop, insp2.lastVisitet); 210 Assert.assertEquals(insp2.stopValue, insp2.lastSeen);
207 repository.getChangelog().all(insp2 = new InspectorImplementsAdaptable(10)); 211 repository.getChangelog().all(insp2 = new InspectorImplementsAdaptable(10));
208 Assert.assertEquals(insp2.when2stop, insp2.lastVisitet); 212 Assert.assertEquals(insp2.stopValue, insp2.lastSeen);
209 } 213 }
210 214
211 @Test 215 @Test
212 public void testManifestCancelSupport() throws Exception { 216 public void testManifestCancelSupport() throws Exception {
213 HgRepository repository = Configuration.get().find("branches-1"); // any repo with as many revisions as possible 217 HgRepository repository = Configuration.get().find("branches-1"); // any repo with as many revisions as possible
214 class InspectorImplementsAdaptable implements HgManifest.Inspector, Adaptable { 218 class InspectorImplementsAdaptable extends CancelAtValue implements HgManifest.Inspector, Adaptable {
215 public final int when2stop;
216 public int lastVisitet = 0;
217 private final CancelImpl cancelImpl = new CancelImpl();
218
219 public InspectorImplementsAdaptable(int limit) { 219 public InspectorImplementsAdaptable(int limit) {
220 when2stop = limit; 220 super(limit);
221 } 221 }
222 222
223 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { 223 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
224 if (++lastVisitet == when2stop) { 224 nextValue(lastSeen+1);
225 cancelImpl.stop();
226 }
227 return true; 225 return true;
228 } 226 }
229 227
230 public boolean end(int manifestRevision) { 228 public boolean end(int manifestRevision) {
231 return true; 229 return true;
242 return true; 240 return true;
243 } 241 }
244 } 242 }
245 InspectorImplementsAdaptable insp1; 243 InspectorImplementsAdaptable insp1;
246 repository.getManifest().walk(0, TIP, insp1= new InspectorImplementsAdaptable(3)); 244 repository.getManifest().walk(0, TIP, insp1= new InspectorImplementsAdaptable(3));
247 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); 245 Assert.assertEquals(insp1.stopValue, insp1.lastSeen);
248 repository.getManifest().walk(0, TIP, insp1 = new InspectorImplementsAdaptable(10)); 246 repository.getManifest().walk(0, TIP, insp1 = new InspectorImplementsAdaptable(10));
249 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); 247 Assert.assertEquals(insp1.stopValue, insp1.lastSeen);
250 } 248 }
251 249
252 @Test 250 @Test
253 public void testCatCommandCancelSupport() throws Exception { 251 public void testCatCommandCancelSupport() throws Exception {
254 HgRepository repository = Configuration.get().find("branches-1"); // any repo 252 HgRepository repository = Configuration.get().find("branches-1"); // any repo