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
Duy Nguyen <pclouds@gmail.com>
Date
Mar 10, 2016, 00:39 UTC
Message-ID
<CACsJy8CbxyJQ7HYy6GaqRhemeSz_upB6jQ7HMX0Vk+tr7bBz3w@mail.gmail.com>
In-Reply-To
<xmqqoaanilia.fsf@gitster.mtv.corp.google.com>
On Thu, Mar 10, 2016 at 12:55 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> 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.
Hmm.. yeah personal view. I'll take this out.
Show 12 quoted lines
>> 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.
Yep, bad phrasing.
Show 11 quoted lines
>> 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...

Naively speaking, in order to fix this without reorganizing a lot of code, when given path 'foo/bar/dir/file1' and the pattern '!dir/', we first still test if the full path "foo/bar/dir/file1" is a directory, then we cut "file1" out (pretend that we are in foo/bar instead of in foo/bar/dir) and test again the full path, which is just foo/bar/dir, if it's a directory. Repeat again and again. This trick does not go through the normal prep_exclude(), so patterns are not popping out when .gitignore should not be used any more.

The implementation is a bit different. Instead of going up one level, test, and go up again, I construct the new pattern "foo/bar/**/dir/**" and match it (only once) against the original full path foo/bar/dir/file1. The note was there because I would have just constructed "**/dir/**" instead and matched too much.

-- 
Duy
Previous: Junio C HamanoNext: Duy Nguyen
Message 22 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.