summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-08-24 16:26:40 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-08-25 17:07:12 -0700
commit401d3b2cc1dc91cd457f0ff8d9149aca50466426 (patch)
treec2ea42d92c30c3c10b75606782cc11db52fd5f54 /org.eclipse.jgit
parentc44495fa2f6ac0b06dc974d1b6626cf52380ea2c (diff)
downloadjgit-401d3b2cc1dc91cd457f0ff8d9149aca50466426.tar.gz
jgit-401d3b2cc1dc91cd457f0ff8d9149aca50466426.zip
Throw AmbiguousObjectException during resolve if its ambiguous
Its wrong to return null if we are resolving an abbreviation and we have proven it matches more than one object. We know how to resolve it if we had more nybbles, as there are two or more objects with the same prefix. Declare that to the caller quite clearly by giving them an AmbiguousObjectException. Change-Id: I01bb48e587e6d001b93da8575c2c81af3eda5a32 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java10
1 files changed, 9 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
index b62f62b347..078b293f41 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -63,6 +63,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
@@ -393,10 +394,15 @@ public abstract class Repository {
* @param revstr
* A git object references expression
* @return an ObjectId or null if revstr can't be resolved to any ObjectId
+ * @throws AmbiguousObjectException
+ * {@code revstr} contains an abbreviated ObjectId and this
+ * repository contains more than one object which match to the
+ * input abbreviation.
* @throws IOException
* on serious errors
*/
- public ObjectId resolve(final String revstr) throws IOException {
+ public ObjectId resolve(final String revstr)
+ throws AmbiguousObjectException, IOException {
RevWalk rw = new RevWalk(this);
try {
return resolve(rw, revstr);
@@ -584,6 +590,8 @@ public abstract class Repository {
Collection<ObjectId> matches = reader.resolve(id);
if (matches.size() == 1)
return matches.iterator().next();
+ if (1 < matches.size())
+ throw new AmbiguousObjectException(id, matches);
} finally {
reader.release();
}