diff options
author | Masaya Suzuki <masayasuzuki@google.com> | 2019-07-23 10:36:14 -0700 |
---|---|---|
committer | Masaya Suzuki <masayasuzuki@google.com> | 2019-10-09 10:02:01 -0700 |
commit | 1e3a7bcef7902e4f035441d878ee056345883197 (patch) | |
tree | 0242aa579cbbb80ee2dcf91c76f36368ffc45c9f /org.eclipse.jgit | |
parent | 63bd24cf356af4a354ef452b01411d1f2cbbec80 (diff) | |
download | jgit-1e3a7bcef7902e4f035441d878ee056345883197.tar.gz jgit-1e3a7bcef7902e4f035441d878ee056345883197.zip |
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>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java | 90 |
1 files changed, 29 insertions, 61 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 b664cfe7bc..8d725b0b58 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -809,11 +809,6 @@ public class UploadPack { } else { 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) { if (!err.isOutput() && err.getMessage() != null) { try { @@ -2117,45 +2112,42 @@ public class UploadPack { Set<String> caps = req.getClientCapabilities(); boolean sideband = caps.contains(OPTION_SIDE_BAND) || caps.contains(OPTION_SIDE_BAND_64K); + if (sideband) { errOut = new SideBandErrorWriter(); - try { - sendPack(true, req, accumulator, allTags, unshallowCommits, - deepenNots, pckOut); - } catch (ServiceMayNotContinueException err) { - String message = err.getMessage(); - if (message == null) { - message = JGitText.get().internalServerError; - } - try { - errOut.writeError(message); - } catch (IOException e) { - err.addSuppressed(e); - 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); + int bufsz = SideBandOutputStream.SMALL_BUF; + if (req.getClientCapabilities().contains(OPTION_SIDE_BAND_64K)) { + bufsz = SideBandOutputStream.MAX_BUF; + } + OutputStream packOut = new SideBandOutputStream( + SideBandOutputStream.CH_DATA, bufsz, rawOut); + + ProgressMonitor pm = NullProgressMonitor.INSTANCE; + if (!req.getClientCapabilities().contains(OPTION_NO_PROGRESS)) { + msgOut = new SideBandOutputStream( + SideBandOutputStream.CH_PROGRESS, bufsz, rawOut); + pm = new SideBandProgressMonitor(msgOut); } + + sendPack(pm, pckOut, packOut, req, accumulator, allTags, + unshallowCommits, deepenNots); + pckOut.end(); } else { - sendPack(false, req, accumulator, allTags, unshallowCommits, deepenNots, - pckOut); + sendPack(NullProgressMonitor.INSTANCE, pckOut, rawOut, req, + accumulator, allTags, unshallowCommits, deepenNots); } } /** * Send the requested objects to the client. * - * @param sideband - * whether to wrap the pack in side-band pkt-lines, interleaved - * with progress messages and errors. + * @param pm + * progress monitor + * @param pckOut + * PacketLineOut that shares the output with packOut + * @param packOut + * packfile output * @param req * request being processed * @param accumulator @@ -2167,35 +2159,14 @@ public class UploadPack { * shallow commits on the client that are now becoming unshallow * @param deepenNots * objects that the client specified using --shallow-exclude - * @param pckOut - * output writer * @throws IOException * if an error occurred while generating or writing the pack. */ - private void sendPack(final boolean sideband, - FetchRequest req, + private void sendPack(ProgressMonitor pm, PacketLineOut pckOut, + OutputStream packOut, FetchRequest req, PackStatistics.Accumulator accumulator, - @Nullable Collection<Ref> allTags, - List<ObjectId> unshallowCommits, - 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); - } - } - + @Nullable Collection<Ref> allTags, List<ObjectId> unshallowCommits, + List<ObjectId> deepenNots) throws IOException { if (wantAll.isEmpty()) { preUploadHook.onSendPack(this, wantIds, commonBase); } else { @@ -2338,9 +2309,6 @@ public class UploadPack { } pw.close(); } - - if (sideband) - pckOut.end(); } private static void findSymrefs( |