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

Re: [PATCH] merge-recursive: use fspathcmp() in path_hashmap_cmp()

From
René Scharfe <l.s.r@web.de>
Date
Aug 30, 2021, 18:22 UTC
Message-ID
<8d2e0876-9441-9665-ebb1-8cb28902014b@web.de>
In-Reply-To
<xmqqeeaa6fey.fsf@gitster.g>
Am 30.08.21 um 18:55 schrieb Junio C Hamano:
Show 34 quoted lines
> Taylor Blau <me@ttaylorr.com> writes:
>
>> Looks obviously right to me. I found another spot in
>> t/helper/test-hashmap.c:test_entry_cmp() that could be cleaned up in the
>> same way. But this looks fine with or without the following diff:
>
>> diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c
>> index 36ff07bd4b..ab34bdfecd 100644
>> --- a/t/helper/test-hashmap.c
>> +++ b/t/helper/test-hashmap.c
>> @@ -28,10 +28,7 @@ static int test_entry_cmp(const void *cmp_data,
>>         e1 = container_of(eptr, const struct test_entry, ent);
>>         e2 = container_of(entry_or_key, const struct test_entry, ent);
>>
>> -       if (ignore_case)
>> -               return strcasecmp(e1->key, key ? key : e2->key);
>> -       else
>> -               return strcmp(e1->key, key ? key : e2->key);
>> +       return fspathcmp(e1->key, key ? key : e2->key);
>
> Sorry but I think this patch is wrong.  Before the precontext of the
> patch, there is a local variable decl for ignore_case---the existing
> code looks at ignore_case that is different from the global
> ignore_case fspathcmp() looks at.
>
> Admittedly, it was probably not an excellent idea to give a name so
> bland and unremarkable, 'ignore_case', to a global that affects so
> many code paths in the system.  But the variable is already very
> established that renaming it would not contribute to improving the
> code at all.
>
> It however may not be a bad idea to catch these code paths where a
> local variable masks 'ignore_case' (and possibly other globals) and
> rename these local ones to avoid a mistake like this.

The name itself is OK, I think, but using it at global scope is confusing. -Wshadow can help find such cases, but not this one, as test-hashmap.c doesn't include the global declaration. Moving the global into a struct to provide a poor man's namespace would fix this for all namesakes, assisted by the compiler. We'd then access it as the_config.ignore_case or even the_config.core.ignore_case.

Moving all config-related variables would be quite noisy, I guess, and probably conflict with lots of in-flight patches, but might be worth it.

René
Previous: Junio C HamanoNext: Jeff King
Message 8 of 15 in “merge-recursive: use fspathcmp() in path_hashmap_cmp()”
  1. merge-recursive: use fspathcmp() in path_hashmap_cmp()René Scharfe, Aug 28, 2021
  2. Taylor BlauAug 29, 2021
  3. Jeff KingAug 29, 2021
  4. Junio C HamanoAug 30, 2021
  5. René ScharfeAug 30, 2021
  6. Jeff KingAug 30, 2021
  7. Junio C HamanoAug 30, 2021
  8. René ScharfeAug 30, 2021
  9. Jeff KingAug 30, 2021
  10. René ScharfeSep 11, 2021
  11. Johannes SchindelinSep 13, 2021
  12. Jeff KingSep 13, 2021
  13. Junio C HamanoSep 13, 2021
  14. Johannes SchindelinSep 14, 2021
  15. Jeff KingSep 14, 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.