bundle-uri: parse bundle.<id>.creationToken values

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>

Derrick Stolee committed Jan 31, 2023 at 13:29 UTC 512fccf8a503bd8617fe46cb62c77480b83fbaea
3 files changed +34
bundle-uri.c
+10
@@ -83,6 +83,9 @@ static int summarize_bundle(struct remote_bundle_info *info, void *data)
83 FILE *fp = data;
84 fprintf(fp, "[bundle \"%s\"]\n", info->id);
85 fprintf(fp, "\turi = %s\n", info->uri);
86 +
87 + if (info->creationToken)
88 + fprintf(fp, "\tcreationToken = %"PRIu64"\n", info->creationToken);
89 return 0;
90 }
91
@@ -203,6 +206,13 @@ static int bundle_list_update(const char *key, const char *value,
206 return 0;
207 }
208
209 + if (!strcmp(subkey, "creationtoken")) {
210 + if (sscanf(value, "%"PRIu64, &bundle->creationToken) != 1)
211 + warning(_("could not parse bundle list key %s with value '%s'"),
212 + "creationToken", value);
213 + return 0;
214 + }
215 +
216 /*
217 * At this point, we ignore any information that we don't
218 * understand, assuming it to be hints for a heuristic the client
bundle-uri.h
+6
@@ -42,6 +42,12 @@ struct remote_bundle_info {
42 * this boolean is true.
43 */
44 unsigned unbundled:1;
45 +
46 + /**
47 + * If the bundle is part of a list with the creationToken
48 + * heuristic, then we use this member for sorting the bundles.
49 + */
50 + uint64_t creationToken;
51 };
52
53 #define REMOTE_BUNDLE_INFO_INIT { 0 }
t/t5750-bundle-uri-parse.sh
+18
@@ -258,10 +258,13 @@ test_expect_success 'parse config format: creationToken heuristic' '
258 heuristic = creationToken
259 [bundle "one"]
260 uri = http://example.com/bundle.bdl
261 + creationToken = 123456
262 [bundle "two"]
263 uri = https://example.com/bundle.bdl
264 + creationToken = 12345678901234567890
265 [bundle "three"]
266 uri = file:///usr/share/git/bundle.bdl
267 + creationToken = 1
268 EOF
269
270 test-tool bundle-uri parse-config expect >actual 2>err &&
@@ -269,4 +272,19 @@ test_expect_success 'parse config format: creationToken heuristic' '
272 test_cmp_config_output expect actual
273 '
274
275 +test_expect_success 'parse config format edge cases: creationToken heuristic' '
276 + cat >expect <<-\EOF &&
277 + [bundle]
278 + version = 1
279 + mode = all
280 + heuristic = creationToken
281 + [bundle "one"]
282 + uri = http://example.com/bundle.bdl
283 + creationToken = bogus
284 + EOF
285 +
286 + test-tool bundle-uri parse-config expect >actual 2>err &&
287 + grep "could not parse bundle list key creationToken with value '\''bogus'\''" err
288 +'
289 +
290 test_done