summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSasa Zivkov <sasa.zivkov@sap.com>2012-06-06 12:07:47 +0200
committerSasa Zivkov <sasa.zivkov@sap.com>2012-06-06 12:51:11 +0200
commitc347a0b534d9fef53c2056254ee88da8e4e88b86 (patch)
tree228d9bb057e535eedceed3e90d69b2dc09d4406a
parentd2fa1fdb15493342893e950a11263d5f53b4de21 (diff)
Make sure the "Object too large..." error is printed to the client
When receiving and object larger than receive.maxObjectSizeLimit, Gerrit relied on the JGits ReceivePack.receive to print out the error message. However, JGit didn't print out this error always. Sometimes it would print the error and throw UnpackException and sometimes it would only throw the UnpackException leaving the user without proper explanation why the object was rejected. With this change we print the error from Gerrit. Change-Id: I5165ce0be86c91abf0ad02b5f7d8d2b1000dc493
-rw-r--r--gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Receive.java11
1 files changed, 11 insertions, 0 deletions
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Receive.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Receive.java
index 0e7ff83f53..85f53bfe82 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Receive.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Receive.java
@@ -24,6 +24,7 @@ import com.google.gerrit.server.git.VisibleRefFilter;
import com.google.gerrit.sshd.AbstractGitCommand;
import com.google.inject.Inject;
+import org.eclipse.jgit.errors.TooLargeObjectInPackException;
import org.eclipse.jgit.errors.UnpackException;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.transport.AdvertiseRefsHook;
@@ -31,6 +32,7 @@ import org.eclipse.jgit.transport.ReceivePack;
import org.kohsuke.args4j.Option;
import java.io.IOException;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -92,6 +94,15 @@ final class Receive extends AbstractGitCommand {
receive.advertiseHistory();
rp.receive(in, out, err);
} catch (UnpackException badStream) {
+ // In case this was caused by the user pushing an object whose size
+ // is larger than the receive.maxObjectSizeLimit gerrit.config parameter
+ // we want to present this error to the user
+ if (badStream.getCause() instanceof TooLargeObjectInPackException) {
+ PrintWriter p = toPrintWriter(err);
+ p.print("error: " + badStream.getCause().getMessage() + "\n");
+ p.flush();
+ }
+
// This may have been triggered by branch level access controls.
// Log what the heck is going on, as detailed as we can.
//