[JGIT PATCH 2/5] Allow exceptions to be created with integer type codes
- From
Shawn O. Pearce <spearce@spearce.org>
- Date
- Jun 12, 2009, 23:00 UTC
- Message-ID
- <1244847619-7364-3-git-send-email-spearce@spearce.org>
- In-Reply-To
- <1244847619-7364-2-git-send-email-spearce@spearce.org>
This may be easier in some contexts where we have the type code we expect handy, but not the type string constant.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org> --- .../jgit/errors/IncorrectObjectTypeException.java | 13 +++++++++++++ .../jgit/errors/MissingObjectException.java | 12 ++++++++++++ 2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/errors/IncorrectObjectTypeException.java b/org.spearce.jgit/src/org/spearce/jgit/errors/IncorrectObjectTypeException.java index a194f19..3af1f44 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/errors/IncorrectObjectTypeException.java +++ b/org.spearce.jgit/src/org/spearce/jgit/errors/IncorrectObjectTypeException.java @@ -40,6 +40,7 @@ import java.io.IOException; +import org.spearce.jgit.lib.Constants; import org.spearce.jgit.lib.ObjectId; /** @@ -62,4 +63,16 @@ public IncorrectObjectTypeException(final ObjectId id, final String type) { super("Object " + id.name() + " is not a " + type + "."); } + + /** + * Construct and IncorrectObjectTypeException for the specified object id. + * + * Provide the type to make it easier to track down the problem. + * + * @param id SHA-1 + * @param type object type + */ + public IncorrectObjectTypeException(final ObjectId id, final int type) { + this(id, Constants.typeString(type)); + } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/errors/MissingObjectException.java b/org.spearce.jgit/src/org/spearce/jgit/errors/MissingObjectException.java index 37147c3..7b7b8f3 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/errors/MissingObjectException.java +++ b/org.spearce.jgit/src/org/spearce/jgit/errors/MissingObjectException.java @@ -40,6 +40,7 @@ import java.io.IOException; +import org.spearce.jgit.lib.Constants; import org.spearce.jgit.lib.ObjectId; /** @@ -58,4 +59,15 @@ public MissingObjectException(final ObjectId id, final String type) { super("Missing " + type + " " + id.name()); } + + /** + * Construct a MissingObjectException for the specified object id. + * Expected type is reported to simplify tracking down the problem. + * + * @param id SHA-1 + * @param type object type + */ + public MissingObjectException(final ObjectId id, final int type) { + this(id, Constants.typeString(type)); + } }
-- 1.6.3.2.367.gf0de