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

Re: [PATCH] grep: provide a noop --recursive option

From
Stefan Beller <sbeller@google.com>
Date
Oct 1, 2018, 19:23 UTC
Message-ID
<CAGZ79kbw96x2Dow7d-sUfOHXiVN8j9KgqEObo+TrVd5zWKbaEA@mail.gmail.com>
In-Reply-To
<20180929145527.23444-1-avarab@gmail.com>

On Sat, Sep 29, 2018 at 7:55 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 40 quoted lines
>
> This --recursive (-r) option does nothing, and is purely here to
> appease people who have "grep -r ..." burned into their muscle memory.
>
> Requested-by: Christoph Berg <myon@debian.org>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>
> On Sat, Sep 29, 2018 at 4:10 PM Christoph Berg <myon@debian.org> wrote:
> >
> > I often use "grep -r $pattern" to recursively grep a source tree. If
> > that takes too long, I hit ^C and tag "git" in front of the command
> > line and re-run it. git then complains "error: unknown switch `r'"
> > because "git grep" is naturally recursive.
> >
> > Could we have "git grep -r" accept the argument for compatibility?
> > Other important grep switches like "-i" are compatible, adding -r
> > would improve usability.
>
> I don't have an opinion on this either way, it doesn't scratch my
> itch, but hey, why not. Here's a patch to implement it.
>
>  Documentation/git-grep.txt | 6 ++++++
>  builtin/grep.c             | 3 +++
>  t/t7810-grep.sh            | 8 ++++++++
>  3 files changed, 17 insertions(+)
>
> diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
> index a3049af1a3..a1aea8be4e 100644
> --- a/Documentation/git-grep.txt
> +++ b/Documentation/git-grep.txt
> @@ -290,6 +290,12 @@ providing this option will cause it to die.
>         Do not output matched lines; instead, exit with status 0 when
>         there is a match and with non-zero status when there isn't.
>
> +-r::
> +--recursive::
> +       This option does nothing. git-grep is always recursive. This
> +       noop option is provided for compatibility with the muscle
> +       memory of people used to grep(1).

git-grep is always file/tree recursive, but there is --recurse-submodules which is off by default. Instead of providing a short alias to a noop, we could use -r for submodules. (And if you happen to have no submodules, this is a noop for you)

Previous: Ævar Arnfjörð BjarmasonNext: Christoph Berg
Message 11 of 15 in “wishlist: git grep -r”
  1. Christoph BergSep 29, 2018
  2. grep: provide a noop --recursive optionÆvar Arnfjörð Bjarmason, Sep 29, 2018
  3. Duy NguyenSep 29, 2018
  4. Ævar Arnfjörð BjarmasonSep 29, 2018
  5. Duy NguyenSep 29, 2018
  6. Junio C HamanoSep 29, 2018
  7. Christoph BergSep 29, 2018
  8. René ScharfeOct 1, 2018
  9. Junio C HamanoOct 5, 2018
  10. Ævar Arnfjörð BjarmasonOct 5, 2018
  11. Stefan BellerOct 1, 2018
  12. Christoph BergOct 5, 2018
  13. Junio C HamanoOct 5, 2018
  14. Mischa POSLAWSKYOct 5, 2018
  15. Stefan BellerOct 5, 2018

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.