summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-06-23 17:26:44 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-06-23 17:32:40 -0700
commit47c07e1a0dec79cb87fc5ccd6ee9b5e64992efb5 (patch)
tree34b6320e5e44ff1b52dd7b149854dca8d181eabe
parent599c0ce745ab0322fc110a374bacf3c5a142da7b (diff)
downloadjgit-47c07e1a0dec79cb87fc5ccd6ee9b5e64992efb5.tar.gz
jgit-47c07e1a0dec79cb87fc5ccd6ee9b5e64992efb5.zip
Replace manual peel loops with RevWalk.peel
Instead of peeling things by hand in application level code, defer the peeling logic into RevWalk's new peel utility method. Change-Id: Idabd10dc41502e782f6a2eeb56f09566b97775a8 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDirectory.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java35
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java13
4 files changed, 35 insertions, 23 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDirectory.java
index e306baabb3..b6fd10d018 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDirectory.java
@@ -409,12 +409,8 @@ public class RefDirectory extends RefDatabase {
RevObject obj = rw.parseAny(leaf.getObjectId());
ObjectIdRef newLeaf;
if (obj instanceof RevTag) {
- do {
- obj = rw.parseAny(((RevTag) obj).getObject());
- } while (obj instanceof RevTag);
-
newLeaf = new ObjectIdRef.PeeledTag(leaf.getStorage(), leaf
- .getName(), leaf.getObjectId(), obj.copy());
+ .getName(), leaf.getObjectId(), rw.peel(obj).copy());
} else {
newLeaf = new ObjectIdRef.PeeledNonTag(leaf.getStorage(), leaf
.getName(), leaf.getObjectId());
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
index 94e11752c6..e42554811b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
@@ -659,11 +659,7 @@ public class RevWalk implements Iterable<RevCommit> {
public RevCommit parseCommit(final AnyObjectId id)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
- RevObject c = parseAny(id);
- while (c instanceof RevTag) {
- c = ((RevTag) c).getObject();
- parseHeaders(c);
- }
+ RevObject c = peel(parseAny(id));
if (!(c instanceof RevCommit))
throw new IncorrectObjectTypeException(id.toObjectId(),
Constants.TYPE_COMMIT);
@@ -690,11 +686,7 @@ public class RevWalk implements Iterable<RevCommit> {
public RevTree parseTree(final AnyObjectId id)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
- RevObject c = parseAny(id);
- while (c instanceof RevTag) {
- c = ((RevTag) c).getObject();
- parseHeaders(c);
- }
+ RevObject c = peel(parseAny(id));
final RevTree t;
if (c instanceof RevCommit)
@@ -803,6 +795,29 @@ public class RevWalk implements Iterable<RevCommit> {
}
/**
+ * Peel back annotated tags until a non-tag object is found.
+ *
+ * @param obj
+ * the starting object.
+ * @return If {@code obj} is not an annotated tag, {@code obj}. Otherwise
+ * the first non-tag object that {@code obj} references. The
+ * returned object's headers have been parsed.
+ * @throws MissingObjectException
+ * a referenced object cannot be found.
+ * @throws IOException
+ * a pack file or loose object could not be read.
+ */
+ public RevObject peel(RevObject obj) throws MissingObjectException,
+ IOException {
+ while (obj instanceof RevTag) {
+ parseHeaders(obj);
+ obj = ((RevTag) obj).getObject();
+ }
+ parseHeaders(obj);
+ return obj;
+ }
+
+ /**
* Create a new flag for application use during walking.
* <p>
* Applications are only assured to be able to create 24 unique flags on any
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java
index e42b7fe0c9..91105cc8a3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java
@@ -84,7 +84,6 @@ import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevFlag;
import org.eclipse.jgit.revwalk.RevObject;
-import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.ReceiveCommand.Result;
@@ -818,8 +817,7 @@ public class ReceivePack {
ow.markUninteresting(o);
if (checkReferencedIsReachable && !baseObjects.isEmpty()) {
- while (o instanceof RevTag)
- o = ((RevTag) o).getObject();
+ o = ow.peel(o);
if (o instanceof RevCommit)
o = ((RevCommit) o).getTree();
if (o instanceof RevTree)
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
index 77cc1a6f0a..712ad3ff75 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -56,6 +56,7 @@ import java.util.Map;
import java.util.Set;
import org.eclipse.jgit.JGitText;
+import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.PackProtocolException;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
@@ -393,11 +394,15 @@ public class UploadPack {
}
if (!o.has(ADVERTISED))
throw new PackProtocolException(MessageFormat.format(JGitText.get().notValid, id.name()));
- want(o);
+ try {
+ want(o);
+ } catch (IOException e) {
+ throw new PackProtocolException(MessageFormat.format(JGitText.get().notValid, id.name()), e);
+ }
}
}
- private void want(RevObject o) {
+ private void want(RevObject o) throws MissingObjectException, IOException {
if (!o.has(WANT)) {
o.add(WANT);
wantAll.add(o);
@@ -406,9 +411,7 @@ public class UploadPack {
wantCommits.add((RevCommit) o);
else if (o instanceof RevTag) {
- do {
- o = ((RevTag) o).getObject();
- } while (o instanceof RevTag);
+ o = walk.peel(o);
if (o instanceof RevCommit)
want(o);
}