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

Re: [PATCH] dir.c: fix dir re-inclusion rules with "NODIR" and "MUSTBEDIR"

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 9, 2016, 17:55 UTC
Message-ID
<xmqqoaanilia.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1457521693-26141-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> Side note, it's probably a bad idea to use basename matching on a
> negative rule (ie. no slashes in the pattern) because what the pattern
> says is "re-include _any_ directory named 'dir'", not just the directory
> "dir" at right below this directory.

I am not sure I agree with this comment. When we say '.depend/' in our .gitignore file, we do want to ignore everything in the directory with that name anywhere in that tree. Perhaps '!include/' followed by '*' may be a good way to pick only the header files that are found in any directory with that name anywhere in the tree in a similar fashion. It certainly is a disappointing comment if made by somebody who wants to make 'dir' and '!dir' behave in a more similar way, I'd have to say.

Show 11 quoted lines
> In the MUSTBEDIR case, the patterns look like this
>
>     *          # exclude dir, dir/file1 and dir/file2..
>     !dir/      #  ..except that dir and everything inside is re-included..
>     dir/file2  # ..except (again!) that dir/file2 is excluded
>                # ..which means dir/file1 stays included
>
> Again, we're ok at the toplevel, then we enter "dir" and test
> "dir/file1". The MUSTBEDIR code tests if the _full_ path (ie. "dir/file1")
> is a directory. We want it to test the "dir" part from "dir/file1"
> instead.
That certainly sounds like a breakage worth fixing.
> In both cases, we want to test if the pattern matches a parent
> directory. match_dir_component() is for this purpose.

I do not follow. I would understand "In all cases, we want to behave as if we are testing the _full_ path against the pattern", though.

IOW, "dir/file1" matches '*' (because 'file1' and '*' matches), '!dir/' (because the pattern is "everything under dir/ directory), and nothing else in the pattern list, and the last match wins---which happens to be negative ignore, hence dir/file1 is not ignored.

> We do want to be careful not to get back too far. Given the file
> foo/bar/.gitignore, we should only check as far back as foo/bar because
> this .gitignore file can never match outside that directory, which is
> "toplevel" in the above paragraphs, to begin with.

Yes. But isn't that what exclude_stack mechanism already gives us? That is, when you are not looking at a path inside foo/bar/, entries stored in foo/bar/.gitignore will not participate the determination of the fate of the path.

I am not sure why you have to say this.  Puzzled...
Previous: Nguyễn Thái Ngọc DuyNext: Duy Nguyen
Message 21 of 28 in “Change in .gitignore handling: intended or bug?”
  1. Charles StrahanMar 4, 2016
  2. Duy NguyenMar 4, 2016
  3. Kevin DaudtMar 4, 2016
  4. Charles StrahanMar 4, 2016
  5. Kevin DaudtMar 4, 2016
  6. Duy NguyenMar 4, 2016
  7. Junio C HamanoMar 4, 2016
  8. Junio C HamanoMar 4, 2016
  9. Duy NguyenMar 5, 2016
  10. Duy NguyenMar 5, 2016
  11. Charles StrahanMar 5, 2016
  12. Junio C HamanoMar 5, 2016
  13. Junio C HamanoMar 7, 2016
  14. Junio C HamanoMar 8, 2016
  15. Duy NguyenMar 8, 2016
  16. Junio C HamanoMar 8, 2016
  17. Duy NguyenMar 9, 2016
  18. Junio C HamanoMar 9, 2016
  19. Junio C HamanoMar 9, 2016
  20. dir.c: fix dir re-inclusion rules with "NODIR" and "MUSTBEDIR"Nguyễn Thái Ngọc Duy, Mar 9, 2016
  21. Junio C HamanoMar 9, 2016
  22. Duy NguyenMar 10, 2016
  23. Duy NguyenMar 9, 2016
  24. Junio C HamanoMar 9, 2016
  25. Duy NguyenMar 10, 2016
  26. Junio C HamanoMar 10, 2016
  27. Junio C HamanoMar 10, 2016
  28. Duy NguyenMar 10, 2016

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.