Re: [PATCH 1/4] dir.c: fix match_pathname()
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Feb 16, 2016, 01:17 UTC
- Message-ID
- <CACsJy8Be+39RLr27_1kSH4WhkoVUr0SZVvCqjzZVvUTtDoAXZg@mail.gmail.com>
- In-Reply-To
- <xmqqmvr1o8lk.fsf@gitster.mtv.corp.google.com>
On Tue, Feb 16, 2016 at 6:29 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 22 quoted lines
> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes: > >> Given the pattern "1/2/3/4" and the path "1/2/3/4/f", the pattern >> prefix is "1/2/3/4". We will compare and remove the prefix from both >> pattern and path and come to this code >> >> /* >> * If the whole pattern did not have a wildcard, >> * then our prefix match is all we need; we >> * do not need to call fnmatch at all. >> */ >> if (!patternlen && !namelen) >> return 1; >> >> where patternlen is zero (full pattern consumed) and the remaining >> path in "name" is "/f". We fail to realize it's matched in this case >> and fall back to fnmatch(), which also fails to catch it. Fix it. > > OK. And by checking *name against '/', we won't mistakenly say that > "1/2/3/4f" matches the pattern. Nicely explained. > > Can a pattern end with a '/'?
No. At this point, we must have stripped that trailing slash and turned it to flag EXC_FLAG_MUSTBEDIR.
-- Duy