From: Ivan Frade Date: Tue, 16 Oct 2018 23:37:18 +0000 (-0700) Subject: UploadPack: Use request instead of field for client capabilities X-Git-Tag: v5.2.0.201811281532-m3~77 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0691c4b94b5a605da50144b8daeb497332d75577;p=jgit.git UploadPack: Use request instead of field for client capabilities Change-Id: Idc21e2b3fd145d2a4b15c1cea5ec1956541e3b40 Signed-off-by: Ivan Frade --- 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 4639cbd44e..58cd564114 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -286,8 +286,7 @@ public class UploadPack { /** Hook for taking post upload actions. */ private PostUploadHook postUploadHook = PostUploadHook.NULL; - /** Capabilities requested by the client. */ - private Set options; + /** Caller user agent */ String userAgent; /** Raw ObjectIds the client has asked for, before validating them. */ @@ -681,10 +680,12 @@ public class UploadPack { * read. */ public boolean isSideBand() throws RequestNotYetReadException { - if (options == null) + if (currentRequest == null) { throw new RequestNotYetReadException(); - return (options.contains(OPTION_SIDE_BAND) - || options.contains(OPTION_SIDE_BAND_64K)); + } + Set caps = currentRequest.getClientCapabilities(); + return caps.contains(OPTION_SIDE_BAND) + || caps.contains(OPTION_SIDE_BAND_64K); } /** @@ -815,7 +816,6 @@ public class UploadPack { currentRequest = req; wantIds = req.getWantIds(); - options = req.getClientCapabilities(); if (req.getWantIds().isEmpty()) { preUploadHook.onBeginNegotiateRound(this, req.getWantIds(), 0); @@ -956,7 +956,6 @@ public class UploadPack { // TODO(ifrade): Refactor to pass around the Request object, instead of // copying data back to class fields - options = req.getClientCapabilities(); wantIds = req.getWantIds(); boolean sectionSent = false; @@ -1368,7 +1367,12 @@ public class UploadPack { * @since 4.0 */ public String getPeerUserAgent() { - return UserAgent.getAgent(options, userAgent); + if (currentRequest == null) { + return userAgent; + } + + return UserAgent.getAgent(currentRequest.getClientCapabilities(), + userAgent); } private boolean negotiate(FetchRequest req, @@ -1784,8 +1788,9 @@ public class UploadPack { FetchRequest req, @Nullable Collection allTags, List unshallowCommits) throws IOException { - final boolean sideband = options.contains(OPTION_SIDE_BAND) - || options.contains(OPTION_SIDE_BAND_64K); + Set caps = req.getClientCapabilities(); + boolean sideband = caps.contains(OPTION_SIDE_BAND) + || caps.contains(OPTION_SIDE_BAND_64K); if (sideband) { try { sendPack(true, req, accumulator, allTags, unshallowCommits); @@ -1857,12 +1862,12 @@ public class UploadPack { if (sideband) { int bufsz = SideBandOutputStream.SMALL_BUF; - if (options.contains(OPTION_SIDE_BAND_64K)) + if (req.getClientCapabilities().contains(OPTION_SIDE_BAND_64K)) bufsz = SideBandOutputStream.MAX_BUF; packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, bufsz, rawOut); - if (!options.contains(OPTION_NO_PROGRESS)) { + if (!req.getClientCapabilities().contains(OPTION_NO_PROGRESS)) { msgOut = new SideBandOutputStream( SideBandOutputStream.CH_PROGRESS, bufsz, rawOut); pm = new SideBandProgressMonitor(msgOut); @@ -1909,8 +1914,9 @@ public class UploadPack { && req.getClientShallowCommits().isEmpty()); pw.setClientShallowCommits(req.getClientShallowCommits()); pw.setReuseDeltaCommits(true); - pw.setDeltaBaseAsOffset(options.contains(OPTION_OFS_DELTA)); - pw.setThin(options.contains(OPTION_THIN_PACK)); + pw.setDeltaBaseAsOffset( + req.getClientCapabilities().contains(OPTION_OFS_DELTA)); + pw.setThin(req.getClientCapabilities().contains(OPTION_THIN_PACK)); pw.setReuseValidatingObjects(false); // Objects named directly by references go at the beginning @@ -1949,7 +1955,8 @@ public class UploadPack { rw = ow; } - if (options.contains(OPTION_INCLUDE_TAG) && allTags != null) { + if (req.getClientCapabilities().contains(OPTION_INCLUDE_TAG) + && allTags != null) { for (Ref ref : allTags) { ObjectId objectId = ref.getObjectId(); if (objectId == null) {