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

Re: [PATCH 8/8] pathspec: convert parse_pathspec to take an index

From
BWBrandon Williams <bmwill@google.com>
Date
May 10, 2017, 17:02 UTC
Message-ID
<20170510170226.GB41649@google.com>
In-Reply-To
<xmqq1srxxn72.fsf@gitster.mtv.corp.google.com>
On 05/10, Junio C Hamano wrote:
Show 30 quoted lines
> Brandon Williams <bmwill@google.com> writes:
> 
> > Convert 'parse_pathspec()' to take an index parameter.
> >
> > Since the index is only needed when the PATHSPEC_SUBMODULE_LEADING_PATH
> > and PATHSPEC_STRIP_SUBMODULE_SLASH flags are given, add a check
> > requiring a non-NULL index when either of these flags are given.
> > Convert callers which use these two flags to pass in an index while
> > having other callers pass in NULL.
> >
> > Now that pathspec.c does not use any cache macros and has no references
> > to 'the_index', mark it by defining NO_THE_INDEX_COMPATIBILITY_MACROS.
> >
> > Signed-off-by: Brandon Williams <bmwill@google.com>
> 
> The same comment as 5/8 applies to this change, but it is a bit
> easier to judge, because it has so many callers, and for some
> builtins, especially manipulator commands like add, checkout, and
> commit, there may be a good reason why they want to keep the primary
> index while playing with an additional in-core index in a distant
> future.
> 
> Does a pathspec parsed using one instance of index_state expected to
> work when matching against a path in another instance of index_state?
> Otherwise, passing a non-NULL istate to parse_pathspec() would tie
> the resulting pathspec to a particular index_state in some way and
> there may need a mechanism to catch an attempt to match paths in
> another index_state with such a pathspec as an error.  Just
> speculating out loud...
> 

Currently I don't believe this links a pathspec with a particular index_state since an index is really just used to do some pre-processing on the paths (check if the path goes into a submodule and die, or strip a slash if the path matches a submodule), though I can see a future where this is true.

I did have another version of this series where I completely removed the two flags related to submodules. Since builtin/add is the only caller which needs to die if a path descends into a submodule, I had a function which did this after the parse_pathspec() call. Also, since (ae8d08242 pathspec: pass directory indicator to match_pathspec_item()) stripping off the slash from a submodule path really is no longer needed for the path matching logic, this means that we could potentially just drop the strip slash flag. The only caveat is ls-files.

ls-files is the only command (that I know of) which does cache pruning based on the common prefix of all pathspecs given. If there is a submodule named 'sub' and you provided a pathspec 'sub/', the matching logic can handle this but the cache pruning logic would prune all entries from the index which don't have a leading 'sub/' which is the common prefix of all pathspecs (if you didn't strip off the slash). Meaning you'd prune the submodule 'sub' when you really didn't want to. This could probably be fixed to have the cache pruning logic to prune by ignoring the trailing slash always.

So there's another option here if you don't feel quite right about piping through an index into parse_pathspec just yet.

-- 
Brandon Williams
Previous: Junio C HamanoNext: Junio C Hamano
Message 15 of 29 in “convert pathspec.c to take an index parameter”
  1. 0/8 convert pathspec.c to take an index parameterBrandon Williams, May 9, 2017
  2. 2/8 submodule: add die_in_unpopulated_submodule functionBrandon Williams, May 9, 2017
  3. 3/8 pathspec: change PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE flagBrandon Williams, May 9, 2017
  4. Junio C HamanoMay 10, 2017
  5. Brandon WilliamsMay 10, 2017
  6. 1/8 pathspec: provide a more descriptive die messageBrandon Williams, May 9, 2017
  7. 5/8 pathspec: convert strip_submodule_slash to take an indexBrandon Williams, May 9, 2017
  8. Junio C HamanoMay 10, 2017
  9. 7/8 pathspec: convert init_pathspec_item to take an indexBrandon Williams, May 9, 2017
  10. 6/8 pathspec: convert find_pathspecs_matching_against_index to take an indexBrandon Williams, May 9, 2017
  11. 4/8 pathspec: rename PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAPBrandon Williams, May 9, 2017
  12. Junio C HamanoMay 10, 2017
  13. 8/8 pathspec: convert parse_pathspec to take an indexBrandon Williams, May 9, 2017
  14. Junio C HamanoMay 10, 2017
  15. Brandon WilliamsMay 10, 2017
  16. Junio C HamanoMay 11, 2017
  17. Johannes SixtMay 11, 2017
  18. Junio C HamanoMay 11, 2017
  19. Brandon WilliamsMay 11, 2017
  20. Junio C HamanoMay 12, 2017
  21. 0/6 convert pathspec.c to take an index parameterBrandon Williams, May 11, 2017
  22. 2/6 submodule: add die_in_unpopulated_submodule functionBrandon Williams, May 11, 2017
  23. 4/6 ls-files: prevent prune_cache from overeagerly pruning submodulesBrandon Williams, May 11, 2017
  24. 3/6 pathspec: remove PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE flagBrandon Williams, May 11, 2017
  25. 6/6 pathspec: convert find_pathspecs_matching_against_index to take an indexBrandon Williams, May 11, 2017
  26. 5/6 pathspec: remove PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAPBrandon Williams, May 11, 2017
  27. 1/6 pathspec: provide a more descriptive die messageBrandon Williams, May 11, 2017
  28. Junio C HamanoMay 12, 2017
  29. Brandon WilliamsMay 12, 2017

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.