{"thread":{"id":"21098","subject":"[JGIT PATCH] Include description for missing prereqs","startedAt":"2009-09-30T14:41:52Z","lastAt":"2009-09-30T14:41:52Z","messageCount":1,"participants":["Sasa Zivkov"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"124032","messageId":"1254321712-1936-1-git-send-email-sasa.zivkov@sap.com","threadId":"21098","inReplyTo":null,"subject":"[JGIT PATCH] Include description for missing prereqs","fromName":"Sasa Zivkov","fromEmail":"sasa.zivkov@sap.com","sentAt":"2009-09-30T14:41:52Z","receivedAt":"2009-09-30T14:41:52Z","isPatch":true,"sender":{"key":"sasa.zivkov@sap.com","avatar":null},"body":"From: Sasa Zivkov <sasa.zivkov@sap.com>\n\nWhen throwing MissingBundlePrerequisiteException we\nalso include the short description, if available, of\neach missing object.\n\nThis is the fix for the following issue:\nhttp://code.google.com/p/egit/issues/detail?id=25\n\nSigned-off-by: Sasa Zivkov <sasa.zivkov@sap.com>\n---\n .../errors/MissingBundlePrerequisiteException.java |   19 +++++++++++--------\n .../jgit/transport/BundleFetchConnection.java      |   20 +++++++++++++-------\n 2 files changed, 24 insertions(+), 15 deletions(-)\n\ndiff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/MissingBundlePrerequisiteException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/MissingBundlePrerequisiteException.java\nindex cc7b34b..b91f3cd 100644\n--- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/MissingBundlePrerequisiteException.java\n+++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/MissingBundlePrerequisiteException.java\n@@ -37,7 +37,7 @@\n \n package org.eclipse.jgit.errors;\n \n-import java.util.Collection;\n+import java.util.Map;\n \n import org.eclipse.jgit.lib.ObjectId;\n import org.eclipse.jgit.transport.URIish;\n@@ -48,12 +48,14 @@\n public class MissingBundlePrerequisiteException extends TransportException {\n \tprivate static final long serialVersionUID = 1L;\n \n-\tprivate static String format(final Collection<ObjectId> ids) {\n+\tprivate static String format(final Map<ObjectId, String> missingCommits) {\n \t\tfinal StringBuilder r = new StringBuilder();\n \t\tr.append(\"missing prerequisite commits:\");\n-\t\tfor (final ObjectId p : ids) {\n+\t\tfor (final Map.Entry<ObjectId, String> e : missingCommits.entrySet()) {\n \t\t\tr.append(\"\\n  \");\n-\t\t\tr.append(p.name());\n+\t\t\tr.append(e.getKey().name());\n+\t\t\tif (e.getValue() != null)\n+\t\t\t\tr.append(\" \").append(e.getValue());\n \t\t}\n \t\treturn r.toString();\n \t}\n@@ -63,11 +65,12 @@ private static String format(final Collection<ObjectId> ids) {\n \t *\n \t * @param uri\n \t *            URI used for transport\n-\t * @param ids\n-\t *            the ids of the base/common object(s) we don't have.\n+\t * @param missingCommits\n+\t *            the Map of the base/common object(s) we don't have. Keys are\n+\t *            ids of the missing objects and values are short descriptions.\n \t */\n \tpublic MissingBundlePrerequisiteException(final URIish uri,\n-\t\t\tfinal Collection<ObjectId> ids) {\n-\t\tsuper(uri, format(ids));\n+\t\t\tfinal Map<ObjectId, String> missingCommits) {\n+\t\tsuper(uri, format(missingCommits));\n \t}\n }\ndiff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java\nindex 42888cf..ceb51d9 100644\n--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java\n+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java\n@@ -44,9 +44,10 @@\n import java.util.ArrayList;\n import java.util.Collection;\n import java.util.Collections;\n-import java.util.HashSet;\n+import java.util.HashMap;\n import java.util.LinkedHashMap;\n import java.util.List;\n+import java.util.Map;\n import java.util.Set;\n \n import org.eclipse.jgit.errors.MissingBundlePrerequisiteException;\n@@ -75,7 +76,7 @@\n \n \tInputStream bin;\n \n-\tfinal Set<ObjectId> prereqs = new HashSet<ObjectId>();\n+\tfinal Map<ObjectId, String> prereqs = new HashMap<ObjectId, String>();\n \n \tprivate String lockMessage;\n \n@@ -120,7 +121,11 @@ private void readBundleV2() throws IOException {\n \t\t\t\tbreak;\n \n \t\t\tif (line.charAt(0) == '-') {\n-\t\t\t\tprereqs.add(ObjectId.fromString(line.substring(1, 41)));\n+\t\t\t\tObjectId id = ObjectId.fromString(line.substring(1, 41));\n+\t\t\t\tString shortDesc = null;\n+\t\t\t\tif (line.length() > 42)\n+\t\t\t\t\tshortDesc = line.substring(42);\n+\t\t\t\tprereqs.put(id, shortDesc);\n \t\t\t\tcontinue;\n \t\t\t}\n \n@@ -199,9 +204,10 @@ private void verifyPrerequisites() throws TransportException {\n \t\tfinal RevFlag PREREQ = rw.newFlag(\"PREREQ\");\n \t\tfinal RevFlag SEEN = rw.newFlag(\"SEEN\");\n \n-\t\tfinal List<ObjectId> missing = new ArrayList<ObjectId>();\n+\t\tfinal Map<ObjectId, String> missing = new HashMap<ObjectId, String>();\n \t\tfinal List<RevObject> commits = new ArrayList<RevObject>();\n-\t\tfor (final ObjectId p : prereqs) {\n+\t\tfor (final Map.Entry<ObjectId, String> e : prereqs.entrySet()) {\n+\t\t\tObjectId p = e.getKey();\n \t\t\ttry {\n \t\t\t\tfinal RevCommit c = rw.parseCommit(p);\n \t\t\t\tif (!c.has(PREREQ)) {\n@@ -209,7 +215,7 @@ private void verifyPrerequisites() throws TransportException {\n \t\t\t\t\tcommits.add(c);\n \t\t\t\t}\n \t\t\t} catch (MissingObjectException notFound) {\n-\t\t\t\tmissing.add(p);\n+\t\t\t\tmissing.put(p, e.getValue());\n \t\t\t} catch (IOException err) {\n \t\t\t\tthrow new TransportException(transport.uri, \"Cannot read commit \"\n \t\t\t\t\t\t+ p.name(), err);\n@@ -243,7 +249,7 @@ private void verifyPrerequisites() throws TransportException {\n \t\tif (remaining > 0) {\n \t\t\tfor (final RevObject o : commits) {\n \t\t\t\tif (!o.has(SEEN))\n-\t\t\t\t\tmissing.add(o);\n+\t\t\t\t\tmissing.put(o, prereqs.get(o));\n \t\t\t}\n \t\t\tthrow new MissingBundlePrerequisiteException(transport.uri, missing);\n \t\t}\n-- \n1.6.4.msysgit.0\n"}]}