Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/CsetParamKeeper.java @ 628:6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Wed, 22 May 2013 15:52:31 +0200 |
| parents | 78a9e26e670d |
| children | a20121a2bba6 |
comparison
equal
deleted
inserted
replaced
| 627:5153eb73b18d | 628:6526d8adbc0f |
|---|---|
| 21 | 21 |
| 22 import org.tmatesoft.hg.core.HgBadArgumentException; | 22 import org.tmatesoft.hg.core.HgBadArgumentException; |
| 23 import org.tmatesoft.hg.core.Nodeid; | 23 import org.tmatesoft.hg.core.Nodeid; |
| 24 import org.tmatesoft.hg.repo.HgInvalidRevisionException; | 24 import org.tmatesoft.hg.repo.HgInvalidRevisionException; |
| 25 import org.tmatesoft.hg.repo.HgRepository; | 25 import org.tmatesoft.hg.repo.HgRepository; |
| 26 import org.tmatesoft.hg.repo.HgRuntimeException; | |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * Common code to keep changelog revision and to perform boundary check. | 29 * Common code to keep changelog revision and to perform boundary check. |
| 29 * | 30 * |
| 30 * @author Artem Tikhomirov | 31 * @author Artem Tikhomirov |
| 41 public CsetParamKeeper set(Nodeid changeset) throws HgBadArgumentException { | 42 public CsetParamKeeper set(Nodeid changeset) throws HgBadArgumentException { |
| 42 try { | 43 try { |
| 43 set(repo.getChangelog().getRevisionIndex(changeset)); | 44 set(repo.getChangelog().getRevisionIndex(changeset)); |
| 44 } catch (HgInvalidRevisionException ex) { | 45 } catch (HgInvalidRevisionException ex) { |
| 45 throw new HgBadArgumentException("Can't find revision", ex).setRevision(changeset); | 46 throw new HgBadArgumentException("Can't find revision", ex).setRevision(changeset); |
| 47 } catch (HgRuntimeException ex) { | |
| 48 throw new HgBadArgumentException(String.format("Can't initialize with revision %s", changeset.shortNotation()), ex); | |
| 46 } | 49 } |
| 47 return this; | 50 return this; |
| 48 } | 51 } |
| 49 | 52 |
| 50 public CsetParamKeeper set(int changelogRevIndex) throws HgBadArgumentException { | 53 public CsetParamKeeper set(int changelogRevIndex) throws HgBadArgumentException { |
| 51 int lastCsetIndex = repo.getChangelog().getLastRevision(); | 54 try { |
| 52 if (changelogRevIndex == HgRepository.TIP) { | 55 int lastCsetIndex = repo.getChangelog().getLastRevision(); |
| 53 changelogRevIndex = lastCsetIndex; | 56 if (changelogRevIndex == HgRepository.TIP) { |
| 57 changelogRevIndex = lastCsetIndex; | |
| 58 } | |
| 59 if (changelogRevIndex < 0 || changelogRevIndex > lastCsetIndex) { | |
| 60 throw new HgBadArgumentException(String.format("Bad revision index %d, value from [0..%d] expected", changelogRevIndex, lastCsetIndex), null).setRevisionIndex(changelogRevIndex); | |
| 61 } | |
| 62 doSet(changelogRevIndex); | |
| 63 } catch (HgRuntimeException ex) { | |
| 64 throw new HgBadArgumentException(String.format("Can't initialize with revision index %d", changelogRevIndex), ex); | |
| 54 } | 65 } |
| 55 if (changelogRevIndex < 0 || changelogRevIndex > lastCsetIndex) { | |
| 56 throw new HgBadArgumentException(String.format("Bad revision index %d, value from [0..%d] expected", changelogRevIndex, lastCsetIndex), null).setRevisionIndex(changelogRevIndex); | |
| 57 } | |
| 58 doSet(changelogRevIndex); | |
| 59 return this; | 66 return this; |
| 60 } | 67 } |
| 61 | 68 |
| 62 public void doSet(int changelogRevIndex) { | 69 public void doSet(int changelogRevIndex) { |
| 63 changelogRevisionIndex = changelogRevIndex; | 70 changelogRevisionIndex = changelogRevIndex; |
| 72 | 79 |
| 73 /** | 80 /** |
| 74 * @param defaultRevisionIndex value to return when no revision was set, may be {@link HgRepository#TIP} which gets translated to real index if used | 81 * @param defaultRevisionIndex value to return when no revision was set, may be {@link HgRepository#TIP} which gets translated to real index if used |
| 75 * @return changelog revision index if set, or defaultRevisionIndex value otherwise | 82 * @return changelog revision index if set, or defaultRevisionIndex value otherwise |
| 76 */ | 83 */ |
| 77 public int get(int defaultRevisionIndex) { | 84 public int get(int defaultRevisionIndex) throws HgRuntimeException { |
| 78 // XXX perhaps, shall translate other predefined constants (like WORKING COPY) here, too (e.g. for HgRevertCommand) | 85 // XXX perhaps, shall translate other predefined constants (like WORKING COPY) here, too (e.g. for HgRevertCommand) |
| 79 if (changelogRevisionIndex != BAD_REVISION || changelogRevisionIndex != TIP) { | 86 if (changelogRevisionIndex != BAD_REVISION || changelogRevisionIndex != TIP) { |
| 80 return changelogRevisionIndex; | 87 return changelogRevisionIndex; |
| 81 } | 88 } |
| 82 if (changelogRevisionIndex == TIP || defaultRevisionIndex == TIP) { | 89 if (changelogRevisionIndex == TIP || defaultRevisionIndex == TIP) { |
