Browse Source

UploadPack: Use request instead of field for client capabilities

Change-Id: Idc21e2b3fd145d2a4b15c1cea5ec1956541e3b40
Signed-off-by: Ivan Frade <ifrade@google.com>
stable-5.2
Ivan Frade 6 years ago
parent
commit
0691c4b94b
  1. 37
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

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

@ -286,8 +286,7 @@ public class UploadPack {
/** Hook for taking post upload actions. */ /** Hook for taking post upload actions. */
private PostUploadHook postUploadHook = PostUploadHook.NULL; private PostUploadHook postUploadHook = PostUploadHook.NULL;
/** Capabilities requested by the client. */ /** Caller user agent */
private Set<String> options;
String userAgent; String userAgent;
/** Raw ObjectIds the client has asked for, before validating them. */ /** Raw ObjectIds the client has asked for, before validating them. */
@ -681,10 +680,12 @@ public class UploadPack {
* read. * read.
*/ */
public boolean isSideBand() throws RequestNotYetReadException { public boolean isSideBand() throws RequestNotYetReadException {
if (options == null) if (currentRequest == null) {
throw new RequestNotYetReadException(); throw new RequestNotYetReadException();
return (options.contains(OPTION_SIDE_BAND) }
|| options.contains(OPTION_SIDE_BAND_64K)); Set<String> caps = currentRequest.getClientCapabilities();
return caps.contains(OPTION_SIDE_BAND)
|| caps.contains(OPTION_SIDE_BAND_64K);
} }
/** /**
@ -815,7 +816,6 @@ public class UploadPack {
currentRequest = req; currentRequest = req;
wantIds = req.getWantIds(); wantIds = req.getWantIds();
options = req.getClientCapabilities();
if (req.getWantIds().isEmpty()) { if (req.getWantIds().isEmpty()) {
preUploadHook.onBeginNegotiateRound(this, req.getWantIds(), 0); preUploadHook.onBeginNegotiateRound(this, req.getWantIds(), 0);
@ -956,7 +956,6 @@ public class UploadPack {
// TODO(ifrade): Refactor to pass around the Request object, instead of // TODO(ifrade): Refactor to pass around the Request object, instead of
// copying data back to class fields // copying data back to class fields
options = req.getClientCapabilities();
wantIds = req.getWantIds(); wantIds = req.getWantIds();
boolean sectionSent = false; boolean sectionSent = false;
@ -1368,7 +1367,12 @@ public class UploadPack {
* @since 4.0 * @since 4.0
*/ */
public String getPeerUserAgent() { public String getPeerUserAgent() {
return UserAgent.getAgent(options, userAgent); if (currentRequest == null) {
return userAgent;
}
return UserAgent.getAgent(currentRequest.getClientCapabilities(),
userAgent);
} }
private boolean negotiate(FetchRequest req, private boolean negotiate(FetchRequest req,
@ -1784,8 +1788,9 @@ public class UploadPack {
FetchRequest req, FetchRequest req,
@Nullable Collection<Ref> allTags, @Nullable Collection<Ref> allTags,
List<ObjectId> unshallowCommits) throws IOException { List<ObjectId> unshallowCommits) throws IOException {
final boolean sideband = options.contains(OPTION_SIDE_BAND) Set<String> caps = req.getClientCapabilities();
|| options.contains(OPTION_SIDE_BAND_64K); boolean sideband = caps.contains(OPTION_SIDE_BAND)
|| caps.contains(OPTION_SIDE_BAND_64K);
if (sideband) { if (sideband) {
try { try {
sendPack(true, req, accumulator, allTags, unshallowCommits); sendPack(true, req, accumulator, allTags, unshallowCommits);
@ -1857,12 +1862,12 @@ public class UploadPack {
if (sideband) { if (sideband) {
int bufsz = SideBandOutputStream.SMALL_BUF; int bufsz = SideBandOutputStream.SMALL_BUF;
if (options.contains(OPTION_SIDE_BAND_64K)) if (req.getClientCapabilities().contains(OPTION_SIDE_BAND_64K))
bufsz = SideBandOutputStream.MAX_BUF; bufsz = SideBandOutputStream.MAX_BUF;
packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA,
bufsz, rawOut); bufsz, rawOut);
if (!options.contains(OPTION_NO_PROGRESS)) { if (!req.getClientCapabilities().contains(OPTION_NO_PROGRESS)) {
msgOut = new SideBandOutputStream( msgOut = new SideBandOutputStream(
SideBandOutputStream.CH_PROGRESS, bufsz, rawOut); SideBandOutputStream.CH_PROGRESS, bufsz, rawOut);
pm = new SideBandProgressMonitor(msgOut); pm = new SideBandProgressMonitor(msgOut);
@ -1909,8 +1914,9 @@ public class UploadPack {
&& req.getClientShallowCommits().isEmpty()); && req.getClientShallowCommits().isEmpty());
pw.setClientShallowCommits(req.getClientShallowCommits()); pw.setClientShallowCommits(req.getClientShallowCommits());
pw.setReuseDeltaCommits(true); pw.setReuseDeltaCommits(true);
pw.setDeltaBaseAsOffset(options.contains(OPTION_OFS_DELTA)); pw.setDeltaBaseAsOffset(
pw.setThin(options.contains(OPTION_THIN_PACK)); req.getClientCapabilities().contains(OPTION_OFS_DELTA));
pw.setThin(req.getClientCapabilities().contains(OPTION_THIN_PACK));
pw.setReuseValidatingObjects(false); pw.setReuseValidatingObjects(false);
// Objects named directly by references go at the beginning // Objects named directly by references go at the beginning
@ -1949,7 +1955,8 @@ public class UploadPack {
rw = ow; rw = ow;
} }
if (options.contains(OPTION_INCLUDE_TAG) && allTags != null) { if (req.getClientCapabilities().contains(OPTION_INCLUDE_TAG)
&& allTags != null) {
for (Ref ref : allTags) { for (Ref ref : allTags) {
ObjectId objectId = ref.getObjectId(); ObjectId objectId = ref.getObjectId();
if (objectId == null) { if (objectId == null) {

Loading…
Cancel
Save