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

Re: [PATCH 2/3] exclude: do strcmp as much as possible before fnmatch

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
May 27, 2012, 12:06 UTC
Message-ID
<CACsJy8DOz30GD_zv9yO7KD55+=H0t=+q_5qRtt51nOoYXwOBBQ@mail.gmail.com>
In-Reply-To
<7vk3zyp14i.fsf@alter.siamese.dyndns.org>
On Sun, May 27, 2012 at 1:51 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>
>> this also avoids calling fnmatch() if the non-wildcard prefix is
>> longer than basename
>>
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>
> I have been wondering if you can take a different approach based on the
> same observation this patch is based on.  If you see an entry /foo/bar/*.c
> in the top-level .gitignore, perhaps you can set it aside in a different
> part of "struct exclude" for the top-level directory (because the pattern
> will never match outside foo/bar directory), so that it is not even used
> for matching, and only when you descend to foo/bar directory, add "/*.c"
> to the "struct exclude" you create for that directory.
that part is "base" field in "struct exclude", I believe.
> That way, instead of "strcmp is faster than fnmatch, but we always compare
> all elements in the huge pattern list given at the toplevel", you would be
> doing "we do not even bother to compare with the elements we know do not
> matter", which would be far more efficient, no?

You still have to do at least one strncmp on "base" though to know if a pattern is applicable to the given directory. So it's not really cheaper than what is done in 3/3.

-- 
Duy
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 14 in “top-level gitignore considered less harmful”
  1. 0/3 top-level gitignore considered less harmfulNguyễn Thái Ngọc Duy, May 26, 2012
  2. 1/3 Unindent excluded_from_list()Nguyễn Thái Ngọc Duy, May 26, 2012
  3. 2/3 exclude: do strcmp as much as possible before fnmatchNguyễn Thái Ngọc Duy, May 26, 2012
  4. Junio C HamanoMay 27, 2012
  5. Nguyen Thai Ngoc DuyMay 27, 2012
  6. Junio C HamanoMay 27, 2012
  7. Nguyen Thai Ngoc DuyMay 28, 2012
  8. Junio C HamanoMay 28, 2012
  9. Junio C HamanoMay 29, 2012
  10. Thiago FarinaMay 29, 2012
  11. 3/3 exclude: reduce computation cost on checking dirname in patternsNguyễn Thái Ngọc Duy, May 26, 2012
  12. Nguyen Thai Ngoc DuyMay 26, 2012
  13. Jeff KingMay 26, 2012
  14. Nguyen Thai Ngoc DuyMay 27, 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.