Mercurial > jhg
comparison src/org/tmatesoft/hg/core/ChangesetTransformer.java @ 215:41a778e3fd31
Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Tue, 17 May 2011 00:56:54 +0200 |
| parents | ffc5f6d59f7e |
| children | a674b8590362 |
comparison
equal
deleted
inserted
replaced
| 214:4252faa556cd | 215:41a778e3fd31 |
|---|---|
| 20 | 20 |
| 21 import org.tmatesoft.hg.repo.HgChangelog; | 21 import org.tmatesoft.hg.repo.HgChangelog; |
| 22 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; | 22 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
| 23 import org.tmatesoft.hg.repo.HgRepository; | 23 import org.tmatesoft.hg.repo.HgRepository; |
| 24 import org.tmatesoft.hg.repo.HgStatusCollector; | 24 import org.tmatesoft.hg.repo.HgStatusCollector; |
| 25 import org.tmatesoft.hg.util.CancelSupport; | |
| 26 import org.tmatesoft.hg.util.CancelledException; | |
| 25 import org.tmatesoft.hg.util.PathPool; | 27 import org.tmatesoft.hg.util.PathPool; |
| 26 import org.tmatesoft.hg.util.PathRewrite; | 28 import org.tmatesoft.hg.util.PathRewrite; |
| 29 import org.tmatesoft.hg.util.ProgressSupport; | |
| 27 | 30 |
| 28 /** | 31 /** |
| 29 * Bridges {@link HgChangelog.RawChangeset} with high-level {@link HgChangeset} API | 32 * Bridges {@link HgChangelog.RawChangeset} with high-level {@link HgChangeset} API |
| 33 * FIXME move to .internal | |
| 30 * | 34 * |
| 31 * @author Artem Tikhomirov | 35 * @author Artem Tikhomirov |
| 32 * @author TMate Software Ltd. | 36 * @author TMate Software Ltd. |
| 33 */ | 37 */ |
| 34 /*package-local*/ class ChangesetTransformer implements HgChangelog.Inspector { | 38 /*package-local*/ class ChangesetTransformer implements HgChangelog.Inspector { |
| 35 private final HgChangesetHandler handler; | 39 private final HgChangesetHandler handler; |
| 36 private final HgChangeset changeset; | 40 private final HgChangeset changeset; |
| 41 private final ProgressSupport progressHelper; | |
| 42 private final CancelSupport cancelHelper; | |
| 37 private Set<String> branches; | 43 private Set<String> branches; |
| 44 private HgCallbackTargetException failure; | |
| 45 private CancelledException cancellation; | |
| 38 | 46 |
| 39 // repo and delegate can't be null, parent walker can | 47 // repo and delegate can't be null, parent walker can |
| 40 public ChangesetTransformer(HgRepository hgRepo, HgChangesetHandler delegate, HgChangelog.ParentWalker pw) { | 48 // ps and cs can't be null |
| 49 public ChangesetTransformer(HgRepository hgRepo, HgChangesetHandler delegate, HgChangelog.ParentWalker pw, ProgressSupport ps, CancelSupport cs) { | |
| 41 if (hgRepo == null || delegate == null) { | 50 if (hgRepo == null || delegate == null) { |
| 51 throw new IllegalArgumentException(); | |
| 52 } | |
| 53 if (ps == null || cs == null) { | |
| 42 throw new IllegalArgumentException(); | 54 throw new IllegalArgumentException(); |
| 43 } | 55 } |
| 44 HgStatusCollector statusCollector = new HgStatusCollector(hgRepo); | 56 HgStatusCollector statusCollector = new HgStatusCollector(hgRepo); |
| 45 // files listed in a changeset don't need their names to be rewritten (they are normalized already) | 57 // files listed in a changeset don't need their names to be rewritten (they are normalized already) |
| 46 PathPool pp = new PathPool(new PathRewrite.Empty()); | 58 PathPool pp = new PathPool(new PathRewrite.Empty()); |
| 47 statusCollector.setPathPool(pp); | 59 statusCollector.setPathPool(pp); |
| 48 changeset = new HgChangeset(statusCollector, pp); | 60 changeset = new HgChangeset(statusCollector, pp); |
| 49 changeset.setParentHelper(pw); | 61 changeset.setParentHelper(pw); |
| 50 handler = delegate; | 62 handler = delegate; |
| 63 cancelHelper = cs; | |
| 64 progressHelper = ps; | |
| 51 } | 65 } |
| 52 | 66 |
| 53 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { | 67 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { |
| 68 if (failure != null || cancellation != null) { | |
| 69 return; // FIXME need a better way to stop iterating revlog | |
| 70 } | |
| 54 if (branches != null && !branches.contains(cset.branch())) { | 71 if (branches != null && !branches.contains(cset.branch())) { |
| 55 return; | 72 return; |
| 56 } | 73 } |
| 57 | 74 |
| 58 changeset.init(revisionNumber, nodeid, cset); | 75 changeset.init(revisionNumber, nodeid, cset); |
| 59 handler.next(changeset); | 76 try { |
| 77 handler.next(changeset); | |
| 78 progressHelper.worked(1); | |
| 79 cancelHelper.checkCancelled(); | |
| 80 } catch (RuntimeException ex) { | |
| 81 failure = new HgCallbackTargetException(ex).setRevision(nodeid).setRevisionNumber(revisionNumber); | |
| 82 } catch (CancelledException ex) { | |
| 83 cancellation = ex; | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 public void checkFailure() throws HgCallbackTargetException, CancelledException { | |
| 88 if (failure != null) { | |
| 89 HgCallbackTargetException toThrow = failure; | |
| 90 failure = null; // just in (otherwise unexpected) case this instance would get reused | |
| 91 throw toThrow; | |
| 92 } | |
| 93 if (cancellation != null) { | |
| 94 CancelledException toThrow = cancellation; | |
| 95 cancellation = null; | |
| 96 throw toThrow; | |
| 97 } | |
| 60 } | 98 } |
| 61 | 99 |
| 62 public void limitBranches(Set<String> branches) { | 100 public void limitBranches(Set<String> branches) { |
| 63 this.branches = branches; | 101 this.branches = branches; |
| 64 } | 102 } |
