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

Re: [PATCH] grep: provide pathspecs/patterns via file or stdin

From
Denton Liu <liu.denton@gmail.com>
Date
Nov 22, 2019, 18:52 UTC
Message-ID
<20191122185251.GA58965@generichostname>
In-Reply-To
<xmqqwobs7i6u.fsf@gitster-ct.c.googlers.com>
Hi Junio,
On Fri, Nov 22, 2019 at 11:34:17AM +0900, Junio C Hamano wrote:
Show 11 quoted lines
> Denton Liu <liu.denton@gmail.com> writes:
> 
> > The reason I ask is because (correct me if I'm wrong) a lot of other git
> > commands (like add, reset and checkout) don't seem to accept pathspecs
> > via stdin and could suffer the same problem. xargs seems like a more
> > general way of solving the problem of long command lines.
> 
> You contributors who are potentially throwing your own topics into
> the cauldron, please be paying a bit more attention to other topics
> already cooking in the pot.  I think am/pathspec-from-file wants to
> go in the general direction.

Interesting, I never caught this topic when it went over the list. I guess I should read your What's Cooking emails more thoroughly instead of just scanning for my own contributions.

Show 15 quoted lines
> 
> There are things "xargs" is sufficient, and there are things that
> absolutely requires a single invocation of "git".  "grep" is a bit
> of both.
> 
>     $ git grep -e "$pattern" -- A B C
> 
> (where A, B and C are hundreds) can be split into three independent
> invocations of "git grep" via "xargs", essentially running
> 
>     $ git grep -e "$pattern" -- A
>     $ git grep -e "$pattern" -- B
>     $ git grep -e "$pattern" -- C
> 
> independently.

In the above, I was talking about the new --pathspecs-file option in particular. So it looks like you agree with me that the new option doesn't supercede xargs?

Show 16 quoted lines
> 
> But
> 
>     $ git grep -e P1 -e P2 -e P3 -- A
> 
> (where each of "-e Pn" in reality may be "-e Pn1 -e Pn2 -e Pn3..."
> that has hundreds of patterns) cannot be split into separate
> invocations and keep the same meaning.
> 
>     $ git grep -e P1 -- A
>     $ git grep -e P2 -- A
>     $ git grep -e P3 -- A
> 
> may show the same lines, but (1) lines with both P1 and P2 would be
> shown duplicated, and (2) the order of the output would be different
> from a single invocation looking for all patterns at once.
We already have `-f` to handle this particular case, no?
Show 8 quoted lines
> 
> Needless to say, the ability to combine patterns with --all-match,
> --and, etc., and negate them would mean the list of patterns must be
> split (even when it makes sense to do so) at the right places.
> 
>     $ git grep -e P1 --and -e P2
> 
> cannot be split into two or more invocations, for example.

Anyway, thanks for going into detail about this. It makes things a lot more clear.

-Denton
Previous: Junio C HamanoNext: Emily Shaffer
Message 5 of 23 in “grep: provide pathspecs/patterns via file or stdin”
  1. grep: provide pathspecs/patterns via file or stdinEmily Shaffer, Nov 22, 2019
  2. Denton LiuNov 22, 2019
  3. Junio C HamanoNov 22, 2019
  4. Junio C HamanoNov 22, 2019
  5. Denton LiuNov 22, 2019
  6. Emily ShafferNov 22, 2019
  7. Emily ShafferNov 22, 2019
  8. Junio C HamanoNov 23, 2019
  9. Junio C HamanoNov 22, 2019
  10. grep: support the --pathspec-from-file optionEmily Shaffer, Dec 4, 2019
  11. Denton LiuDec 4, 2019
  12. Junio C HamanoDec 4, 2019
  13. Junio C HamanoDec 4, 2019
  14. Emily ShafferDec 13, 2019
  15. Alexandr MiloslavskiyDec 5, 2019
  16. Emily ShafferDec 13, 2019
  17. Johannes SchindelinDec 6, 2019
  18. SZEDER GáborDec 6, 2019
  19. grep: support the --pathspec-from-file optionEmily Shaffer, Dec 13, 2019
  20. Alexandr MiloslavskiyDec 13, 2019
  21. Junio C HamanoDec 13, 2019
  22. Alexandr MiloslavskiyDec 13, 2019
  23. Emily ShafferDec 17, 2019

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.