comparison src/org/tmatesoft/hg/repo/HgChangelog.java @ 312:f9f3e9b67ccc

Facilitate cancellation and progress reporting in changelog and manifest iterations
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 27 Sep 2011 05:29:12 +0200
parents a6d19adc2636
children 09628675bcee
comparison
equal deleted inserted replaced
311:b9592e21176a 312:f9f3e9b67ccc
31 import java.util.TimeZone; 31 import java.util.TimeZone;
32 32
33 import org.tmatesoft.hg.core.HgBadStateException; 33 import org.tmatesoft.hg.core.HgBadStateException;
34 import org.tmatesoft.hg.core.Nodeid; 34 import org.tmatesoft.hg.core.Nodeid;
35 import org.tmatesoft.hg.internal.DataAccess; 35 import org.tmatesoft.hg.internal.DataAccess;
36 import org.tmatesoft.hg.internal.IterateControlMediator;
37 import org.tmatesoft.hg.internal.Lifecycle;
36 import org.tmatesoft.hg.internal.Pool; 38 import org.tmatesoft.hg.internal.Pool;
37 import org.tmatesoft.hg.internal.RevlogStream; 39 import org.tmatesoft.hg.internal.RevlogStream;
40 import org.tmatesoft.hg.util.CancelSupport;
41 import org.tmatesoft.hg.util.ProgressSupport;
38 42
39 /** 43 /**
40 * Representation of the Mercurial changelog file (list of ChangeSets) 44 * Representation of the Mercurial changelog file (list of ChangeSets)
41 * 45 *
42 * @author Artem Tikhomirov 46 * @author Artem Tikhomirov
336 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { 340 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
337 result.add(cset.clone()); 341 result.add(cset.clone());
338 } 342 }
339 } 343 }
340 344
341 private static class RawCsetParser implements RevlogStream.Inspector { 345 private static class RawCsetParser implements RevlogStream.Inspector, Lifecycle {
342 346
343 private final Inspector inspector; 347 private final Inspector inspector;
344 private final Pool<String> usersPool; 348 private final Pool<String> usersPool;
345 private final RawChangeset cset = new RawChangeset(); 349 private final RawChangeset cset = new RawChangeset();
350 private final ProgressSupport progressHelper;
351 private IterateControlMediator iterateControl;
346 352
347 public RawCsetParser(HgChangelog.Inspector delegate) { 353 public RawCsetParser(HgChangelog.Inspector delegate) {
348 assert delegate != null; 354 assert delegate != null;
349 inspector = delegate; 355 inspector = delegate;
350 usersPool = new Pool<String>(); 356 usersPool = new Pool<String>();
357 progressHelper = ProgressSupport.Factory.get(delegate);
351 } 358 }
352 359
353 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { 360 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) {
354 try { 361 try {
355 byte[] data = da.byteArray(); 362 byte[] data = da.byteArray();
356 cset.init(data, 0, data.length, usersPool); 363 cset.init(data, 0, data.length, usersPool);
357 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse 364 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse
358 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); 365 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset);
366 progressHelper.worked(1);
359 } catch (Exception ex) { 367 } catch (Exception ex) {
360 throw new HgBadStateException(ex); // FIXME exception handling 368 throw new HgBadStateException(ex); // FIXME exception handling
361 } 369 }
370 if (iterateControl != null) {
371 iterateControl.checkCancelled();
372 }
373 }
374
375 public void start(int count, Callback callback, Object token) {
376 CancelSupport cs = CancelSupport.Factory.get(inspector, null);
377 iterateControl = cs == null ? null : new IterateControlMediator(cs, callback);
378 progressHelper.start(count);
379 }
380
381 public void finish(Object token) {
382 progressHelper.done();
362 } 383 }
363 } 384 }
364 } 385 }