Re: [PATCH 1/4] ref-cache.c: fix prefix matching in ref iteration
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 9, 2023, 18:15 UTC
- Message-ID
- <xmqqa5sr1x3p.fsf@gitster.g>
- In-Reply-To
- <3585d72f-9f06-d190-ad5a-bec6db3f647f@github.com>
Victoria Dye <vdye@github.com> writes:
> 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.
Ah, yes, I didn't mention it but I suspected as such (i.e. the code is structured in such a way that this broken implementation does not matter to the current callers).
> 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.
OK, perfectly understandable.
Show 11 quoted lines
> 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.
Good find. Thanks!