]> source.dussan.org Git - jgit.git/commitdiff
TransferConfig: Move reading advertisesid setting into TransferConfig 66/196566/6
authorJosh Brown <sjoshbrown@google.com>
Tue, 1 Nov 2022 19:00:07 +0000 (19:00 +0000)
committerJosh Brown <sjoshbrown@google.com>
Wed, 2 Nov 2022 20:13:08 +0000 (16:13 -0400)
The config setting to enable advertising the session-id capability is
currently read in the ReceivePack class. This change moves it to a
common location in the TransferConfig class so that it can be reused
in other places like UploadPack. TransferConfig is also a more logical
place for the setting as it resides in the `transfer` config section.

Set the transfer.advertisesid setting to true to send the session-id
capability to the client.

Change-Id: If68ecb5e68b59f5c452a7992d02e3688b0a86747
Signed-off-by: Josh Brown <sjoshbrown@google.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransferConfigTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java

index d9b85fb00329da1a35204d6a40eca94328181015..8dad571e5ae70c67882a0301adc05fa18128efc6 100644 (file)
@@ -11,6 +11,8 @@ package org.eclipse.jgit.transport;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
 
 import org.eclipse.jgit.lib.Config;
 import org.junit.Test;
@@ -66,4 +68,19 @@ public class TransferConfigTest {
                TransferConfig tc = new TransferConfig(rc);
                assertNull(tc.protocolVersion);
        }
+
+       @Test
+       public void testParseAdvertiseSIDDefault() {
+               Config rc = new Config();
+               TransferConfig tc = new TransferConfig(rc);
+               assertFalse(tc.isAllowReceiveClientSID());
+       }
+
+       @Test
+       public void testParseAdvertiseSIDSet() {
+               Config rc = new Config();
+               rc.setBoolean("transfer", null, "advertiseSID", true);
+               TransferConfig tc = new TransferConfig(rc);
+               assertTrue(tc.isAllowReceiveClientSID());
+       }
 }
index fe01ecc1f34fb96ca824f6dfb0e0f3273dd00efc..816cec89afac442b7e496c453955cbeedeed9356 100644 (file)
@@ -312,6 +312,7 @@ public class ReceivePack {
 
                TransferConfig tc = db.getConfig().get(TransferConfig.KEY);
                objectChecker = tc.newReceiveObjectChecker();
+               allowReceiveClientSID = tc.isAllowReceiveClientSID();
 
                ReceiveConfig rc = db.getConfig().get(ReceiveConfig::new);
                allowCreates = rc.allowCreates;
@@ -320,7 +321,6 @@ public class ReceivePack {
                allowNonFastForwards = rc.allowNonFastForwards;
                allowOfsDelta = rc.allowOfsDelta;
                allowPushOptions = rc.allowPushOptions;
-               allowReceiveClientSID = rc.allowReceiveClientSID;
                maxCommandBytes = rc.maxCommandBytes;
                maxDiscardBytes = rc.maxDiscardBytes;
                advertiseRefsHook = AdvertiseRefsHook.DEFAULT;
@@ -344,8 +344,6 @@ public class ReceivePack {
 
                final boolean allowPushOptions;
 
-               final boolean allowReceiveClientSID;
-
                final long maxCommandBytes;
 
                final long maxDiscardBytes;
@@ -361,10 +359,6 @@ public class ReceivePack {
                                        true);
                        allowPushOptions = config.getBoolean("receive", "pushoptions", //$NON-NLS-1$ //$NON-NLS-2$
                                        false);
-                       // TODO: This should not be enabled until the corresponding change to
-                       // upload pack has been implemented.
-                       allowReceiveClientSID = config.getBoolean("transfer", //$NON-NLS-1$
-                                       "advertisesid", false); //$NON-NLS-1$
                        maxCommandBytes = config.getLong("receive", //$NON-NLS-1$
                                        "maxCommandBytes", //$NON-NLS-1$
                                        3 << 20);
index 02be434887eda7ef9aefb2e3a6480b7e082b9117..805166a40563184c326ad2447eeca8aa1d0337fa 100644 (file)
@@ -125,6 +125,8 @@ public class TransferConfig {
        private final boolean advertiseWaitForDone;
        private final boolean advertiseObjectInfo;
 
+       private final boolean allowReceiveClientSID;
+
        final @Nullable ProtocolVersion protocolVersion;
        final String[] hideRefs;
 
@@ -214,6 +216,8 @@ public class TransferConfig {
                                "advertisewaitfordone", false);
                advertiseObjectInfo = rc.getBoolean("uploadpack",
                                "advertiseobjectinfo", false);
+               allowReceiveClientSID = rc.getBoolean("transfer", "advertisesid",
+                               false);
        }
 
        /**
@@ -328,6 +332,14 @@ public class TransferConfig {
                return advertiseObjectInfo;
        }
 
+       /**
+        * @return true to advertise and receive session-id capability
+        * @since 6.4
+        */
+       public boolean isAllowReceiveClientSID() {
+               return allowReceiveClientSID;
+       }
+
        /**
         * Get {@link org.eclipse.jgit.transport.RefFilter} respecting configured
         * hidden refs.