git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 3/5] read-cache & fetch-negotiator: check "enum" values in switch()

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 20, 2021, 23:33 UTC
Message-ID
<87pmt2aki2.fsf@evledraar.gmail.com>
In-Reply-To
<YUkH1LSa1WcFDmvr@nand.local>
On Mon, Sep 20 2021, Taylor Blau wrote:
Show 10 quoted lines
> On Sun, Sep 19, 2021 at 10:47:17AM +0200, Ævar Arnfjörð Bjarmason wrote:
>> Change tweak_untracked_cache() in "read-cache.c" to use a switch() to
>> have the compiler assert that we checked all possible values in the
>> "enum untracked_cache_setting" type, and likewise remove the "default"
>> case in fetch_negotiator_init() in favor of checking for
>> "FETCH_NEGOTIATION_UNSET" and "FETCH_NEGOTIATION_NONE".
>>
>> As will be discussed in a subsequent we'll only ever have either of
>
> s/subsequent/& patch/ ?
Thanks.
Show 40 quoted lines
>> these set to FETCH_NEGOTIATION_NONE, FETCH_NEGOTIATION_UNSET and
>> UNTRACKED_CACHE_UNSET within the prepare_repo_settings() function
>> itself. In preparation for fixing that code let's add a BUG() here to
>> mark this as unreachable code.
>>
>> See ad0fb659993 (repo-settings: parse core.untrackedCache, 2019-08-13)
>> for when the "unset" and "keep" handling for core.untrackedCache was
>> consolidated, and aaf633c2ad1 (repo-settings: create
>> feature.experimental setting, 2019-08-13) for the addition of the
>> "default" pattern in "fetch-negotiator.c".
>>
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>>  fetch-negotiator.c |  4 +++-
>>  read-cache.c       | 15 ++++++++++-----
>>  2 files changed, 13 insertions(+), 6 deletions(-)
>>
>> diff --git a/fetch-negotiator.c b/fetch-negotiator.c
>> index 57ed5784e14..237f92b8696 100644
>> --- a/fetch-negotiator.c
>> +++ b/fetch-negotiator.c
>> @@ -19,8 +19,10 @@ void fetch_negotiator_init(struct repository *r,
>>  		return;
>>
>>  	case FETCH_NEGOTIATION_DEFAULT:
>> -	default:
>>  		default_negotiator_init(negotiator);
>>  		return;
>> +	case FETCH_NEGOTIATION_NONE:
>> +	case FETCH_NEGOTIATION_UNSET:
>> +		BUG("FETCH_NEGOTIATION_UNSET only in prepare_repo_settings()");
>
> I was briefly confused why this BUG message mentioned
> FETCH_NEGOTIATION_UNSET, since we only support FETCH_NEGOTIATION_DEFAULT
> here.
>
> But then I realized that it said "only in prepare_repo_settings()", and
> we're in fetch_negotiator_init(). So this makes sense to me.
>
> Other than the small typo in the patch message, this looks good to me.
I guess I'll also mention NONE here, so:
    BUG("FETCH_NEGOTIATION_{NONE,UNSET} only in prepare_repo_settings()");
Or elaborate a bit:
    BUG("FETCH_NEGOTIATION_{NONE,UNSET} used outside of prepare_repo_settings()!");

In any case this lives for just one commit, and is just here to demonstrate the transition we're in.

Previous: Taylor BlauNext: Ævar Arnfjörð Bjarmason
Message 20 of 34 in “repo-settings.c: refactor for clarity, get rid of hacks etc.”
  1. 0/5 repo-settings.c: refactor for clarity, get rid of hacks etc.Ævar Arnfjörð Bjarmason, Sep 16, 2021
  2. 1/5 wrapper.c: add x{un,}setenv(), and use xsetenv() in environment.cÆvar Arnfjörð Bjarmason, Sep 16, 2021
  3. Junio C HamanoSep 17, 2021
  4. Ævar Arnfjörð BjarmasonSep 17, 2021
  5. 2/5 environment.c: remove test-specific "ignore_untracked..." variableÆvar Arnfjörð Bjarmason, Sep 16, 2021
  6. Junio C HamanoSep 17, 2021
  7. 3/5 read-cache & fetch-negotiator: check "enum" values in switch()Ævar Arnfjörð Bjarmason, Sep 16, 2021
  8. Junio C HamanoSep 17, 2021
  9. 5/5 repository.h: don't use a mix of int and bitfieldsÆvar Arnfjörð Bjarmason, Sep 16, 2021
  10. 4/5 repo-settings.c: simplify the setupÆvar Arnfjörð Bjarmason, Sep 16, 2021
  11. 0/5 repo-settings.c: refactor for clarity, get rid of hacks etc.Ævar Arnfjörð Bjarmason, Sep 19, 2021
  12. 2/5 environment.c: remove test-specific "ignore_untracked..." variableÆvar Arnfjörð Bjarmason, Sep 19, 2021
  13. Taylor BlauSep 20, 2021
  14. Ævar Arnfjörð BjarmasonSep 20, 2021
  15. 1/5 wrapper.c: add x{un,}setenv(), and use xsetenv() in environment.cÆvar Arnfjörð Bjarmason, Sep 19, 2021
  16. Taylor BlauSep 20, 2021
  17. Ævar Arnfjörð BjarmasonSep 20, 2021
  18. 3/5 read-cache & fetch-negotiator: check "enum" values in switch()Ævar Arnfjörð Bjarmason, Sep 19, 2021
  19. Taylor BlauSep 20, 2021
  20. Ævar Arnfjörð BjarmasonSep 20, 2021
  21. 5/5 repository.h: don't use a mix of int and bitfieldsÆvar Arnfjörð Bjarmason, Sep 19, 2021
  22. Taylor BlauSep 20, 2021
  23. 4/5 repo-settings.c: simplify the setupÆvar Arnfjörð Bjarmason, Sep 19, 2021
  24. Derrick StoleeSep 20, 2021
  25. Taylor BlauSep 20, 2021
  26. 0/5 repo-settings.c: refactor for clarity, get rid of hacks etc.Ævar Arnfjörð Bjarmason, Sep 21, 2021
  27. 1/5 wrapper.c: add x{un,}setenv(), and use xsetenv() in environment.cÆvar Arnfjörð Bjarmason, Sep 21, 2021
  28. 2/5 environment.c: remove test-specific "ignore_untracked..." variableÆvar Arnfjörð Bjarmason, Sep 21, 2021
  29. 3/5 read-cache & fetch-negotiator: check "enum" values in switch()Ævar Arnfjörð Bjarmason, Sep 21, 2021
  30. 4/5 repo-settings.c: simplify the setupÆvar Arnfjörð Bjarmason, Sep 21, 2021
  31. 5/5 repository.h: don't use a mix of int and bitfieldsÆvar Arnfjörð Bjarmason, Sep 21, 2021
  32. Derrick StoleeSep 21, 2021
  33. Taylor BlauSep 21, 2021
  34. Junio C HamanoSep 22, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.