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

Re: [PATCH 1/4] ref-cache.c: fix prefix matching in ref iteration

From
Victoria Dye <vdye@github.com>
Date
Oct 9, 2023, 16:21 UTC
Message-ID
<3585d72f-9f06-d190-ad5a-bec6db3f647f@github.com>
In-Reply-To
<ZSPQLjJwq-7SjsDT@tanuki>
Patrick Steinhardt wrote:
Show 21 quoted lines
>> Allowing prefix="refs/heads/v1.0" to yield entry="refs/heads/v1"
>> (case #2 above that this patch fixes the behaviour for) would cause
>> ref_iterator_advance() to return a ref outside the hierarhcy,
>> wouldn't it?  So it appears to me that either one of the two would
>> be true:
>>
>>  * the code is structured in such a way that such a condition does
>>    not actually happen (in which case this patch would be a no-op),
>>    or
>>
>>  * there is a bug in the current code that is fixed by this patch,
>>    whose externally observable behaviour can be verified with a
>>    test.
>>
>> It is not quite clear to me which is the case here.  The code with
>> the patch looks more logical than the original, but I am not sure
>> how to demonstrate the existing breakage (if any).
> 
> Agreed, I also had a bit of a hard time to figure out whether this is an
> actual bug fix, a performance improvement or merely a refactoring.
> 

I originally operated on the assumption that it was the first case, which is why I didn't include a test in this patch. Commands like 'for-each-ref', 'show-ref', etc. either use an empty prefix or a directory prefix with a trailing slash, which won't trigger this issue. I encountered the problem while working on a builtin that filtered refs by a user-specified prefix - the results included refs that should not have been matched, which led me to this fix.

Scanning through the codebase again, though, I do see a way to replicate the issue:

$ git update-ref refs/bisect/b HEAD $ git rev-parse --abbrev-ref --bisect refs/bisect/b

Because 'rev-parse --bisect' uses the "refs/bisect/bad" prefix (no trailing slash) and does no additional filtering in its 'for_each_fullref_in' callback, refs like "refs/bisect/b" and "refs/bisect/ba" are (incorrectly) matched. I'll re-roll with the added test.

Previous: Patrick SteinhardtNext: Junio C Hamano
Message 5 of 21 in “Performance improvement & cleanup in loose ref iteration”
  1. 0/4 Performance improvement & cleanup in loose ref iterationVictoria Dye via GitGitGadget, Oct 6, 2023
  2. 1/4 ref-cache.c: fix prefix matching in ref iterationVictoria Dye via GitGitGadget, Oct 6, 2023
  3. Junio C HamanoOct 6, 2023
  4. Patrick SteinhardtOct 9, 2023
  5. Victoria DyeOct 9, 2023
  6. Junio C HamanoOct 9, 2023
  7. 3/4 dir.[ch]: add 'follow_symlink' arg to 'get_dtype'Victoria Dye via GitGitGadget, Oct 6, 2023
  8. 2/4 dir.[ch]: expose 'get_dtype'Victoria Dye via GitGitGadget, Oct 6, 2023
  9. Junio C HamanoOct 6, 2023
  10. 4/4 files-backend.c: avoid stat in 'loose_fill_ref_dir'Victoria Dye via GitGitGadget, Oct 6, 2023
  11. Junio C HamanoOct 6, 2023
  12. Junio C HamanoOct 6, 2023
  13. Patrick SteinhardtOct 9, 2023
  14. Victoria DyeOct 9, 2023
  15. Patrick SteinhardtOct 10, 2023
  16. 0/4 Performance improvement & cleanup in loose ref iterationVictoria Dye via GitGitGadget, Oct 9, 2023
  17. 1/4 ref-cache.c: fix prefix matching in ref iterationVictoria Dye via GitGitGadget, Oct 9, 2023
  18. Patrick SteinhardtOct 10, 2023
  19. 2/4 dir.[ch]: expose 'get_dtype'Victoria Dye via GitGitGadget, Oct 9, 2023
  20. 3/4 dir.[ch]: add 'follow_symlink' arg to 'get_dtype'Victoria Dye via GitGitGadget, Oct 9, 2023
  21. 4/4 files-backend.c: avoid stat in 'loose_fill_ref_dir'Victoria Dye via GitGitGadget, Oct 9, 2023

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.