/** Shallow commits the client already has. */
private Set<ObjectId> clientShallowCommits = new HashSet<>();
- /** Desired depth from the client on a shallow request. */
- private int depth;
-
/** Commit time of the oldest common commit, in seconds. */
private int oldestTime;
private PackStatistics statistics;
+ /**
+ * Request this instance is handling.
+ *
+ * We need to keep a reference to it for {@link PreUploadHook pre upload
+ * hooks}. They receive a reference this instance and invoke methods like
+ * getDepth() to get information about the request.
+ */
+ private FetchRequest currentRequest;
+
/**
* Create a new pack upload for an open repository.
*
ProtocolV0Parser parser = new ProtocolV0Parser(transferConfig);
req = parser.recvWants(pckIn);
+ currentRequest = req;
wantIds = req.getWantIds();
clientShallowCommits = req.getClientShallowCommits();
options = req.getClientCapabilities();
- depth = req.getDepth();
if (req.getWantIds().isEmpty()) {
preUploadHook.onBeginNegotiateRound(this, req.getWantIds(), 0);
if (!clientShallowCommits.isEmpty())
verifyClientShallow(clientShallowCommits);
- if (depth != 0 || req.getDeepenSince() != 0) {
+ if (req.getDepth() != 0 || req.getDeepenSince() != 0) {
computeShallowsAndUnshallows(req, shallow -> {
pckOut.writeString("shallow " + shallow.name() + '\n'); //$NON-NLS-1$
}, unshallow -> {
}
if (!clientShallowCommits.isEmpty())
walk.assumeShallow(clientShallowCommits);
- sendPack = negotiate(accumulator);
+ sendPack = negotiate(req, accumulator);
accumulator.timeNegotiating += System.currentTimeMillis()
- negotiateStart;
ProtocolV2Parser parser = new ProtocolV2Parser(transferConfig);
FetchV2Request req = parser.parseFetchRequest(pckIn,
db.getRefDatabase());
+ currentRequest = req;
rawOut.stopBuffering();
protocolV2Hook.onFetch(req);
options = req.getClientCapabilities();
wantIds = req.getWantIds();
clientShallowCommits = req.getClientShallowCommits();
- depth = req.getDepth();
boolean sectionSent = false;
boolean mayHaveShallow = req.getDepth() != 0
* @since 4.0
*/
public int getDepth() {
- if (options == null)
+ if (currentRequest == null)
throw new RequestNotYetReadException();
- return depth;
+ return currentRequest.getDepth();
}
/**
return UserAgent.getAgent(options, userAgent);
}
- private boolean negotiate(PackStatistics.Accumulator accumulator)
+ private boolean negotiate(FetchRequest req,
+ PackStatistics.Accumulator accumulator)
throws IOException {
okToGiveUp = Boolean.FALSE;
// disconnected, and will try another request with actual want/have.
// Don't report the EOF here, its a bug in the protocol that the client
// just disconnects without sending an END.
- if (!biDirectionalPipe && depth > 0)
+ if (!biDirectionalPipe && req.getDepth() > 0)
return false;
throw eof;
}
} else {
pw.setUseCachedPacks(true);
}
- pw.setUseBitmaps(depth == 0 && clientShallowCommits.isEmpty());
+ pw.setUseBitmaps(
+ req.getDepth() == 0 && clientShallowCommits.isEmpty());
pw.setClientShallowCommits(clientShallowCommits);
pw.setReuseDeltaCommits(true);
pw.setDeltaBaseAsOffset(options.contains(OPTION_OFS_DELTA));
}
RevWalk rw = walk;
- if (depth > 0 || req.getDeepenSince() != 0) {
- int walkDepth = depth == 0 ? Integer.MAX_VALUE : depth - 1;
- pw.setShallowPack(depth, unshallowCommits);
+ if (req.getDepth() > 0 || req.getDeepenSince() != 0) {
+ int walkDepth = req.getDepth() == 0 ? Integer.MAX_VALUE
+ : req.getDepth() - 1;
+ pw.setShallowPack(req.getDepth(), unshallowCommits);
rw = new DepthWalk.RevWalk(walk.getObjectReader(), walkDepth);
((DepthWalk.RevWalk) rw).setDeepenSince(req.getDeepenSince());
rw.assumeShallow(clientShallowCommits);