Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/HgChangelog.java @ 423:9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 23 Mar 2012 22:51:18 +0100 |
parents | 7f136a3fa671 |
children | 6437d261048a |
comparison
equal
deleted
inserted
replaced
422:5d1cc7366d04 | 423:9c9c442b5f2e |
---|---|
30 import java.util.Locale; | 30 import java.util.Locale; |
31 import java.util.Map; | 31 import java.util.Map; |
32 import java.util.TimeZone; | 32 import java.util.TimeZone; |
33 | 33 |
34 import org.tmatesoft.hg.core.HgBadArgumentException; | 34 import org.tmatesoft.hg.core.HgBadArgumentException; |
35 import org.tmatesoft.hg.core.HgException; | |
36 import org.tmatesoft.hg.core.HgInvalidControlFileException; | |
37 import org.tmatesoft.hg.core.HgInvalidRevisionException; | |
38 import org.tmatesoft.hg.core.Nodeid; | 35 import org.tmatesoft.hg.core.Nodeid; |
36 import org.tmatesoft.hg.internal.Callback; | |
39 import org.tmatesoft.hg.internal.DataAccess; | 37 import org.tmatesoft.hg.internal.DataAccess; |
40 import org.tmatesoft.hg.internal.IterateControlMediator; | 38 import org.tmatesoft.hg.internal.IterateControlMediator; |
41 import org.tmatesoft.hg.internal.Lifecycle; | 39 import org.tmatesoft.hg.internal.Lifecycle; |
42 import org.tmatesoft.hg.internal.Pool; | 40 import org.tmatesoft.hg.internal.Pool; |
43 import org.tmatesoft.hg.internal.RevlogStream; | 41 import org.tmatesoft.hg.internal.RevlogStream; |
105 public RawChangeset changeset(Nodeid nid) throws HgInvalidControlFileException, HgInvalidRevisionException { | 103 public RawChangeset changeset(Nodeid nid) throws HgInvalidControlFileException, HgInvalidRevisionException { |
106 int x = getRevisionIndex(nid); | 104 int x = getRevisionIndex(nid); |
107 return range(x, x).get(0); | 105 return range(x, x).get(0); |
108 } | 106 } |
109 | 107 |
108 @Callback | |
110 public interface Inspector { | 109 public interface Inspector { |
111 // TODO describe whether cset is new instance each time | 110 /** |
112 // describe what revisionNumber is when Inspector is used with HgBundle (BAD_REVISION or bundle's local order?) | 111 * Access next changeset |
113 void next(int revisionNumber, Nodeid nodeid, RawChangeset cset); | 112 * TODO describe what revisionNumber is when Inspector is used with HgBundle (BAD_REVISION or bundle's local order?) |
113 * | |
114 * @param revisionIndex index of revision being inspected, local to the inspected object | |
115 * @param nodeid revision being inspected | |
116 * @param cset changeset raw data | |
117 */ | |
118 void next(int revisionIndex, Nodeid nodeid, RawChangeset cset); | |
114 } | 119 } |
115 | 120 |
116 /** | 121 /** |
117 * Unlike regular {@link Inspector}, this one supplies changeset revision along with its parents and children according | 122 * Unlike regular {@link Inspector}, this one supplies changeset revision along with its parents and children according |
118 * to parent information of the revlog this inspector visits. | 123 * to parent information of the revlog this inspector visits. |
384 inspector = delegate; | 389 inspector = delegate; |
385 usersPool = new Pool<String>(); | 390 usersPool = new Pool<String>(); |
386 progressHelper = ProgressSupport.Factory.get(delegate); | 391 progressHelper = ProgressSupport.Factory.get(delegate); |
387 } | 392 } |
388 | 393 |
389 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) throws HgException { | 394 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { |
390 try { | 395 try { |
391 byte[] data = da.byteArray(); | 396 byte[] data = da.byteArray(); |
392 cset.init(data, 0, data.length, usersPool); | 397 cset.init(data, 0, data.length, usersPool); |
393 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse | 398 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse |
394 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); | 399 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); |
395 progressHelper.worked(1); | 400 progressHelper.worked(1); |
401 } catch (HgBadArgumentException ex) { | |
402 // see below about better exception | |
403 throw new HgInvalidControlFileException("Failed reading changelog", ex, null).setRevisionIndex(revisionNumber); | |
396 } catch (IOException ex) { | 404 } catch (IOException ex) { |
397 throw new HgException(ex); // XXX need better exception, perhaps smth like HgChangelogException (extends HgInvalidControlFileException) | 405 // XXX need better exception, perhaps smth like HgChangelogException (extends HgInvalidControlFileException) |
406 throw new HgInvalidControlFileException("Failed reading changelog", ex, null).setRevisionIndex(revisionNumber); | |
398 } | 407 } |
399 if (iterateControl != null) { | 408 if (iterateControl != null) { |
400 iterateControl.checkCancelled(); | 409 iterateControl.checkCancelled(); |
401 } | 410 } |
402 } | 411 } |