From 3c974d0251e61dd7dd0576dad22c515ed7eb09ff Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Tue, 16 Oct 2018 13:56:43 -0700 Subject: [PATCH] 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 --- .../eclipse/jgit/transport/UploadPack.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) 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 d3875ebaf..7d5dc88c4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -311,13 +311,6 @@ private static interface IOConsumer { */ 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 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 refIdSet(Collection refs) { * Determines what object ids must be marked as shallow or unshallow for the * client. */ - private void computeShallowsAndUnshallows(Iterable wants, + private void computeShallowsAndUnshallows(FetchRequest req, IOConsumer shallowFunc, IOConsumer 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 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()); } }