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. */
private PostUploadHook postUploadHook = PostUploadHook.NULL;
/** Capabilities requested by the client. */
private Set<String> 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<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;
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<Ref> allTags,
List<ObjectId> unshallowCommits) throws IOException {
final boolean sideband = options.contains(OPTION_SIDE_BAND)
|| options.contains(OPTION_SIDE_BAND_64K);
Set<String> 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) {

Loading…
Cancel
Save