]> source.dussan.org Git - jgit.git/commitdiff
UploadPack: Use request in computeShallowUnshallow 52/129752/3
authorIvan Frade <ifrade@google.com>
Tue, 16 Oct 2018 20:56:43 +0000 (13:56 -0700)
committerIvan Frade <ifrade@google.com>
Tue, 16 Oct 2018 23:13:04 +0000 (16:13 -0700)
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>
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

index d3875ebaf59c424c3804150b6c54ad12f8009caf..7d5dc88c47ae15cdeba34e8e053e1693f957b89c 100644 (file)
@@ -311,13 +311,6 @@ public class UploadPack {
         */
        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 @@ public class UploadPack {
                        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 @@ public class UploadPack {
                clientShallowCommits = req.getClientShallowCommits();
                depth = req.getDepth();
                shallowSince = req.getDeepenSince();
-               deepenNotRefs = req.getDeepenNotRefs();
 
                boolean sectionSent = false;
                boolean mayHaveShallow = req.getDepth() != 0
@@ -981,7 +973,7 @@ public class UploadPack {
                        verifyClientShallow(req.getClientShallowCommits());
                }
                if (mayHaveShallow) {
-                       computeShallowsAndUnshallows(req.getWantIds(),
+                       computeShallowsAndUnshallows(req,
                                        shallowCommit -> shallowCommits.add(shallowCommit),
                                        unshallowCommit -> unshallowCommits.add(unshallowCommit));
                }
@@ -1145,24 +1137,26 @@ public class UploadPack {
         * 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 @@ public class UploadPack {
 
                                // 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());
                                }
                        }