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

Re: [PATCH 2/5] pathspec: add PATHSPEC_FROMROOT flag

From
Stefan Beller <sbeller@google.com>
Date
Feb 25, 2017, 00:31 UTC
Message-ID
<CAGZ79kYRrAmJ+=563PBkdiBwaUzqqQOMVANT_fTvURFv+=Yiog@mail.gmail.com>
In-Reply-To
<20170224235100.52627-3-bmwill@google.com>
On Fri, Feb 24, 2017 at 3:50 PM, Brandon Williams <bmwill@google.com> wrote:
Show 6 quoted lines
> Add the `PATHSPEC_FROMROOT` flag to allow callers to instruct
> 'parse_pathspec()' that all provided pathspecs are relative to the root
> of the repository.  This allows a caller to prevent a path that may be
> outside of the repository from erroring out during the pathspec struct
> construction.
>
> +/* For callers that know all paths are relative to the root of the repository */
> +#define PATHSPEC_FROMROOT (1<<9)

What is the calling convention for these submodule pathspecs? IIRC, we'd pass on the super-prefix and the literal pathspec, e.g. when there is a submodule "sub" inside the superproject, The invocation on the submodule would be

    git FOO --super-prefix="sub" <arguments> -- sub/pathspec/inside/...

and then the submodule process would need to "subtract" the superprefix from the pathspec argument to see its actual pathspec, e.g. in gerrit:

$ GIT_TRACE=1 git grep --recurse-submodules -i test -- \
    plugins/cookbook-plugin/
...
trace: run_command: '--super-prefix=plugins/cookbook-plugin/' 'grep' \
  '--recurse-submodules' '-i' '-etest' '--threads=4' '--'
'plugins/cookbook-plugin/'
..
but also:
...
 trace: run_command: '--super-prefix=plugins/download-commands/' 'grep' \
  '--recurse-submodules' '-i' '-etest' '--threads=4' '--'
'plugins/cookbook-plugin/'
...
So if I change into a directory:

$ cd plugins plugins$ git grep --recurse-submodules -i test -- cookbook-plugin/ plugins$ #empty? plugins$ git grep --recurse-submodules -i test -- plugins/cookbook-plugin/ ... Usual output, so the pathspecs are absolute path to the superprojects root? Let's try relative path: plugins$ git grep --recurse-submodules -i test -- ../plugins/cookbook-plugin/ fatal: ../plugins/cookbook-plugin/: '../plugins/cookbook-plugin/' is outside repository ... Running with GIT_TRACE=1:

trace: run_command: '--super-prefix=plugins/cookbook-plugin/' 'grep' \
    '--recurse-submodules' '-i' '-etest' '--threads=4' '--'
'../plugins/cookbook-plugin/'

that seems like a mismatch of pathspec and superproject prefix, the prefix ought to be different then? Maybe also including ../ because that is the relative path from cwd to the superporojects root and that is where we anchor all paths?

Easy to test that out:
plugins$ GIT_TRACE=1 git --super-prefix=../ grep --recurse-submodules \
    -i test -- ../plugins/cookbook-plugin/
fatal: can't use --super-prefix from a subdirectory
ok, not as easy. :/

So another test with relative path: (in git.git)

cd t/diff-lib t/diff-lib$ git grep freedom COPYING:freedom to share and change it. By contrast, the GNU General Public ...

So the path displayed is relative to the cwd (and the search results as well) In the submodule case we would expect to have the super prefix to be computed to be relative to the cwd?

Checking the tests, this is handled correctly with this patch series. :)
But nevertheless, I think I know why I dislike this approach now:
The super prefix is handled "too dumb" IMHO, see the case
    plugins$ git grep test  -- cookbook-plugin/
above, that doesn't correctly figure out the correct output.
Although this might be a separate bug, but it sounds like it
is the same underlying issue.

-- for the naming: How about PATHSPEC_FROMOUTSIDE when going with the series as is here? (the superprefix is not resolved, so the pathspecs given are literally pathspecs that are outside this repo and we can ignore them?

Thanks, Stefan

Previous: Brandon WilliamsNext: Brandon Williams
Message 6 of 48 in “recursing submodules with relative pathspec (grep and ls-files)”
  1. 0/5 recursing submodules with relative pathspec (grep and ls-files)Brandon Williams, Feb 24, 2017
  2. 1/5 grep: illustrate bug when recursing with relative pathspecBrandon Williams, Feb 24, 2017
  3. Duy NguyenFeb 26, 2017
  4. Brandon WilliamsFeb 27, 2017
  5. 2/5 pathspec: add PATHSPEC_FROMROOT flagBrandon Williams, Feb 24, 2017
  6. Stefan BellerFeb 25, 2017
  7. 3/5 grep: fix bug when recuring with relative pathspecBrandon Williams, Feb 24, 2017
  8. Junio C HamanoFeb 28, 2017
  9. Brandon WilliamsMar 2, 2017
  10. 5/5 ls-files: fix bug when recuring with relative pathspecBrandon Williams, Feb 24, 2017
  11. Junio C HamanoFeb 28, 2017
  12. Brandon WilliamsMar 2, 2017
  13. 4/5 ls-files: illustrate bug when recursing with relative pathspecBrandon Williams, Feb 24, 2017
  14. Brandon WilliamsFeb 27, 2017
  15. grep: fix bug when recursing with relative pathspecBrandon Williams, Mar 6, 2017
  16. 0/4 recursing submodules with relative pathspec (grep and ls-files)Brandon Williams, Mar 14, 2017
  17. 1/4 grep: fix help text typoBrandon Williams, Mar 14, 2017
  18. Stefan BellerMar 14, 2017
  19. Brandon WilliamsMar 15, 2017
  20. 2/4 setup: allow for prefix to be passed to git commandsBrandon Williams, Mar 14, 2017
  21. Johannes SchindelinMar 14, 2017
  22. Brandon WilliamsMar 14, 2017
  23. 3/4 grep: fix bug when recursing with relative pathspecBrandon Williams, Mar 14, 2017
  24. Stefan BellerMar 14, 2017
  25. 4/4 ls-files: fix bug when recursing with relative pathspecBrandon Williams, Mar 14, 2017
  26. Stefan BellerMar 14, 2017
  27. Brandon WilliamsMar 15, 2017
  28. 0/5 recursing submodules with relative pathspec (grep and ls-files)Brandon Williams, Mar 17, 2017
  29. 3/5 grep: fix bug when recursing with relative pathspecBrandon Williams, Mar 17, 2017
  30. Duy NguyenMar 21, 2017
  31. Junio C HamanoMar 21, 2017
  32. Brandon WilliamsMar 22, 2017
  33. 5/5 ls-files: fix bug when recursing with relative pathspecBrandon Williams, Mar 17, 2017
  34. 4/5 ls-files: fix typo in variable nameBrandon Williams, Mar 17, 2017
  35. 2/5 setup: allow for prefix to be passed to git commandsBrandon Williams, Mar 17, 2017
  36. Stefan BellerMar 17, 2017
  37. Junio C HamanoMar 17, 2017
  38. Brandon WilliamsMar 17, 2017
  39. Junio C HamanoMar 17, 2017
  40. Brandon WilliamsMar 17, 2017
  41. Junio C HamanoMar 17, 2017
  42. Brandon WilliamsMar 20, 2017
  43. Junio C HamanoMar 21, 2017
  44. Stefan BellerMar 28, 2017
  45. Brandon WilliamsMar 17, 2017
  46. Stefan BellerMar 17, 2017
  47. Brandon WilliamsMar 17, 2017
  48. 1/5 grep: fix help text typoBrandon Williams, Mar 17, 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.