comparison src/org/tmatesoft/hg/repo/HgStatusCollector.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 7bcfbc255f48
children 5050ee565bd1
comparison
equal deleted inserted replaced
627:5153eb73b18d 628:6526d8adbc0f
71 71
72 public HgRepository getRepo() { 72 public HgRepository getRepo() {
73 return repo; 73 return repo;
74 } 74 }
75 75
76 private ManifestRevision get(int rev) throws HgInvalidControlFileException { 76 private ManifestRevision get(int rev) throws HgRuntimeException {
77 ManifestRevision i = cache.get(rev); 77 ManifestRevision i = cache.get(rev);
78 if (i == null) { 78 if (i == null) {
79 if (rev == NO_REVISION) { 79 if (rev == NO_REVISION) {
80 return emptyFakeState; 80 return emptyFakeState;
81 } 81 }
96 // assume usually we go from oldest to newest, hence remove oldest as most likely to be no longer necessary 96 // assume usually we go from oldest to newest, hence remove oldest as most likely to be no longer necessary
97 cache.removeFromStart(cache.size() - cacheMaxSize + 1 /* room for new element */); 97 cache.removeFromStart(cache.size() - cacheMaxSize + 1 /* room for new element */);
98 } 98 }
99 } 99 }
100 100
101 private void initCacheRange(int minRev, int maxRev) throws HgInvalidControlFileException { 101 private void initCacheRange(int minRev, int maxRev) throws HgRuntimeException {
102 ensureCacheSize(); 102 ensureCacheSize();
103 // In fact, walk(minRev, maxRev) doesn't imply 103 // In fact, walk(minRev, maxRev) doesn't imply
104 // there would be maxRev-minRev+1 revisions visited. For example, 104 // there would be maxRev-minRev+1 revisions visited. For example,
105 // check cpython repo with 'hg log -r 22418:22420 --debug' and admire 105 // check cpython repo with 'hg log -r 22418:22420 --debug' and admire
106 // manifest revisions 66650, 21683, 21684. Thus, innocent walk(22418,22420) results in 40k+ revisions and OOME 106 // manifest revisions 66650, 21683, 21684. Thus, innocent walk(22418,22420) results in 40k+ revisions and OOME
157 * Access specific manifest revision 157 * Access specific manifest revision
158 * @param rev 158 * @param rev
159 * @return 159 * @return
160 * @throws HgInvalidControlFileException 160 * @throws HgInvalidControlFileException
161 */ 161 */
162 /*package-local*/ ManifestRevision raw(int rev) throws HgInvalidControlFileException { 162 /*package-local*/ ManifestRevision raw(int rev) throws HgRuntimeException {
163 return get(rev); 163 return get(rev);
164 } 164 }
165 /*package-local*/ Convertor<Path> getPathPool() { 165 /*package-local*/ Convertor<Path> getPathPool() {
166 if (pathPool == null) { 166 if (pathPool == null) {
167 pathPool = cacheFilenames; 167 pathPool = cacheFilenames;
342 * Collects status between two revisions, changes from <b>rev1</b> up to <b>rev2</b>. 342 * Collects status between two revisions, changes from <b>rev1</b> up to <b>rev2</b>.
343 * 343 *
344 * @param rev1 <em>from</em> changeset index 344 * @param rev1 <em>from</em> changeset index
345 * @param rev2 <em>to</em> changeset index 345 * @param rev2 <em>to</em> changeset index
346 * @return information object that describes change between the revisions 346 * @return information object that describes change between the revisions
347 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> 347 * @throws HgInvalidRevisionException if any supplied revision doesn't identify changeset revision. <em>Runtime exception</em>
348 */ 348 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
349 public Record status(int rev1, int rev2) throws HgInvalidRevisionException, HgInvalidControlFileException { 349 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
350 */
351 public Record status(int rev1, int rev2) throws HgRuntimeException {
350 Record rv = new Record(); 352 Record rv = new Record();
351 try { 353 try {
352 walk(rev1, rev2, rv); 354 walk(rev1, rev2, rv);
353 } catch (CancelledException ex) { 355 } catch (CancelledException ex) {
354 // can't happen as long our Record class doesn't implement CancelSupport 356 // can't happen as long our Record class doesn't implement CancelSupport
357 throw t; 359 throw t;
358 } 360 }
359 return rv; 361 return rv;
360 } 362 }
361 363
362 /*package-local*/static Path getOriginIfCopy(HgRepository hgRepo, Path fname, Collection<Path> originals, int originalChangelogRevision) throws HgInvalidFileException { 364 /*package-local*/static Path getOriginIfCopy(HgRepository hgRepo, Path fname, Collection<Path> originals, int originalChangelogRevision) throws HgRuntimeException {
363 HgDataFile df = hgRepo.getFileNode(fname); 365 HgDataFile df = hgRepo.getFileNode(fname);
364 if (!df.exists()) { 366 if (!df.exists()) {
365 String msg = String.format("Didn't find file '%s' in the repo. Perhaps, bad storage name conversion?", fname); 367 String msg = String.format("Didn't find file '%s' in the repo. Perhaps, bad storage name conversion?", fname);
366 throw new HgInvalidFileException(msg, null).setFileName(fname).setRevisionIndex(originalChangelogRevision); 368 throw new HgInvalidFileException(msg, null).setFileName(fname).setRevisionIndex(originalChangelogRevision);
367 } 369 }
415 startRev = startRevision; 417 startRev = startRevision;
416 endRev = endRevision; 418 endRev = endRevision;
417 statusHelper = self; 419 statusHelper = self;
418 } 420 }
419 421
420 public Nodeid nodeidBeforeChange(Path fname) throws HgInvalidControlFileException { 422 public Nodeid nodeidBeforeChange(Path fname) throws HgRuntimeException {
421 if (statusHelper == null || startRev == BAD_REVISION) { 423 if (statusHelper == null || startRev == BAD_REVISION) {
422 return null; 424 return null;
423 } 425 }
424 if ((modified == null || !modified.contains(fname)) && (removed == null || !removed.contains(fname))) { 426 if ((modified == null || !modified.contains(fname)) && (removed == null || !removed.contains(fname))) {
425 return null; 427 return null;
426 } 428 }
427 return statusHelper.raw(startRev).nodeid(fname); 429 return statusHelper.raw(startRev).nodeid(fname);
428 } 430 }
429 public Nodeid nodeidAfterChange(Path fname) throws HgInvalidControlFileException { 431 public Nodeid nodeidAfterChange(Path fname) throws HgRuntimeException {
430 if (statusHelper == null || endRev == BAD_REVISION) { 432 if (statusHelper == null || endRev == BAD_REVISION) {
431 return null; 433 return null;
432 } 434 }
433 if ((modified == null || !modified.contains(fname)) && (added == null || !added.contains(fname))) { 435 if ((modified == null || !modified.contains(fname)) && (added == null || !added.contains(fname))) {
434 return null; 436 return null;