]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bundle-uri: parse bundle.<id>.creationToken values
authorDerrick Stolee <derrickstolee@github.com>
Tue, 31 Jan 2023 13:29:13 +0000 (13:29 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 Jan 2023 16:57:48 +0000 (08:57 -0800)
The previous change taught Git to parse the bundle.heuristic value,
especially when its value is "creationToken". Now, teach Git to parse
the bundle.<id>.creationToken values on each bundle in a bundle list.

Before implementing any logic based on creationToken values for the
creationToken heuristic, parse and print these values for testing
purposes.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
bundle-uri.c
bundle-uri.h
t/t5750-bundle-uri-parse.sh

index 36ec542718deb7acd72ce03246edc89ab0e41ee4..d4277b2e3a7a77390091f5183cd894e0290a8642 100644 (file)
@@ -83,6 +83,9 @@ static int summarize_bundle(struct remote_bundle_info *info, void *data)
        FILE *fp = data;
        fprintf(fp, "[bundle \"%s\"]\n", info->id);
        fprintf(fp, "\turi = %s\n", info->uri);
+
+       if (info->creationToken)
+               fprintf(fp, "\tcreationToken = %"PRIu64"\n", info->creationToken);
        return 0;
 }
 
@@ -203,6 +206,13 @@ static int bundle_list_update(const char *key, const char *value,
                return 0;
        }
 
+       if (!strcmp(subkey, "creationtoken")) {
+               if (sscanf(value, "%"PRIu64, &bundle->creationToken) != 1)
+                       warning(_("could not parse bundle list key %s with value '%s'"),
+                               "creationToken", value);
+               return 0;
+       }
+
        /*
         * At this point, we ignore any information that we don't
         * understand, assuming it to be hints for a heuristic the client
index 2e44a50a90b04b21603737488a59a35a6eaa4a91..ef32840bfa64eee7a07fda3322b024440e09ad19 100644 (file)
@@ -42,6 +42,12 @@ struct remote_bundle_info {
         * this boolean is true.
         */
        unsigned unbundled:1;
+
+       /**
+        * If the bundle is part of a list with the creationToken
+        * heuristic, then we use this member for sorting the bundles.
+        */
+       uint64_t creationToken;
 };
 
 #define REMOTE_BUNDLE_INFO_INIT { 0 }
index 6fc92a9c0d46ad5a3e917056fb3c4dfc26408945..81bdf58b94443415083cd1dca427e08564f9af53 100755 (executable)
@@ -258,10 +258,13 @@ test_expect_success 'parse config format: creationToken heuristic' '
                heuristic = creationToken
        [bundle "one"]
                uri = http://example.com/bundle.bdl
+               creationToken = 123456
        [bundle "two"]
                uri = https://example.com/bundle.bdl
+               creationToken = 12345678901234567890
        [bundle "three"]
                uri = file:///usr/share/git/bundle.bdl
+               creationToken = 1
        EOF
 
        test-tool bundle-uri parse-config expect >actual 2>err &&
@@ -269,4 +272,19 @@ test_expect_success 'parse config format: creationToken heuristic' '
        test_cmp_config_output expect actual
 '
 
+test_expect_success 'parse config format edge cases: creationToken heuristic' '
+       cat >expect <<-\EOF &&
+       [bundle]
+               version = 1
+               mode = all
+               heuristic = creationToken
+       [bundle "one"]
+               uri = http://example.com/bundle.bdl
+               creationToken = bogus
+       EOF
+
+       test-tool bundle-uri parse-config expect >actual 2>err &&
+       grep "could not parse bundle list key creationToken with value '\''bogus'\''" err
+'
+
 test_done