]> source.dussan.org Git - jgit.git/commitdiff
UploadPack: Use request instead of field for filterBlobLimt 51/129751/2
authorIvan Frade <ifrade@google.com>
Tue, 18 Sep 2018 21:58:44 +0000 (14:58 -0700)
committerIvan Frade <ifrade@google.com>
Tue, 16 Oct 2018 18:17:42 +0000 (11:17 -0700)
filterBlobLimit is not part of the UploadPack state, and as field
of the class is difficult to see where it is set or accessed.

Use the request object instead of a field. This reduces
UploadPack state and makes clearer how the value is used.

Change-Id: I96a04a5a8b31bf2243de701e1fd7ebb4080b49e2
Signed-off-by: Ivan Frade <ifrade@google.com>
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

index a3853393367d9cedaa3dba57ace7e23e2a64b6d6..d3875ebaf59c424c3804150b6c54ad12f8009caf 100644 (file)
@@ -351,8 +351,6 @@ public class UploadPack {
 
        private PackStatistics statistics;
 
-       private long filterBlobLimit = -1;
-
        /**
         * Create a new pack upload for an open repository.
         *
@@ -810,6 +808,7 @@ public class UploadPack {
                // writing a response. Buffer the response until then.
                PackStatistics.Accumulator accumulator = new PackStatistics.Accumulator();
                List<ObjectId> unshallowCommits = new ArrayList<>();
+               FetchRequest req;
                try {
                        if (biDirectionalPipe)
                                sendAdvertisedRefs(new PacketLineOutRefAdvertiser(pckOut));
@@ -822,11 +821,10 @@ public class UploadPack {
                        accumulator.advertised = advertised.size();
 
                        ProtocolV0Parser parser = new ProtocolV0Parser(transferConfig);
-                       FetchV0Request req = parser.recvWants(pckIn);
+                       req = parser.recvWants(pckIn);
 
                        wantIds = req.getWantIds();
                        clientShallowCommits = req.getClientShallowCommits();
-                       filterBlobLimit = req.getFilterBlobLimit();
                        options = req.getClientCapabilities();
                        depth = req.getDepth();
 
@@ -909,7 +907,8 @@ public class UploadPack {
                }
 
                if (sendPack) {
-                       sendPack(accumulator, refs == null ? null : refs.values(), unshallowCommits);
+                       sendPack(accumulator, req, refs == null ? null : refs.values(),
+                                       unshallowCommits);
                }
        }
 
@@ -969,7 +968,6 @@ public class UploadPack {
                clientShallowCommits = req.getClientShallowCommits();
                depth = req.getDepth();
                shallowSince = req.getDeepenSince();
-               filterBlobLimit = req.getFilterBlobLimit();
                deepenNotRefs = req.getDeepenNotRefs();
 
                boolean sectionSent = false;
@@ -1041,6 +1039,7 @@ public class UploadPack {
                                pckOut.writeDelim();
                        pckOut.writeString("packfile\n"); //$NON-NLS-1$
                        sendPack(new PackStatistics.Accumulator(),
+                                       req,
                                        req.getClientCapabilities().contains(OPTION_INCLUDE_TAG)
                                                ? db.getRefDatabase().getRefsByPrefix(R_TAGS)
                                                : null,
@@ -1778,25 +1777,26 @@ public class UploadPack {
         * Send the requested objects to the client.
         *
         * @param accumulator
-        *                where to write statistics about the content of the pack.
+        *            where to write statistics about the content of the pack.
+        * @param req
+        *            request in process
         * @param allTags
-        *                refs to search for annotated tags to include in the pack
-        *                if the {@link #OPTION_INCLUDE_TAG} capability was
-        *                requested.
+        *            refs to search for annotated tags to include in the pack if
+        *            the {@link #OPTION_INCLUDE_TAG} capability was requested.
         * @param unshallowCommits
-        *                shallow commits on the client that are now becoming
-        *                unshallow
+        *            shallow commits on the client that are now becoming unshallow
         * @throws IOException
-        *                if an error occured while generating or writing the pack.
+        *             if an error occured while generating or writing the pack.
         */
        private void sendPack(PackStatistics.Accumulator accumulator,
+                       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);
                if (sideband) {
                        try {
-                               sendPack(true, accumulator, allTags, unshallowCommits);
+                               sendPack(true, req, accumulator, allTags, unshallowCommits);
                        } catch (ServiceMayNotContinueException noPack) {
                                // This was already reported on (below).
                                throw noPack;
@@ -1817,7 +1817,7 @@ public class UploadPack {
                                        throw err;
                        }
                } else {
-                       sendPack(false, accumulator, allTags, unshallowCommits);
+                       sendPack(false, req, accumulator, allTags, unshallowCommits);
                }
        }
 
@@ -1841,21 +1841,22 @@ public class UploadPack {
         * Send the requested objects to the client.
         *
         * @param sideband
-        *                whether to wrap the pack in side-band pkt-lines,
-        *                interleaved with progress messages and errors.
+        *            whether to wrap the pack in side-band pkt-lines, interleaved
+        *            with progress messages and errors.
+        * @param req
+        *            request being processed
         * @param accumulator
-        *                where to write statistics about the content of the pack.
+        *            where to write statistics about the content of the pack.
         * @param allTags
-        *                refs to search for annotated tags to include in the pack
-        *                if the {@link #OPTION_INCLUDE_TAG} capability was
-        *                requested.
+        *            refs to search for annotated tags to include in the pack if
+        *            the {@link #OPTION_INCLUDE_TAG} capability was requested.
         * @param unshallowCommits
-        *                shallow commits on the client that are now becoming
-        *                unshallow
+        *            shallow commits on the client that are now becoming unshallow
         * @throws IOException
-        *                if an error occured while generating or writing the pack.
+        *             if an error occured while generating or writing the pack.
         */
        private void sendPack(final boolean sideband,
+                       FetchRequest req,
                        PackStatistics.Accumulator accumulator,
                        @Nullable Collection<Ref> allTags,
                        List<ObjectId> unshallowCommits) throws IOException {
@@ -1905,8 +1906,8 @@ public class UploadPack {
                                accumulator);
                try {
                        pw.setIndexDisabled(true);
-                       if (filterBlobLimit >= 0) {
-                               pw.setFilterBlobLimit(filterBlobLimit);
+                       if (req.getFilterBlobLimit() >= 0) {
+                               pw.setFilterBlobLimit(req.getFilterBlobLimit());
                                pw.setUseCachedPacks(false);
                        } else {
                                pw.setUseCachedPacks(true);