Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/Revlog.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 |
---|---|
27 import java.util.Collection; | 27 import java.util.Collection; |
28 import java.util.HashSet; | 28 import java.util.HashSet; |
29 import java.util.LinkedList; | 29 import java.util.LinkedList; |
30 import java.util.List; | 30 import java.util.List; |
31 | 31 |
32 import org.tmatesoft.hg.core.HgBadStateException; | |
33 import org.tmatesoft.hg.core.HgException; | 32 import org.tmatesoft.hg.core.HgException; |
34 import org.tmatesoft.hg.core.HgInvalidControlFileException; | |
35 import org.tmatesoft.hg.core.HgInvalidRevisionException; | |
36 import org.tmatesoft.hg.core.Nodeid; | 33 import org.tmatesoft.hg.core.Nodeid; |
37 import org.tmatesoft.hg.internal.ArrayHelper; | 34 import org.tmatesoft.hg.internal.ArrayHelper; |
38 import org.tmatesoft.hg.internal.DataAccess; | 35 import org.tmatesoft.hg.internal.DataAccess; |
39 import org.tmatesoft.hg.internal.Experimental; | 36 import org.tmatesoft.hg.internal.Experimental; |
40 import org.tmatesoft.hg.internal.Preview; | 37 import org.tmatesoft.hg.internal.Preview; |
170 if (BAD_REVISION == rn) { | 167 if (BAD_REVISION == rn) { |
171 return false; | 168 return false; |
172 } | 169 } |
173 if (rn < 0 || rn >= content.revisionCount()) { | 170 if (rn < 0 || rn >= content.revisionCount()) { |
174 // Sanity check | 171 // Sanity check |
175 throw new HgBadStateException(String.format("Revision index %d found for nodeid %s is not from the range [0..%d]", rn, nodeid.shortNotation(), content.revisionCount()-1)); | 172 throw new HgInvalidStateException(String.format("Revision index %d found for nodeid %s is not from the range [0..%d]", rn, nodeid.shortNotation(), content.revisionCount()-1)); |
176 } | 173 } |
177 return true; | 174 return true; |
178 } | 175 } |
179 | 176 |
180 /** | 177 /** |
397 } | 394 } |
398 } | 395 } |
399 | 396 |
400 private void assertSortedIndex(int x) { | 397 private void assertSortedIndex(int x) { |
401 if (x < 0) { | 398 if (x < 0) { |
402 throw new HgBadStateException(String.format("Bad index", x)); | 399 throw new HgInvalidStateException(String.format("Bad index", x)); |
403 } | 400 } |
404 } | 401 } |
405 | 402 |
406 /** | 403 /** |
407 * Tells whether supplied revision is from the walker's associated revlog. | 404 * Tells whether supplied revision is from the walker's associated revlog. |
615 protected void recordFailure(Exception ex) { | 612 protected void recordFailure(Exception ex) { |
616 assert failure == null; | 613 assert failure == null; |
617 failure = ex; | 614 failure = ex; |
618 } | 615 } |
619 | 616 |
617 // FIXME is HgException of any use here now? | |
620 // TODO consider if IOException in addition to HgException is of any real utility | 618 // TODO consider if IOException in addition to HgException is of any real utility |
621 public void checkFailed() throws HgException, IOException, CancelledException { | 619 public void checkFailed() throws HgException, IOException, CancelledException { |
622 if (failure == null) { | 620 if (failure == null) { |
623 return; | 621 return; |
624 } | 622 } |
629 throw (CancelledException) failure; | 627 throw (CancelledException) failure; |
630 } | 628 } |
631 if (failure instanceof HgException) { | 629 if (failure instanceof HgException) { |
632 throw (HgException) failure; | 630 throw (HgException) failure; |
633 } | 631 } |
634 throw new HgBadStateException(failure); | 632 throw new HgInvalidStateException(failure.toString()); |
635 } | 633 } |
636 | 634 |
637 public void checkCancelled() throws CancelledException { | 635 public void checkCancelled() throws CancelledException { |
638 if (cancelSupport != null) { | 636 if (cancelSupport != null) { |
639 cancelSupport.checkCancelled(); | 637 cancelSupport.checkCancelled(); |
695 int consumed = sink.write(buf); | 693 int consumed = sink.write(buf); |
696 if ((consumed == 0 || consumed != buf.position()) && logFacility != null) { | 694 if ((consumed == 0 || consumed != buf.position()) && logFacility != null) { |
697 logFacility.warn(getClass(), "Bad data sink when reading revision %d. Reported %d bytes consumed, byt actually read %d", revisionNumber, consumed, buf.position()); | 695 logFacility.warn(getClass(), "Bad data sink when reading revision %d. Reported %d bytes consumed, byt actually read %d", revisionNumber, consumed, buf.position()); |
698 } | 696 } |
699 if (buf.position() == 0) { | 697 if (buf.position() == 0) { |
700 throw new HgBadStateException("Bad sink implementation (consumes no bytes) results in endless loop"); | 698 throw new HgInvalidStateException("Bad sink implementation (consumes no bytes) results in endless loop"); |
701 } | 699 } |
702 buf.compact(); // ensure (a) there's space for new (b) data starts at 0 | 700 buf.compact(); // ensure (a) there's space for new (b) data starts at 0 |
703 progressSupport.worked(consumed); | 701 progressSupport.worked(consumed); |
704 } | 702 } |
705 progressSupport.done(); // XXX shall specify whether #done() is invoked always or only if completed successfully. | 703 progressSupport.done(); // XXX shall specify whether #done() is invoked always or only if completed successfully. |