]> source.dussan.org Git - jgit.git/commitdiff
UploadPack: Use reachable-sha1-in-want configuration 52/49652/2
authorFredrik Medley <fredrik.medley@gmail.com>
Fri, 29 May 2015 18:04:50 +0000 (20:04 +0200)
committerFredrik Medley <fredrik.medley@gmail.com>
Tue, 9 Jun 2015 16:43:48 +0000 (18:43 +0200)
C git 2.5 supports setting the equivalent of
RequestPolicy.REACHABLE_COMMIT with uploadpack.allowreachablesha1inwant.
Parse this into TransportConfig and use it from UploadPack. An explicitly
set RequestPolicy overrides the config, and the policy may still be
upgraded on a unidirectional connection to avoid races.

Change-Id: Id39771a6e42d8082099acde11249306828a053c0
Signed-off-by: Fredrik Medley <fredrik.medley@gmail.com>
org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/GitProtocolConstants.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

index a6fc633593326a0fe542f7915947d502700257c1..cf13582db5240fdd39333139a891b2782300d99b 100644 (file)
@@ -193,6 +193,13 @@ public abstract class BasePackFetchConnection extends BasePackConnection
         */
        public static final String OPTION_ALLOW_TIP_SHA1_IN_WANT = GitProtocolConstants.OPTION_ALLOW_TIP_SHA1_IN_WANT;
 
+       /**
+        * The client supports fetching objects that are reachable from a tip of a
+        * ref that is allowed to fetch.
+        * @since 4.1
+        */
+       public static final String OPTION_ALLOW_REACHABLE_SHA1_IN_WANT = GitProtocolConstants.OPTION_ALLOW_REACHABLE_SHA1_IN_WANT;
+
        private final RevWalk walk;
 
        /** All commits that are immediately reachable by a local ref. */
index 8d2d554b91a616dd315d0908d02029458dda63ba..efde0626217130d630e53a179786647542bdf90b 100644 (file)
@@ -129,6 +129,14 @@ public class GitProtocolConstants {
         */
        public static final String OPTION_ALLOW_TIP_SHA1_IN_WANT = "allow-tip-sha1-in-want"; //$NON-NLS-1$
 
+       /**
+        * The client supports fetching objects that are reachable from a tip of a
+        * ref that is allowed to fetch.
+        *
+        * @since 4.1
+        */
+       public static final String OPTION_ALLOW_REACHABLE_SHA1_IN_WANT = "allow-reachable-sha1-in-want"; //$NON-NLS-1$
+
        /**
         * Symbolic reference support for better negotiation.
         *
index 138002e63e701e101110ecc9df88aa192b59b176..f4de82147d3c05e453d1bdbc72f45ec9de73a00f 100644 (file)
@@ -71,6 +71,7 @@ public class TransferConfig {
        private final boolean safeForWindows;
        private final boolean safeForMacOS;
        private final boolean allowTipSha1InWant;
+       private final boolean allowReachableSha1InWant;
        private final String[] hideRefs;
 
        TransferConfig(final Repository db) {
@@ -94,6 +95,8 @@ public class TransferConfig {
 
                allowTipSha1InWant = rc.getBoolean(
                                "uploadpack", "allowtipsha1inwant", false); //$NON-NLS-1$ //$NON-NLS-2$
+               allowReachableSha1InWant = rc.getBoolean(
+                               "uploadpack", "allowreachablesha1inwant", false); //$NON-NLS-1$ //$NON-NLS-2$
                hideRefs = rc.getStringList("uploadpack", null, "hiderefs"); //$NON-NLS-1$ //$NON-NLS-2$
        }
 
@@ -120,6 +123,14 @@ public class TransferConfig {
                return allowTipSha1InWant;
        }
 
+       /**
+        * @return allow clients to request non-tip SHA-1s?
+        * @since 4.1
+        */
+       public boolean isAllowReachableSha1InWant() {
+               return allowReachableSha1InWant;
+       }
+
        /**
         * @return {@link RefFilter} respecting configured hidden refs.
         * @since 3.1
index 753277dd3fd69f6acece941d9bdf481a332bf809..1e6aabbe0129ab59d2a04f3c2fb661be95de6806 100644 (file)
@@ -46,6 +46,7 @@ package org.eclipse.jgit.transport;
 import static org.eclipse.jgit.lib.RefDatabase.ALL;
 import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_AGENT;
 import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_ALLOW_TIP_SHA1_IN_WANT;
+import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_ALLOW_REACHABLE_SHA1_IN_WANT;
 import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_INCLUDE_TAG;
 import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_MULTI_ACK;
 import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_MULTI_ACK_DETAILED;
@@ -552,8 +553,13 @@ public class UploadPack {
         */
        public void setTransferConfig(TransferConfig tc) {
                this.transferConfig = tc != null ? tc : new TransferConfig(db);
-               setRequestPolicy(transferConfig.isAllowTipSha1InWant()
-                               ? RequestPolicy.TIP : RequestPolicy.ADVERTISED);
+               if (transferConfig.isAllowTipSha1InWant()) {
+                       setRequestPolicy(transferConfig.isAllowReachableSha1InWant()
+                               ? RequestPolicy.REACHABLE_COMMIT_TIP : RequestPolicy.TIP);
+               } else {
+                       setRequestPolicy(transferConfig.isAllowReachableSha1InWant()
+                               ? RequestPolicy.REACHABLE_COMMIT : RequestPolicy.ADVERTISED);
+               }
        }
 
        /** @return the configured logger. */
@@ -808,6 +814,10 @@ public class UploadPack {
                                || policy == RequestPolicy.REACHABLE_COMMIT_TIP
                                || policy == null)
                        adv.advertiseCapability(OPTION_ALLOW_TIP_SHA1_IN_WANT);
+               if (policy == RequestPolicy.REACHABLE_COMMIT
+                               || policy == RequestPolicy.REACHABLE_COMMIT_TIP
+                               || policy == null)
+                       adv.advertiseCapability(OPTION_ALLOW_REACHABLE_SHA1_IN_WANT);
                adv.advertiseCapability(OPTION_AGENT, UserAgent.get());
                adv.setDerefTags(true);
                Map<String, Ref> advertisedOrDefaultRefs = getAdvertisedOrDefaultRefs();