UploadPack: Use request in computeShallowUnshallow

All data required in this function is available in the request object.
Use that object instead of class members. This reduces class state and
is more readable.

Make the function use a request object and remove the now unnecessary
field "deepenNotRefs".

Change-Id: If861e44c2860a78cf19f456d1b3feb7ddc314cce
Signed-off-by: Ivan Frade <ifrade@google.com>
This commit is contained in:
Ivan Frade 2018-10-16 13:56:43 -07:00
parent b41d7624b8
commit 3c974d0251
1 changed files with 11 additions and 17 deletions

View File

@ -311,13 +311,6 @@ private static interface IOConsumer<R> {
*/
private int shallowSince;
/**
* (Possibly short) ref names, ancestors of which the client has asked us
* not to send using --shallow-exclude. Cannot be non-empty if depth is
* nonzero.
*/
private List<String> deepenNotRefs = new ArrayList<>();
/** Commit time of the oldest common commit, in seconds. */
private int oldestTime;
@ -847,7 +840,7 @@ else if (requestValidator instanceof AnyRequestValidator)
if (!clientShallowCommits.isEmpty())
verifyClientShallow(clientShallowCommits);
if (depth != 0 || shallowSince != 0) {
computeShallowsAndUnshallows(wantIds, shallow -> {
computeShallowsAndUnshallows(req, shallow -> {
pckOut.writeString("shallow " + shallow.name() + '\n'); //$NON-NLS-1$
}, unshallow -> {
pckOut.writeString("unshallow " + unshallow.name() + '\n'); //$NON-NLS-1$
@ -968,7 +961,6 @@ private void fetchV2() throws IOException {
clientShallowCommits = req.getClientShallowCommits();
depth = req.getDepth();
shallowSince = req.getDeepenSince();
deepenNotRefs = req.getDeepenNotRefs();
boolean sectionSent = false;
boolean mayHaveShallow = req.getDepth() != 0
@ -981,7 +973,7 @@ private void fetchV2() throws IOException {
verifyClientShallow(req.getClientShallowCommits());
}
if (mayHaveShallow) {
computeShallowsAndUnshallows(req.getWantIds(),
computeShallowsAndUnshallows(req,
shallowCommit -> shallowCommits.add(shallowCommit),
unshallowCommit -> unshallowCommits.add(unshallowCommit));
}
@ -1145,24 +1137,26 @@ private static Set<ObjectId> refIdSet(Collection<Ref> refs) {
* Determines what object ids must be marked as shallow or unshallow for the
* client.
*/
private void computeShallowsAndUnshallows(Iterable<ObjectId> wants,
private void computeShallowsAndUnshallows(FetchRequest req,
IOConsumer<ObjectId> shallowFunc,
IOConsumer<ObjectId> unshallowFunc)
throws IOException {
if (options.contains(OPTION_DEEPEN_RELATIVE) || !deepenNotRefs.isEmpty()) {
if (req.getClientCapabilities().contains(OPTION_DEEPEN_RELATIVE)
|| !req.getDeepenNotRefs().isEmpty()) {
// TODO(jonathantanmy): Implement deepen-relative
// and deepen-not.
throw new UnsupportedOperationException();
}
int walkDepth = depth == 0 ? Integer.MAX_VALUE : depth - 1;
int walkDepth = req.getDepth() == 0 ? Integer.MAX_VALUE
: req.getDepth() - 1;
try (DepthWalk.RevWalk depthWalk = new DepthWalk.RevWalk(
walk.getObjectReader(), walkDepth)) {
depthWalk.setDeepenSince(shallowSince);
depthWalk.setDeepenSince(req.getDeepenSince());
// Find all the commits which will be shallow
for (ObjectId o : wants) {
for (ObjectId o : req.getWantIds()) {
try {
depthWalk.markRoot(depthWalk.parseCommit(o));
} catch (IncorrectObjectTypeException notCommit) {
@ -1178,13 +1172,13 @@ private void computeShallowsAndUnshallows(Iterable<ObjectId> wants,
// Commits at the boundary which aren't already shallow in
// the client need to be marked as such
if (isBoundary && !clientShallowCommits.contains(c)) {
if (isBoundary && !req.getClientShallowCommits().contains(c)) {
shallowFunc.accept(c.copy());
}
// Commits not on the boundary which are shallow in the client
// need to become unshallowed
if (!isBoundary && clientShallowCommits.remove(c)) {
if (!isBoundary && req.getClientShallowCommits().remove(c)) {
unshallowFunc.accept(c.copy());
}
}