Re: [PATCH 3/8] bundle-uri: parse bundle.<id>.creationToken values
- From
Victoria Dye <vdye@github.com>
- Date
- Jan 17, 2023, 19:24 UTC
- Message-ID
- <d9ef2037-0365-dbe3-c5d6-04d7e96fc7c9@github.com>
- In-Reply-To
- <a1808f0b10cfb519613bc292e30b884962a83275.1673037405.git.gitgitgadget@gmail.com>
Derrick Stolee via GitGitGadget wrote:
Show 41 quoted lines
> From: Derrick Stolee <derrickstolee@github.com>
>
> 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>
> ---
> bundle-uri.c | 10 ++++++++++
> bundle-uri.h | 6 ++++++
> t/t5750-bundle-uri-parse.sh | 18 ++++++++++++++++++
> 3 files changed, 34 insertions(+)
>
> diff --git a/bundle-uri.c b/bundle-uri.c
> index 56c94595c2a..63e2cc21057 100644
> --- a/bundle-uri.c
> +++ b/bundle-uri.c
> @@ -80,6 +80,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;
> }
>
> @@ -190,6 +193,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;
> + }Like the 'heuristic' key in the last patch, the parsing of 'creationToken' is pretty straightforward.
Show 36 quoted lines
> diff --git a/t/t5750-bundle-uri-parse.sh b/t/t5750-bundle-uri-parse.sh > index 6fc92a9c0d4..81bdf58b944 100755 > --- a/t/t5750-bundle-uri-parse.sh > +++ b/t/t5750-bundle-uri-parse.sh > @@ -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 > +'
And the tests cover both valid and invalid cases nicely.
> + > test_done