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

Re: [PATCH v2 2/2] attr: more matching optimizations from .gitignore

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Oct 11, 2012, 01:36 UTC
Message-ID
<CACsJy8CdCN0hBU2WwffNvHOwcC87v2OVJj=SYH4BYYveBpFiQw@mail.gmail.com>
In-Reply-To
<7v626iatt9.fsf@alter.siamese.dyndns.org>
On Thu, Oct 11, 2012 at 4:41 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 17 quoted lines
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>
>>    @@ -690,16 +689,18 @@ static int path_matches(const char *pathname, int pathlen,
>>        * contain the trailing slash
>>        */
>>
>>    -  if (pathlen < baselen ||
>>    +  if (pathlen < baselen + 1 ||
>>           (baselen && pathname[baselen] != '/') ||
>>    -      strncmp(pathname, base, baselen))
>>    +      strncmp_icase(pathname, base, baselen))
>
> Shouldn't the last comparison be
>
>         strncmp_icase(pathname, base, baselen + 1)
>
> instead,

"base" does not contain the trailing slash, so it can only match up to base[baselen-1], then fail at base[baselen], which is '\0'. The "no trailing slash" business in this function is tricky :(

Show 7 quoted lines
> if you are trying to match this part from dir.c where
> baselen does count the trailing slash?
>
>                 if (pathlen < x->baselen ||
>                     (x->baselen && pathname[x->baselen-1] != '/') ||
>                     strncmp_icase(pathname, x->base, x->baselen))
>                         continue;

strncmp_icase() here just needs to compare x->baselen-1 chars (i.e. no trailing slash) as the trailing slash is explicitly checked just above strncmp_icase. But it does not hurt to compare an extra character so I leave it unchanged. But obviously it causes confusion when we try to match this function and the one in attr.c

-- 
Duy
Previous: Junio C HamanoNext: Junio C Hamano
Message 12 of 14 in “gitignore: make pattern parsing code a separate function”
  1. 1/2 gitignore: make pattern parsing code a separate functionNguyễn Thái Ngọc Duy, Oct 9, 2012
  2. 2/2 attr: more matching optimizations from .gitignoreNguyễn Thái Ngọc Duy, Oct 9, 2012
  3. Junio C HamanoOct 9, 2012
  4. Johannes SixtOct 9, 2012
  5. Junio C HamanoOct 9, 2012
  6. Junio C HamanoOct 9, 2012
  7. 2/2 attr: more matching optimizations from .gitignoreNguyễn Thái Ngọc Duy, Oct 10, 2012
  8. Junio C HamanoOct 10, 2012
  9. Nguyen Thai Ngoc DuyOct 12, 2012
  10. Junio C HamanoOct 10, 2012
  11. Junio C HamanoOct 10, 2012
  12. Nguyen Thai Ngoc DuyOct 11, 2012
  13. Junio C HamanoOct 12, 2012
  14. Nguyen Thai Ngoc DuyOct 13, 2012

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.