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

Re: [PATCH/WIP 02/11] notes-merge: use opendir/readdir instead of using read_directory()

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Oct 27, 2011, 07:51 UTC
Message-ID
<CACsJy8C4iHffr4UYP9SvCU0OPC-LocUORwAQ492LqaV_tyvFQA@mail.gmail.com>
In-Reply-To
<7vmxcn3b8w.fsf@alter.siamese.dyndns.org>
On Thu, Oct 27, 2011 at 4:37 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
> Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
>
>> Current read_directory() treats given path separately from contents
>> inside the path. If the given path has ".git", it's ok (but it'll stop
>> at .git if during tree recursion). The new read_directory() does not
>> make this exception, so when note-merge call
>> read_directory(".git/NOTES_MERGE_WORKTREE"), read_directory() sees
>> ".git" and stops immediately, assuming it's a gitlink.
>
> When read_directory("where/ever") is called, what kind of paths does it
> collect? Do the paths the function collects share "where/ever" as their
> common prefix? I thought it collects the paths relative to whatever
> top-level directory given to the function, so that "where/ever" could be
> anything.

Correct. But read_directory() takes pathspec now so naturally it does not treat "where/ever" a common prefix anymore. So it has to open(".") and starts from there. Even current code does not trust "where/ever" completely. treat_leading_path() may dismiss "where/ever" if it's excluded by .gitignore.

> Why does it even have to look at the given path in the first place and
> make a decision heavier than "can I opendir() and read from it"?
Because opendir("wh*/*r") may fail.
> In other
> words, if you see read_directory("some/thing/.git/more/stuff") and find a
> substring ".git/" in there, what "magic" gitlink handling does the code
> have to do?

"some/thing/.git" can be considered a new entry in index, so it should stop traversing at ".git". But because "some/thing/.git" does not exacly match "some/thing/.git/more/stuff", it is filtered out.

git-add deals with this case especially in order to avoid accidentally replace "some/thing/.git" in index with "some/thing/.git/more/stuff". But I feel it should be handled by read_directory(), not git-add.

Show 8 quoted lines
> I do not think it matters for _this_ particular case, but I can for
> example imagine an alternative implementation of a merge that uses
> temporary working tree somewhere other than the main working tree, and one
> of the natural "temporary" places such a feature in the future may want to
> use is inside .git/ somewhere. If you are planning to close the door by
> breaking the behaviour of read_directory(".git/some_where") for such
> callers with this series, we need to be aware of it, and that is why I am
> not satisfied by your explanation.

Maybe I should step back a bit. Instead of treating any input to read_directory() as pathspec, callers may provide two sets: a prefix set and a pathspec set. read_directory() starts from the prefix set without any checks, then descends in using pathspec.

But then what about the "if (treat_one_path(..) == path_ignored)" in treat_leading_path()? Remove it?

-- 
Duy
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 50 in “read_directory() rewrite to support struct pathspec”
  1. 00/11 read_directory() rewrite to support struct pathspecNguyễn Thái Ngọc Duy, Oct 24, 2011
  2. 01/11 Introduce "check-attr --excluded" as a replacement for "add --ignore-missing"Nguyễn Thái Ngọc Duy, Oct 24, 2011
  3. Junio C HamanoOct 27, 2011
  4. Nguyen Thai Ngoc DuyOct 28, 2011
  5. 02/11 notes-merge: use opendir/readdir instead of using read_directory()Nguyễn Thái Ngọc Duy, Oct 24, 2011
  6. Junio C HamanoOct 25, 2011
  7. Nguyen Thai Ngoc DuyOct 26, 2011
  8. Junio C HamanoOct 26, 2011
  9. Nguyen Thai Ngoc DuyOct 27, 2011
  10. Junio C HamanoOct 27, 2011
  11. Nguyen Thai Ngoc DuyOct 28, 2011
  12. 1/2 t3310: Add testcase demonstrating failure to --commit from within another dirJohan Herland, Mar 12, 2012
  13. 2/2 notes-merge: use opendir/readdir instead of using read_directory()Johan Herland, Mar 12, 2012
  14. Nguyen Thai Ngoc DuyMar 12, 2012
  15. fixup! t3310 on WindowsJohannes Sixt, Mar 14, 2012
  16. Johan HerlandMar 14, 2012
  17. Johannes SixtMar 14, 2012
  18. David BremnerMar 14, 2012
  19. Johan HerlandMar 14, 2012
  20. Junio C HamanoMar 14, 2012
  21. 3/2 notes-merge: Don't remove .git/NOTES_MERGE_WORKTREE; it may be the user's cwdJohan Herland, Mar 14, 2012
  22. Junio C HamanoMar 15, 2012
  23. Junio C HamanoMar 15, 2012
  24. Johan HerlandMar 15, 2012
  25. Re* [PATCH 3/2] notes-merge: Don't remove .git/NOTES_MERGE_WORKTREE; it may be the user's cwdJunio C Hamano, Mar 15, 2012
  26. Junio C HamanoMar 15, 2012
  27. Johannes SixtMar 15, 2012
  28. 03/11 t5403: avoid doing "git add foo/bar" where foo/.git existsNguyễn Thái Ngọc Duy, Oct 24, 2011
  29. Junio C HamanoOct 25, 2011
  30. Nguyen Thai Ngoc DuyOct 26, 2011
  31. Junio C HamanoOct 26, 2011
  32. Nguyen Thai Ngoc DuyOct 27, 2011
  33. Junio C HamanoOct 27, 2011
  34. Nguyen Thai Ngoc DuyOct 30, 2011
  35. Junio C HamanoOct 30, 2011
  36. Nguyen Thai Ngoc DuyOct 30, 2011
  37. Junio C HamanoOct 30, 2011
  38. 04/11 tree-walk.c: do not leak internal structure in tree_entry_len()Nguyễn Thái Ngọc Duy, Oct 24, 2011
  39. Junio C HamanoOct 25, 2011
  40. 05/11 symbolize return values of tree_entry_interesting()Nguyễn Thái Ngọc Duy, Oct 24, 2011
  41. Junio C HamanoOct 25, 2011
  42. Junio C HamanoOct 27, 2011
  43. Nguyen Thai Ngoc DuyOct 30, 2011
  44. 06/11 read_directory_recursive: reduce one indentation levelNguyễn Thái Ngọc Duy, Oct 24, 2011
  45. 07/11 tree_entry_interesting: make use of local pointer "item"Nguyễn Thái Ngọc Duy, Oct 24, 2011
  46. 08/11 tree-walk: mark useful pathspecsNguyễn Thái Ngọc Duy, Oct 24, 2011
  47. 09/11 tree_entry_interesting: differentiate partial vs full matchNguyễn Thái Ngọc Duy, Oct 24, 2011
  48. 10/11 read-dir: stop using path_simplify code in favor of tree_entry_interesting()Nguyễn Thái Ngọc Duy, Oct 24, 2011
  49. 11/11 dir.c: remove dead code after read_directory() rewriteNguyễn Thái Ngọc Duy, Oct 24, 2011
  50. Junio C HamanoOct 24, 2011

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.