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

Re: [RFC PATCH 3/3] grep: add support for grepping in submodules

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 29, 2010, 22:59 UTC
Message-ID
<7v4od8ma0j.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4CA3BBD7.3090006@web.de>
Jens Lehmann <Jens.Lehmann@web.de> writes:
> Hm, at a quick glance it might be much easier to copy argc & argv
> in cmd_grep() before parse_options() starts manipulating it.

Yes, I think that is a much saner direction to go. Otherwise, you would need to unparse grep boolean expressions as well.

A few more things to think about.
1. What does this mean:
    $ git grep --recursive -e frotz master next

It recurses into the submodule commits recorded in 'master' and 'next' commits in the superproject, right?

How do the lines output from the above look like? From the superproject, we will get lines like these:

    master:t/README:  test_description='xxx test (option --frotz)
    master:t/README:  and tries to run git-ls-files with option --frotz.'

What if we have a submodule at git-gui in the superproject, and its README has string frotz in it? Should we label the submodule commit we find in 'master' of superproject as 'master' as well, even if it is not at the tip of 'master' branch of the submodule? Or do we get abbreviated hexadecimal SHA-1 name? IOW, would we see:

    master:git-gui/README: git-gui also knows frotz
or
    deadbeef:git-gui/README: git-gui also knows frotz

where "deadbeaf...." is what "git rev-parse master:git-gui" would give us in the superproject?

I tend to think the former is preferable, but then most likely you would need to pass not just submodule-prefix but the original ref name (i.e. 'master') you started from down to the recursive one.

2. Now how would this work with pathspecs?
    $ git grep --recursive -e frotz -- dir/

This should look for the string in the named directory in the superproject and if there are submodules in that directory, recurse into them as well, right?

What pathspec, if any, will be in effect when we recurse into the submodule at dir/sub? Limiting to dir/ feels wrong, no?

3. Corollary.

Is it reasonable to expect that we will look into all shell scripts, both in the superproject and in submodules, with this:

    $ git grep --recursive -e frotz -- '*.sh'

Oops? What happened to the "we restrict the recursion using pathspec, and we do not pass down the pathspec" that was suggested in 2.?

Previous: Jens LehmannNext: Chris Packham
Message 13 of 22 in “grep: submodule support”
  1. 0/3 grep: submodule supportChris Packham, Sep 29, 2010
  2. 1/3 add test for git grep --recursiveChris Packham, Sep 29, 2010
  3. Ævar Arnfjörð BjarmasonSep 29, 2010
  4. Chris PackhamSep 29, 2010
  5. Kevin BallardSep 29, 2010
  6. 2/3 grep: prepare grep for submodulesChris Packham, Sep 29, 2010
  7. Nguyen Thai Ngoc DuySep 30, 2010
  8. Chris PackhamSep 30, 2010
  9. Nguyen Thai Ngoc DuyOct 1, 2010
  10. Chris PackhamOct 1, 2010
  11. 3/3 grep: add support for grepping in submodulesChris Packham, Sep 29, 2010
  12. Jens LehmannSep 29, 2010
  13. Junio C HamanoSep 29, 2010
  14. Chris PackhamSep 29, 2010
  15. Jens LehmannSep 30, 2010
  16. Johannes SixtSep 30, 2010
  17. Jens LehmannSep 30, 2010
  18. Chris PackhamSep 29, 2010
  19. Jens LehmannSep 30, 2010
  20. Chris PackhamSep 30, 2010
  21. Heiko VoigtSep 30, 2010
  22. Jens LehmannSep 30, 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.