summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2013-05-22 12:12:52 -0700
committerShawn Pearce <spearce@spearce.org>2013-05-22 12:14:08 -0700
commit6e896ba66ba095b97a89a622d43f05ce9ad501e7 (patch)
tree12defc1699b622d9ca58adf88f27b18e341cd9cb /org.eclipse.jgit
parent3e58471ee3b671b9b9ebdb7c909a8e7a4647a688 (diff)
downloadjgit-6e896ba66ba095b97a89a622d43f05ce9ad501e7.tar.gz
jgit-6e896ba66ba095b97a89a622d43f05ce9ad501e7.zip
Allow PreUploadHook.onSendPack to send messages to the client
Before transmitting to the client a hook may want to send along a text message ahead of the pack, such as a "message of the day". Enable this usage by mirroring the message sending API from ReceivePack on the UploadPack instance, using the side band. Change-Id: I31cd254a4ddb816641397a3e9c2c20212471c37f
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java32
1 files changed, 30 insertions, 2 deletions
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 5347eb713c..6ae08acaa2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -80,6 +80,7 @@ import org.eclipse.jgit.revwalk.filter.CommitTimeRevFilter;
import org.eclipse.jgit.storage.pack.PackConfig;
import org.eclipse.jgit.transport.BasePackFetchConnection.MultiAck;
import org.eclipse.jgit.transport.RefAdvertiser.PacketLineOutRefAdvertiser;
+import org.eclipse.jgit.util.io.DisabledOutputStream;
import org.eclipse.jgit.util.io.InterruptTimer;
import org.eclipse.jgit.util.io.TimeoutInputStream;
import org.eclipse.jgit.util.io.TimeoutOutputStream;
@@ -192,6 +193,8 @@ public class UploadPack {
private PacketLineOut pckOut;
+ private OutputStream msgOut = DisabledOutputStream.INSTANCE;
+
/** The refs we advertised as existing at the start of the connection. */
private Map<String, Ref> refs;
@@ -504,6 +507,8 @@ public class UploadPack {
try {
rawIn = input;
rawOut = output;
+ if (messages != null)
+ msgOut = messages;
if (timeout > 0) {
final Thread caller = Thread.currentThread();
@@ -520,6 +525,7 @@ public class UploadPack {
pckOut = new PacketLineOut(rawOut);
service();
} finally {
+ msgOut = DisabledOutputStream.INSTANCE;
walk.release();
if (timer != null) {
try {
@@ -692,6 +698,29 @@ public class UploadPack {
adv.end();
}
+ /**
+ * Send a message to the client, if it supports receiving them.
+ * <p>
+ * If the client doesn't support receiving messages, the message will be
+ * discarded, with no other indication to the caller or to the client.
+ *
+ * @param what
+ * string describing the problem identified by the hook. The
+ * string must not end with an LF, and must not contain an LF.
+ */
+ public void sendMessage(String what) {
+ try {
+ msgOut.write(Constants.encode(what + "\n")); //$NON-NLS-1$
+ } catch (IOException e) {
+ // Ignore write failures.
+ }
+ }
+
+ /** @return an underlying stream for sending messages to the client, or null. */
+ public OutputStream getMessageOutputStream() {
+ return msgOut;
+ }
+
private void recvWants() throws IOException {
boolean isFirst = true;
for (;;) {
@@ -1076,7 +1105,6 @@ public class UploadPack {
private void sendPack(final boolean sideband) throws IOException {
ProgressMonitor pm = NullProgressMonitor.INSTANCE;
OutputStream packOut = rawOut;
- SideBandOutputStream msgOut = null;
if (sideband) {
int bufsz = SideBandOutputStream.SMALL_BUF;
@@ -1181,7 +1209,7 @@ public class UploadPack {
pw.writePack(pm, NullProgressMonitor.INSTANCE, packOut);
statistics = pw.getStatistics();
- if (msgOut != null) {
+ if (msgOut != DisabledOutputStream.INSTANCE) {
String msg = pw.getStatistics().getMessage() + '\n';
msgOut.write(Constants.encode(msg));
msgOut.flush();