Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgStatusCollector.java @ 366:189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Fri, 16 Dec 2011 04:43:18 +0100 |
| parents | 150500515714 |
| children | 2fadf8695f8a |
comparison
equal
deleted
inserted
replaced
| 365:3572fcb06473 | 366:189dc6dc1c3e |
|---|---|
| 73 | 73 |
| 74 public HgRepository getRepo() { | 74 public HgRepository getRepo() { |
| 75 return repo; | 75 return repo; |
| 76 } | 76 } |
| 77 | 77 |
| 78 private ManifestRevision get(int rev) { | 78 private ManifestRevision get(int rev) throws HgInvalidControlFileException { |
| 79 ManifestRevision i = cache.get(rev); | 79 ManifestRevision i = cache.get(rev); |
| 80 if (i == null) { | 80 if (i == null) { |
| 81 if (rev == -1) { | 81 if (rev == -1) { |
| 82 return emptyFakeState; | 82 return emptyFakeState; |
| 83 } | 83 } |
| 98 // assume usually we go from oldest to newest, hence remove oldest as most likely to be no longer necessary | 98 // assume usually we go from oldest to newest, hence remove oldest as most likely to be no longer necessary |
| 99 cache.removeFromStart(cache.size() - cacheMaxSize + 1 /* room for new element */); | 99 cache.removeFromStart(cache.size() - cacheMaxSize + 1 /* room for new element */); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 private void initCacheRange(int minRev, int maxRev) { | 103 private void initCacheRange(int minRev, int maxRev) throws HgInvalidControlFileException { |
| 104 ensureCacheSize(); | 104 ensureCacheSize(); |
| 105 // In fact, walk(minRev, maxRev) doesn't imply | 105 // In fact, walk(minRev, maxRev) doesn't imply |
| 106 // there would be maxRev-minRev+1 revisions visited. For example, | 106 // there would be maxRev-minRev+1 revisions visited. For example, |
| 107 // check cpython repo with 'hg log -r 22418:22420 --debug' and admire | 107 // check cpython repo with 'hg log -r 22418:22420 --debug' and admire |
| 108 // manifest revisions 66650, 21683, 21684. Thus, innocent walk(22418,22420) results in 40k+ revisions and OOME | 108 // manifest revisions 66650, 21683, 21684. Thus, innocent walk(22418,22420) results in 40k+ revisions and OOME |
| 157 fakeEmptyRev.begin(-1, null, -1); | 157 fakeEmptyRev.begin(-1, null, -1); |
| 158 fakeEmptyRev.end(-1); | 158 fakeEmptyRev.end(-1); |
| 159 return fakeEmptyRev; | 159 return fakeEmptyRev; |
| 160 } | 160 } |
| 161 | 161 |
| 162 /*package-local*/ ManifestRevision raw(int rev) { | 162 /*package-local*/ ManifestRevision raw(int rev) throws HgInvalidControlFileException { |
| 163 return get(rev); | 163 return get(rev); |
| 164 } | 164 } |
| 165 /*package-local*/ PathPool getPathPool() { | 165 /*package-local*/ PathPool getPathPool() { |
| 166 if (pathPool == null) { | 166 if (pathPool == null) { |
| 167 pathPool = new PathPool(new PathRewrite.Empty()); | 167 pathPool = new PathPool(new PathRewrite.Empty()); |
| 184 // do not assign null, ever | 184 // do not assign null, ever |
| 185 scope = scopeMatcher == null ? new Path.Matcher.Any() : scopeMatcher; | 185 scope = scopeMatcher == null ? new Path.Matcher.Any() : scopeMatcher; |
| 186 } | 186 } |
| 187 | 187 |
| 188 // hg status --change <rev> | 188 // hg status --change <rev> |
| 189 public void change(int rev, HgStatusInspector inspector) { | 189 public void change(int rev, HgStatusInspector inspector) throws /*FIXME HInvalidRevisionException,*/ HgInvalidControlFileException { |
| 190 int[] parents = new int[2]; | 190 int[] parents = new int[2]; |
| 191 repo.getChangelog().parents(rev, parents, null, null); | 191 repo.getChangelog().parents(rev, parents, null, null); |
| 192 walk(parents[0], rev, inspector); | 192 walk(parents[0], rev, inspector); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // rev1 and rev2 are changelog revision numbers, argument order matters. | 195 // rev1 and rev2 are changelog revision numbers, argument order matters. |
| 196 // Either rev1 or rev2 may be -1 to indicate comparison to empty repository (XXX this is due to use of | 196 // Either rev1 or rev2 may be -1 to indicate comparison to empty repository (XXX this is due to use of |
| 197 // parents in #change(), I believe. Perhaps, need a constant for this? Otherwise this hidden knowledge gets | 197 // parents in #change(), I believe. Perhaps, need a constant for this? Otherwise this hidden knowledge gets |
| 198 // exposed to e.g. Record | 198 // exposed to e.g. Record |
| 199 public void walk(int rev1, int rev2, HgStatusInspector inspector) { | 199 public void walk(int rev1, int rev2, HgStatusInspector inspector) throws /*FIXME HInvalidRevisionException,*/ HgInvalidControlFileException { |
| 200 if (rev1 == rev2) { | 200 if (rev1 == rev2) { |
| 201 throw new IllegalArgumentException(); | 201 throw new IllegalArgumentException(); |
| 202 } | 202 } |
| 203 if (inspector == null) { | 203 if (inspector == null) { |
| 204 throw new IllegalArgumentException(); | 204 throw new IllegalArgumentException(); |
| 282 inspector.removed(r1fname); | 282 inspector.removed(r1fname); |
| 283 } | 283 } |
| 284 } | 284 } |
| 285 } | 285 } |
| 286 | 286 |
| 287 public Record status(int rev1, int rev2) { | 287 public Record status(int rev1, int rev2) throws /*FIXME HInvalidRevisionException,*/ HgInvalidControlFileException { |
| 288 Record rv = new Record(); | 288 Record rv = new Record(); |
| 289 walk(rev1, rev2, rv); | 289 walk(rev1, rev2, rv); |
| 290 return rv; | 290 return rv; |
| 291 } | 291 } |
| 292 | 292 |
| 345 startRev = startRevision; | 345 startRev = startRevision; |
| 346 endRev = endRevision; | 346 endRev = endRevision; |
| 347 statusHelper = self; | 347 statusHelper = self; |
| 348 } | 348 } |
| 349 | 349 |
| 350 public Nodeid nodeidBeforeChange(Path fname) { | 350 public Nodeid nodeidBeforeChange(Path fname) throws HgInvalidControlFileException { |
| 351 if (statusHelper == null || startRev == BAD_REVISION) { | 351 if (statusHelper == null || startRev == BAD_REVISION) { |
| 352 return null; | 352 return null; |
| 353 } | 353 } |
| 354 if ((modified == null || !modified.contains(fname)) && (removed == null || !removed.contains(fname))) { | 354 if ((modified == null || !modified.contains(fname)) && (removed == null || !removed.contains(fname))) { |
| 355 return null; | 355 return null; |
| 356 } | 356 } |
| 357 return statusHelper.raw(startRev).nodeid(fname); | 357 return statusHelper.raw(startRev).nodeid(fname); |
| 358 } | 358 } |
| 359 public Nodeid nodeidAfterChange(Path fname) { | 359 public Nodeid nodeidAfterChange(Path fname) throws HgInvalidControlFileException { |
| 360 if (statusHelper == null || endRev == BAD_REVISION) { | 360 if (statusHelper == null || endRev == BAD_REVISION) { |
| 361 return null; | 361 return null; |
| 362 } | 362 } |
| 363 if ((modified == null || !modified.contains(fname)) && (added == null || !added.contains(fname))) { | 363 if ((modified == null || !modified.contains(fname)) && (added == null || !added.contains(fname))) { |
| 364 return null; | 364 return null; |
