Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasaya Suzuki2019-11-08 18:12:20 +0000
committerMasaya Suzuki2019-12-02 22:03:46 +0000
commit6ccff81428d1df0b020db43268e845cb4ab7ed46 (patch)
tree9c8e8c2a84ee2d265a7bcd22a05caba0bf18b0d0 /org.eclipse.jgit
parent224746e0f201ae1bd8614e3c6204ee832c515578 (diff)
downloadjgit-6ccff81428d1df0b020db43268e845cb4ab7ed46.tar.gz
jgit-6ccff81428d1df0b020db43268e845cb4ab7ed46.tar.xz
jgit-6ccff81428d1df0b020db43268e845cb4ab7ed46.zip
transport: Let users specify an error handler for unpacking a pack file
Currently, there's no way for a user to customize the error handler for the exception happened during unpacking an incoming pack file. Create an error handler class and let them specify one. Change-Id: Id07638ee58c88e1365181c3ddd17ee0266f3934d Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java20
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UnpackErrorHandler.java29
2 files changed, 48 insertions, 1 deletions
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 32c9abc1ac..94cfe6c0a3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java
@@ -299,6 +299,8 @@ public class ReceivePack {
// Use the default implementation.
};
+ private UnpackErrorHandler unpackErrorHandler = new DefaultUnpackErrorHandler();
+
/** Hook to report on the commands after execution. */
private PostReceiveHook postReceive;
@@ -2145,6 +2147,15 @@ public class ReceivePack {
}
/**
+ * @param unpackErrorHandler
+ * the unpackErrorHandler to set
+ * @since 5.7
+ */
+ public void setUnpackErrorHandler(UnpackErrorHandler unpackErrorHandler) {
+ this.unpackErrorHandler = unpackErrorHandler;
+ }
+
+ /**
* Set whether this class will report command failures as warning messages
* before sending the command results.
*
@@ -2220,7 +2231,7 @@ public class ReceivePack {
} catch (IOException | RuntimeException
| SubmoduleValidationException | Error err) {
unlockPack();
- sendStatusReport(err);
+ unpackErrorHandler.handleUnpackException(err);
throw new UnpackException(err);
}
}
@@ -2289,4 +2300,11 @@ public class ReceivePack {
filterCommands(Result.OK));
}
}
+
+ private class DefaultUnpackErrorHandler implements UnpackErrorHandler {
+ @Override
+ public void handleUnpackException(Throwable t) throws IOException {
+ sendStatusReport(t);
+ }
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UnpackErrorHandler.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UnpackErrorHandler.java
new file mode 100644
index 0000000000..12c9a76214
--- /dev/null
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UnpackErrorHandler.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2019, Google LLC and others
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+package org.eclipse.jgit.transport;
+
+import java.io.IOException;
+
+/**
+ * Exception handler for processing an incoming pack file.
+ *
+ * @since 5.7
+ */
+public interface UnpackErrorHandler {
+ /**
+ * Handle an exception thrown while unpacking the pack file.
+ *
+ * @param t
+ * exception thrown
+ * @throws IOException
+ * thrown when failed to write an error back to the client.
+ */
+ void handleUnpackException(Throwable t) throws IOException;
+}

Back to the top