Browse Source

UploadPack: Consolidate the sideband handling code to one place

This consolidates the sideband stream creation code and the error
handling code for the sideband-allowed part in the Git protocol to one
place.

Change-Id: I0e3e94564f50d1be32006f9d8bcd1ef1ce6bf07e
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
next
Masaya Suzuki 5 years ago
parent
commit
1e3a7bcef7
  1. 90
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

90
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

@ -809,11 +809,6 @@ public class UploadPack {
} else { } else {
service(pckOut); service(pckOut);
} }
} catch (UploadPackInternalServerErrorException err) {
// UploadPackInternalServerErrorException is a special exception
// that indicates an error is already written to the client. Do
// nothing.
throw err;
} catch (ServiceMayNotContinueException err) { } catch (ServiceMayNotContinueException err) {
if (!err.isOutput() && err.getMessage() != null) { if (!err.isOutput() && err.getMessage() != null) {
try { try {
@ -2117,45 +2112,42 @@ public class UploadPack {
Set<String> caps = req.getClientCapabilities(); Set<String> caps = req.getClientCapabilities();
boolean sideband = caps.contains(OPTION_SIDE_BAND) boolean sideband = caps.contains(OPTION_SIDE_BAND)
|| caps.contains(OPTION_SIDE_BAND_64K); || caps.contains(OPTION_SIDE_BAND_64K);
if (sideband) { if (sideband) {
errOut = new SideBandErrorWriter(); errOut = new SideBandErrorWriter();
try { int bufsz = SideBandOutputStream.SMALL_BUF;
sendPack(true, req, accumulator, allTags, unshallowCommits, if (req.getClientCapabilities().contains(OPTION_SIDE_BAND_64K)) {
deepenNots, pckOut); bufsz = SideBandOutputStream.MAX_BUF;
} catch (ServiceMayNotContinueException err) { }
String message = err.getMessage(); OutputStream packOut = new SideBandOutputStream(
if (message == null) { SideBandOutputStream.CH_DATA, bufsz, rawOut);
message = JGitText.get().internalServerError;
} ProgressMonitor pm = NullProgressMonitor.INSTANCE;
try { if (!req.getClientCapabilities().contains(OPTION_NO_PROGRESS)) {
errOut.writeError(message); msgOut = new SideBandOutputStream(
} catch (IOException e) { SideBandOutputStream.CH_PROGRESS, bufsz, rawOut);
err.addSuppressed(e); pm = new SideBandProgressMonitor(msgOut);
throw err;
}
throw new UploadPackInternalServerErrorException(err);
} catch (IOException | RuntimeException | Error err) {
try {
errOut.writeError(JGitText.get().internalServerError);
} catch (IOException e) {
err.addSuppressed(e);
throw err;
}
throw new UploadPackInternalServerErrorException(err);
} }
sendPack(pm, pckOut, packOut, req, accumulator, allTags,
unshallowCommits, deepenNots);
pckOut.end();
} else { } else {
sendPack(false, req, accumulator, allTags, unshallowCommits, deepenNots, sendPack(NullProgressMonitor.INSTANCE, pckOut, rawOut, req,
pckOut); accumulator, allTags, unshallowCommits, deepenNots);
} }
} }
/** /**
* Send the requested objects to the client. * Send the requested objects to the client.
* *
* @param sideband * @param pm
* whether to wrap the pack in side-band pkt-lines, interleaved * progress monitor
* with progress messages and errors. * @param pckOut
* PacketLineOut that shares the output with packOut
* @param packOut
* packfile output
* @param req * @param req
* request being processed * request being processed
* @param accumulator * @param accumulator
@ -2167,35 +2159,14 @@ public class UploadPack {
* shallow commits on the client that are now becoming unshallow * shallow commits on the client that are now becoming unshallow
* @param deepenNots * @param deepenNots
* objects that the client specified using --shallow-exclude * objects that the client specified using --shallow-exclude
* @param pckOut
* output writer
* @throws IOException * @throws IOException
* if an error occurred while generating or writing the pack. * if an error occurred while generating or writing the pack.
*/ */
private void sendPack(final boolean sideband, private void sendPack(ProgressMonitor pm, PacketLineOut pckOut,
FetchRequest req, OutputStream packOut, FetchRequest req,
PackStatistics.Accumulator accumulator, PackStatistics.Accumulator accumulator,
@Nullable Collection<Ref> allTags, @Nullable Collection<Ref> allTags, List<ObjectId> unshallowCommits,
List<ObjectId> unshallowCommits, List<ObjectId> deepenNots) throws IOException {
List<ObjectId> deepenNots,
PacketLineOut pckOut) throws IOException {
ProgressMonitor pm = NullProgressMonitor.INSTANCE;
OutputStream packOut = rawOut;
if (sideband) {
int bufsz = SideBandOutputStream.SMALL_BUF;
if (req.getClientCapabilities().contains(OPTION_SIDE_BAND_64K))
bufsz = SideBandOutputStream.MAX_BUF;
packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA,
bufsz, rawOut);
if (!req.getClientCapabilities().contains(OPTION_NO_PROGRESS)) {
msgOut = new SideBandOutputStream(
SideBandOutputStream.CH_PROGRESS, bufsz, rawOut);
pm = new SideBandProgressMonitor(msgOut);
}
}
if (wantAll.isEmpty()) { if (wantAll.isEmpty()) {
preUploadHook.onSendPack(this, wantIds, commonBase); preUploadHook.onSendPack(this, wantIds, commonBase);
} else { } else {
@ -2338,9 +2309,6 @@ public class UploadPack {
} }
pw.close(); pw.close();
} }
if (sideband)
pckOut.end();
} }
private static void findSymrefs( private static void findSymrefs(

Loading…
Cancel
Save