Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/ChangelogMonitor.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 | 5c68567b3645 |
| children |
comparison
equal
deleted
inserted
replaced
| 627:5153eb73b18d | 628:6526d8adbc0f |
|---|---|
| 17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
| 18 | 18 |
| 19 import org.tmatesoft.hg.core.Nodeid; | 19 import org.tmatesoft.hg.core.Nodeid; |
| 20 import org.tmatesoft.hg.core.SessionContext; | 20 import org.tmatesoft.hg.core.SessionContext; |
| 21 import org.tmatesoft.hg.repo.HgRepository; | 21 import org.tmatesoft.hg.repo.HgRepository; |
| 22 import org.tmatesoft.hg.repo.HgRuntimeException; | |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * Track changes to a repository based on recent changelog revision. | 25 * Track changes to a repository based on recent changelog revision. |
| 25 * TODO shall be merged with {@link RevlogChangeMonitor} and {@link FileChangeMonitor} into | 26 * TODO shall be merged with {@link RevlogChangeMonitor} and {@link FileChangeMonitor} into |
| 26 * a single facility available from {@link SessionContext} | 27 * a single facility available from {@link SessionContext} |
| 36 public ChangelogMonitor(HgRepository hgRepo) { | 37 public ChangelogMonitor(HgRepository hgRepo) { |
| 37 repo = hgRepo; | 38 repo = hgRepo; |
| 38 } | 39 } |
| 39 | 40 |
| 40 // memorize the state of the repository's changelog | 41 // memorize the state of the repository's changelog |
| 41 public void touch() { | 42 public void touch() throws HgRuntimeException { |
| 42 changelogRevCount = repo.getChangelog().getRevisionCount(); | 43 changelogRevCount = repo.getChangelog().getRevisionCount(); |
| 43 changelogLastRev = safeGetRevision(changelogRevCount-1); | 44 changelogLastRev = safeGetRevision(changelogRevCount-1); |
| 44 } | 45 } |
| 45 | 46 |
| 46 // if present state doesn't match the one we remember | 47 // if present state doesn't match the one we remember |
| 47 public boolean isChanged() { | 48 public boolean isChanged() throws HgRuntimeException { |
| 48 int rc = repo.getChangelog().getRevisionCount(); | 49 int rc = repo.getChangelog().getRevisionCount(); |
| 49 if (rc != changelogRevCount) { | 50 if (rc != changelogRevCount) { |
| 50 return true; | 51 return true; |
| 51 } | 52 } |
| 52 Nodeid r = safeGetRevision(rc-1); | 53 Nodeid r = safeGetRevision(rc-1); |
| 53 return !r.equals(changelogLastRev); | 54 return !r.equals(changelogLastRev); |
| 54 } | 55 } |
| 55 | 56 |
| 56 // handles empty repository case | 57 // handles empty repository case |
| 57 private Nodeid safeGetRevision(int revIndex) { | 58 private Nodeid safeGetRevision(int revIndex) throws HgRuntimeException { |
| 58 if (revIndex >= 0) { | 59 if (revIndex >= 0) { |
| 59 return repo.getChangelog().getRevision(revIndex); | 60 return repo.getChangelog().getRevision(revIndex); |
| 60 } | 61 } |
| 61 return Nodeid.NULL; | 62 return Nodeid.NULL; |
| 62 } | 63 } |
