[JGIT PATCH] Include description for missing prereqs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Sasa Zivkov <sasa.zivkov@xxxxxxx>

When throwing MissingBundlePrerequisiteException we
also include the short description, if available, of
each missing object.

This is the fix for the following issue:
http://code.google.com/p/egit/issues/detail?id=25

Signed-off-by: Sasa Zivkov <sasa.zivkov@xxxxxxx>
---
 .../errors/MissingBundlePrerequisiteException.java |   19 +++++++++++--------
 .../jgit/transport/BundleFetchConnection.java      |   20 +++++++++++++-------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/errors/MissingBundlePrerequisiteException.java b/org.spearce.jgit/src/org/spearce/jgit/errors/MissingBundlePrerequisiteException.java
index d2335c1..d90350c 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/errors/MissingBundlePrerequisiteException.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/errors/MissingBundlePrerequisiteException.java
@@ -37,7 +37,7 @@
 
 package org.spearce.jgit.errors;
 
-import java.util.Collection;
+import java.util.Map;
 
 import org.spearce.jgit.lib.ObjectId;
 import org.spearce.jgit.transport.URIish;
@@ -48,12 +48,14 @@
 public class MissingBundlePrerequisiteException extends TransportException {
 	private static final long serialVersionUID = 1L;
 
-	private static String format(final Collection<ObjectId> ids) {
+	private static String format(final Map<ObjectId, String> missingCommits) {
 		final StringBuilder r = new StringBuilder();
 		r.append("missing prerequisite commits:");
-		for (final ObjectId p : ids) {
+		for (final Map.Entry<ObjectId, String> e : missingCommits.entrySet()) {
 			r.append("\n  ");
-			r.append(p.name());
+			r.append(e.getKey().name());
+			if (e.getValue() != null)
+				r.append(" ").append(e.getValue());
 		}
 		return r.toString();
 	}
@@ -63,11 +65,12 @@ private static String format(final Collection<ObjectId> ids) {
 	 *
 	 * @param uri
 	 *            URI used for transport
-	 * @param ids
-	 *            the ids of the base/common object(s) we don't have.
+	 * @param missingCommits
+	 *            the Map of the base/common object(s) we don't have. Keys are
+	 *            ids of the missing objects and values are short descriptions.
 	 */
 	public MissingBundlePrerequisiteException(final URIish uri,
-			final Collection<ObjectId> ids) {
-		super(uri, format(ids));
+			final Map<ObjectId, String> missingCommits) {
+		super(uri, format(missingCommits));
 	}
 }
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/BundleFetchConnection.java b/org.spearce.jgit/src/org/spearce/jgit/transport/BundleFetchConnection.java
index 14e0c7d..034e158 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/BundleFetchConnection.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/BundleFetchConnection.java
@@ -44,9 +44,10 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.spearce.jgit.errors.MissingBundlePrerequisiteException;
@@ -75,7 +76,7 @@
 
 	InputStream bin;
 
-	final Set<ObjectId> prereqs = new HashSet<ObjectId>();
+	final Map<ObjectId, String> prereqs = new HashMap<ObjectId, String>();
 
 	private String lockMessage;
 
@@ -120,7 +121,11 @@ private void readBundleV2() throws IOException {
 				break;
 
 			if (line.charAt(0) == '-') {
-				prereqs.add(ObjectId.fromString(line.substring(1, 41)));
+				ObjectId id = ObjectId.fromString(line.substring(1, 41));
+				String shortDesc = null;
+				if (line.length() > 42)
+					shortDesc = line.substring(42);
+				prereqs.put(id, shortDesc);
 				continue;
 			}
 
@@ -199,9 +204,10 @@ private void verifyPrerequisites() throws TransportException {
 		final RevFlag PREREQ = rw.newFlag("PREREQ");
 		final RevFlag SEEN = rw.newFlag("SEEN");
 
-		final List<ObjectId> missing = new ArrayList<ObjectId>();
+		final Map<ObjectId, String> missing = new HashMap<ObjectId, String>();
 		final List<RevObject> commits = new ArrayList<RevObject>();
-		for (final ObjectId p : prereqs) {
+		for (final Map.Entry<ObjectId, String> e : prereqs.entrySet()) {
+			ObjectId p = e.getKey();
 			try {
 				final RevCommit c = rw.parseCommit(p);
 				if (!c.has(PREREQ)) {
@@ -209,7 +215,7 @@ private void verifyPrerequisites() throws TransportException {
 					commits.add(c);
 				}
 			} catch (MissingObjectException notFound) {
-				missing.add(p);
+				missing.put(p, e.getValue());
 			} catch (IOException err) {
 				throw new TransportException(transport.uri, "Cannot read commit "
 						+ p.name(), err);
@@ -243,7 +249,7 @@ private void verifyPrerequisites() throws TransportException {
 		if (remaining > 0) {
 			for (final RevObject o : commits) {
 				if (!o.has(SEEN))
-					missing.add(o);
+					missing.put(o, prereqs.get(o));
 			}
 			throw new MissingBundlePrerequisiteException(transport.uri, missing);
 		}
-- 
1.6.4.msysgit.0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]