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

Re: [PATCH 3/8] tree_entry_interesting(): remove dependency on struct diff_options

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 14, 2010, 23:20 UTC
Message-ID
<7veicv7w06.fsf@alter.siamese.dyndns.org>
In-Reply-To
<AANLkTimHykY5V=C7vmDoA-HCWYLJT_p4MEyfdMqXgB6+@mail.gmail.com>
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
Show 7 quoted lines
>> About naming.  Where else other than "tree" (in the "hierarchical
>> namespace" sense) context do you see pathspec?  Does the struct really
>> need to be called TREE_pathspec_list?
>
> Pathspecs are usually stored in a list, const char ** and I don't want
> to take the generic name "pathspec_list", unless we convert all to use
> this struct. Any suggestions of other names?

I was hoping [*1*] that in the longer term we would have a unified machinery to handle pathspecs across ls-tree, ls-files, diff-tree, diff-files and grep. These commands more or less share the same idea of what purpose a pathspec serves, but take quite different codepaths, and the biggest problem is that some know globbing while others don't.

The problem arising from the two semantics [*2*] is visible when you run "git add" with pathspec where add_files_to_cache() updates the index only at changed paths (found using diff-files machinery, that implements "diff" family of pathspec semantics to match only directory prefix) and then add_files() adds the paths that are untracked (found using the ls-files machinery, that knows about globbing).

Once we have a unified machinery to handle pathspec, the data structure that holds the pathspec should naturally be called "struct pathspec", while an element on that list would be "struct pathspec_elem" or perhaps "struct pathspec_pattern" [*3*].

I would imagine that "struct exclude" (in dir.[ch]) that is contained in "struct exclude_list" might be a good place to start from, in the sense that it shows how a match pattern can be pre-parsed to optimize the matching operation [*4*]. It however may not know about one particular kind of optimization that is essential when dealing with tree objects: the ability to ask "is this subtree worth descending into?". That logic is necessary to avoid opening unnecessary tree objects in diff-tree and grep.

[Footnote]
*1* https://git.wiki.kernel.org/index.php/SoC2010Ideas#Unify_Pathspec_Semantics

*2* As the maintainer, I do consider it also is a problem that each of these semantics has multiple codepaths to implement it, but that is a secondary issue. Having two semantics is visible to the end user and is a bigger problem.

*3* I personally tend to consider the whole set as _a_ "path specification" even when you give more than one patterns to match on the command line, but it may be just me. I am Ok with "struct pathspec_set" that holds a set of "struct pathspec", too. Unlike exclude-list where the order of elements in it has a meaning, the matching patterns in a pathspec are unordered, so even if we may end up implementing it as a list, it would be incorrect to call that "struct pathspec_list".

*4* "struct exclude_list" is somewhat special in that it is a dynamic data source where you learn more matching rules as you dig deeper. We do not need that aspect of the dir.[ch] codepath for unified pathspec handling.

Previous: Nguyen Thai Ngoc DuyNext: Nguyễn Thái Ngọc Duy
Message 7 of 21 in “en/object-list-with-pathspec v4”
  1. 0/8 en/object-list-with-pathspec v4Nguyễn Thái Ngọc Duy, Sep 8, 2010
  2. 1/8 diff-no-index: use diff_tree_setup_paths()Nguyễn Thái Ngọc Duy, Sep 8, 2010
  3. 2/8 Introduce struct tree_pathspec_listNguyễn Thái Ngọc Duy, Sep 8, 2010
  4. 3/8 tree_entry_interesting(): remove dependency on struct diff_optionsNguyễn Thái Ngọc Duy, Sep 8, 2010
  5. Junio C HamanoSep 14, 2010
  6. Nguyen Thai Ngoc DuySep 14, 2010
  7. Junio C HamanoSep 14, 2010
  8. 4/8 tree-walk: move tree_entry_interesting() from tree-diff.cNguyễn Thái Ngọc Duy, Sep 8, 2010
  9. 5/8 Add testcases showing how pathspecs are ignored with rev-list --objectsNguyễn Thái Ngọc Duy, Sep 8, 2010
  10. Junio C HamanoSep 14, 2010
  11. 6/8 Make rev-list --objects work together with pathspecsNguyễn Thái Ngọc Duy, Sep 8, 2010
  12. 7/8 setup_tree_pathspec(): interpret '^' as negative pathspecNguyễn Thái Ngọc Duy, Sep 8, 2010
  13. Elijah NewrenSep 11, 2010
  14. Nguyen Thai Ngoc DuySep 13, 2010
  15. Junio C HamanoSep 14, 2010
  16. Nguyen Thai Ngoc DuySep 14, 2010
  17. 8/8 tree_entry_interesting(): support negative pathspecNguyễn Thái Ngọc Duy, Sep 8, 2010
  18. Elijah NewrenSep 11, 2010
  19. Junio C HamanoSep 14, 2010
  20. Nguyen Thai Ngoc DuySep 14, 2010
  21. Elijah NewrenSep 11, 2010

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.