]> source.dussan.org Git - jgit.git/commitdiff
Add constants for parsing git wire protocol version 79/172979/3
authorDavid Ostrovsky <david@ostrovsky.org>
Sun, 29 Nov 2020 12:06:00 +0000 (13:06 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Sun, 29 Nov 2020 21:46:51 +0000 (22:46 +0100)
This would allow other JGit users to access and reuse the constants.

Change-Id: I1608802f45586af5f8582afa592e26679e9cebe3
Signed-off-by: David Ostrovsky <david@ostrovsky.org>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java

index 96657761cf461d26919da294dff25faeaeb1db8f..26a453be143a46510bf5c6001fbcde5bba7f304a 100644 (file)
@@ -38,6 +38,7 @@ import org.eclipse.jgit.internal.JGitText;
 import org.eclipse.jgit.junit.TestRepository;
 import org.eclipse.jgit.junit.http.AccessEvent;
 import org.eclipse.jgit.junit.http.AppServer;
+import org.eclipse.jgit.lib.ConfigConstants;
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.lib.RefUpdate;
@@ -49,6 +50,7 @@ import org.eclipse.jgit.transport.HttpTransport;
 import org.eclipse.jgit.transport.PacketLineIn;
 import org.eclipse.jgit.transport.PacketLineOut;
 import org.eclipse.jgit.transport.Transport;
+import org.eclipse.jgit.transport.TransferConfig;
 import org.eclipse.jgit.transport.URIish;
 import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
 import org.eclipse.jgit.transport.http.HttpConnection;
@@ -342,8 +344,10 @@ public class HttpClientTests extends AllFactoriesHttpTestCase {
 
        @Test
        public void testV2HttpFirstResponse() throws Exception {
-               remoteRepository.getRepository().getConfig().setInt(
-                               "protocol", null, "version", 2);
+               remoteRepository.getRepository().getConfig().setString(
+                               ConfigConstants.CONFIG_PROTOCOL_SECTION, null,
+                               ConfigConstants.CONFIG_KEY_VERSION,
+                               TransferConfig.ProtocolVersion.V2.version());
 
                String url = smartAuthNoneURI.toString() + "/info/refs?service=git-upload-pack";
                HttpConnection c = HttpTransport.getConnectionFactory()
@@ -364,8 +368,10 @@ public class HttpClientTests extends AllFactoriesHttpTestCase {
 
        @Test
        public void testV2HttpSubsequentResponse() throws Exception {
-               remoteRepository.getRepository().getConfig().setInt(
-                               "protocol", null, "version", 2);
+               remoteRepository.getRepository().getConfig().setString(
+                               ConfigConstants.CONFIG_PROTOCOL_SECTION, null,
+                               ConfigConstants.CONFIG_KEY_VERSION,
+                               TransferConfig.ProtocolVersion.V2.version());
 
                String url = smartAuthNoneURI.toString() + "/git-upload-pack";
                HttpConnection c = HttpTransport.getConnectionFactory()
index e9b4af932ea659aeedbb572e4c0b30b0517eb3f4..46ba3aa5d42d82d8f751a7bc8ff13533ad6dcd2e 100644 (file)
@@ -38,6 +38,7 @@ import org.eclipse.jgit.internal.storage.file.PackLock;
 import org.eclipse.jgit.internal.storage.pack.CachedPack;
 import org.eclipse.jgit.internal.storage.pack.CachedPackUriProvider;
 import org.eclipse.jgit.junit.TestRepository;
+import org.eclipse.jgit.lib.ConfigConstants;
 import org.eclipse.jgit.lib.NullProgressMonitor;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectInserter;
@@ -370,7 +371,9 @@ public class UploadPackTest {
 
                ByteArrayInputStream send = linesAsInputStream(inputLines);
 
-               server.getConfig().setString("protocol", null, "version", "2");
+               server.getConfig().setString(ConfigConstants.CONFIG_PROTOCOL_SECTION,
+                               null, ConfigConstants.CONFIG_KEY_VERSION,
+                               TransferConfig.ProtocolVersion.V2.version());
                UploadPack up = new UploadPack(server);
                if (postConstructionSetup != null) {
                        postConstructionSetup.accept(up);
@@ -2165,7 +2168,9 @@ public class UploadPackTest {
 
        @Test
        public void testGetPeerAgentProtocolV2() throws Exception {
-               server.getConfig().setString("protocol", null, "version", "2");
+               server.getConfig().setString(ConfigConstants.CONFIG_PROTOCOL_SECTION,
+                               null, ConfigConstants.CONFIG_KEY_VERSION,
+                               TransferConfig.ProtocolVersion.V2.version());
 
                RevCommit one = remote.commit().message("1").create();
                remote.update("one", one);
index 4fcf8e2dcd2e91291495798029691fcd61f099fb..834fff5dd93afa4a3869184d5e34d160bc068795 100644 (file)
@@ -92,6 +92,12 @@ public final class ConfigConstants {
         */
        public static final String CONFIG_GPG_SECTION = "gpg";
 
+       /**
+        * The "protocol" section
+        * @since 5.9
+        */
+       public static final String CONFIG_PROTOCOL_SECTION = "protocol";
+
        /**
         * The "format" key
         * @since 5.2
@@ -685,7 +691,7 @@ public final class ConfigConstants {
        public static final String CONFIG_INDEX_SECTION = "index";
 
        /**
-        * The "index.version" key
+        * The "version" key
         *
         * @since 5.9
         */
index cc577fa11e91b5cc88aad57c7d8cef172958b994..0b38159c094a7a7f157ad41e8065a53d38f83536 100644 (file)
@@ -21,6 +21,7 @@ import java.util.Map;
 import org.eclipse.jgit.annotations.Nullable;
 import org.eclipse.jgit.internal.storage.file.LazyObjectIdSetFile;
 import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.lib.ConfigConstants;
 import org.eclipse.jgit.lib.Config.SectionParser;
 import org.eclipse.jgit.lib.ObjectChecker;
 import org.eclipse.jgit.lib.ObjectIdSet;
@@ -60,11 +61,19 @@ public class TransferConfig {
        }
 
        /**
-        * A git configuration variable for which versions of the Git protocol to prefer.
-        * Used in protocol.version.
+        * A git configuration variable for which versions of the Git protocol to
+        * prefer. Used in protocol.version.
+        *
+        * @since 5.9
         */
-       enum ProtocolVersion {
+       public enum ProtocolVersion {
+               /**
+                * Git wire protocol version 0 (the default).
+                */
                V0("0"), //$NON-NLS-1$
+               /**
+                * Git wire protocol version 2.
+                */
                V2("2"); //$NON-NLS-1$
 
                final String name;
@@ -73,6 +82,15 @@ public class TransferConfig {
                        this.name = name;
                }
 
+               /**
+                * Returns version number
+                *
+                * @return string version
+                */
+               public String version() {
+                       return name;
+               }
+
                @Nullable
                static ProtocolVersion parse(@Nullable String name) {
                        if (name == null) {
@@ -177,7 +195,9 @@ public class TransferConfig {
                                "uploadpack", "allowreachablesha1inwant", false);
                allowFilter = rc.getBoolean(
                                "uploadpack", "allowfilter", false);
-               protocolVersion = ProtocolVersion.parse(rc.getString("protocol", null, "version"));
+               protocolVersion = ProtocolVersion.parse(rc
+                               .getString(ConfigConstants.CONFIG_PROTOCOL_SECTION, null,
+                                               ConfigConstants.CONFIG_KEY_VERSION));
                hideRefs = rc.getStringList("uploadpack", null, "hiderefs");
                allowSidebandAll = rc.getBoolean(
                                "uploadpack", "allowsidebandall", false);