From c9a6980a422b485c23bfd99a939a378c5dd5114c Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 16 Mar 2011 21:50:42 -0700 Subject: [PATCH] UploadPack: Report invalid want lines with ERR Instead of aborting hard with a server-side exception, report an error to the client with "ERR %s" in a context where the client is expecting ACK/NAK. Older clients will report this text to the user, but newer ones know how to format this message in a more user-friendly way. Change-Id: I1879b38988ba66f648c069c10dbfa14c3f34adb2 Signed-off-by: Shawn O. Pearce --- .../org/eclipse/jgit/JGitText.properties | 2 +- .../src/org/eclipse/jgit/JGitText.java | 2 +- .../org/eclipse/jgit/transport/UploadPack.java | 16 ++++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties index 61291f67d0..b606bbb249 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties @@ -303,7 +303,6 @@ notASCIIString=Not ASCII string: {0} notAuthorized=not authorized notAValidPack=Not a valid pack {0} notFound=not found. -notValid={0} not valid nothingToFetch=Nothing to fetch. nothingToPush=Nothing to push. notMergedExceptionMessage=Branch was not deleted as it has not been merged yet; use the force option to delete it anyway @@ -466,6 +465,7 @@ updatingRefFailed=Updating the ref {0} to {1} failed. ReturnCode from RefUpdate. uriNotFound={0} not found userConfigFileInvalid=User config file {0} invalid {1} walkFailure=Walk failure. +wantNotValid=want {0} not valid windowSizeMustBeLesserThanLimit=Window size must be < limit windowSizeMustBePowerOf2=Window size must be power of 2 writeTimedOut=Write timed out diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java index 1ce088461f..5877b4f6a6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java @@ -363,7 +363,6 @@ public class JGitText extends TranslationBundle { /***/ public String notAuthorized; /***/ public String notAValidPack; /***/ public String notFound; - /***/ public String notValid; /***/ public String nothingToFetch; /***/ public String nothingToPush; /***/ public String notMergedExceptionMessage; @@ -526,6 +525,7 @@ public class JGitText extends TranslationBundle { /***/ public String uriNotFound; /***/ public String userConfigFileInvalid; /***/ public String walkFailure; + /***/ public String wantNotValid; /***/ public String windowSizeMustBeLesserThanLimit; /***/ public String windowSizeMustBePowerOf2; /***/ public String writeTimedOut; 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 58a48f10e7..4b225575e8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -511,10 +511,12 @@ public class UploadPack { try { obj = q.next(); } catch (MissingObjectException notFound) { - if (wantIds.contains(notFound.getObjectId())) { - throw new PackProtocolException( - MessageFormat.format(JGitText.get().notValid, - notFound.getMessage()), notFound); + ObjectId id = notFound.getObjectId(); + if (wantIds.contains(id)) { + String msg = MessageFormat.format( + JGitText.get().wantNotValid, id.name()); + pckOut.writeString("ERR " + msg); + throw new PackProtocolException(msg, notFound); } continue; } @@ -526,8 +528,10 @@ public class UploadPack { // if (wantIds.remove(obj)) { if (!advertised.contains(obj)) { - throw new PackProtocolException(MessageFormat.format( - JGitText.get().notValid, obj.name())); + String msg = MessageFormat.format( + JGitText.get().wantNotValid, obj.name()); + pckOut.writeString("ERR " + msg); + throw new PackProtocolException(msg); } if (!obj.has(WANT)) { -- 2.39.5