Browse Source

UploadPack: Permit flushing progress messages under smart HTTP

If UploadPack invokes flush() on the output stream we pass it, its
most likely the progress messages coming down the side band stream.
As pack generation can take a while, we want to push that down
at the client as early as we can, to keep the connection alive,
and to let the user know we are still working on their behalf.

Ensure we dump the temporary buffer whenever flush() is invoked,
otherwise the messages don't get sent in a timely fashion to the
user agent (in this case, git fetch).

We specifically don't implement flush() for ReceivePack right now,
as that protocol currently does not provide progress messages to
the user, but it does invoke flush several times, as the different
streams include '0000' type flush-pkts to denote various end points.

Change-Id: I797c90a2c562a416223dc0704785f61ac64e0220
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
ccd0c0c911
  1. 7
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
  2. 19
      org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java

7
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java

@ -107,7 +107,12 @@ class UploadPackServlet extends HttpServlet {
up.setBiDirectionalPipe(false); up.setBiDirectionalPipe(false);
rsp.setContentType(RSP_TYPE); rsp.setContentType(RSP_TYPE);
final SmartOutputStream out = new SmartOutputStream(req, rsp); final SmartOutputStream out = new SmartOutputStream(req, rsp) {
@Override
public void flush() throws IOException {
doFlush();
}
};
up.upload(getInputStream(req), out, null); up.upload(getInputStream(req), out, null);
out.close(); out.close();

19
org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java

@ -138,6 +138,19 @@ public abstract class TemporaryBuffer extends OutputStream {
overflow.write(b, off, len); overflow.write(b, off, len);
} }
/**
* Dumps the entire buffer into the overflow stream, and flushes it.
*
* @throws IOException
* the overflow stream cannot be started, or the buffer contents
* cannot be written to it, or it failed to flush.
*/
protected void doFlush() throws IOException {
if (overflow == null)
switchToOverflow();
overflow.flush();
}
/** /**
* Copy all bytes remaining on the input stream into this buffer. * Copy all bytes remaining on the input stream into this buffer.
* *
@ -260,6 +273,11 @@ public abstract class TemporaryBuffer extends OutputStream {
if (blocks.size() * Block.SZ < inCoreLimit) if (blocks.size() * Block.SZ < inCoreLimit)
return false; return false;
switchToOverflow();
return true;
}
private void switchToOverflow() throws IOException {
overflow = overflow(); overflow = overflow();
final Block last = blocks.remove(blocks.size() - 1); final Block last = blocks.remove(blocks.size() - 1);
@ -269,7 +287,6 @@ public abstract class TemporaryBuffer extends OutputStream {
overflow = new BufferedOutputStream(overflow, Block.SZ); overflow = new BufferedOutputStream(overflow, Block.SZ);
overflow.write(last.buffer, 0, last.count); overflow.write(last.buffer, 0, last.count);
return true;
} }
public void close() throws IOException { public void close() throws IOException {

Loading…
Cancel
Save