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

git-grep: option parsing conflicts with prefix-dash searches

From
JEJan Engelhardt <jengelh@medozas.de>
Date
Feb 5, 2010, 23:09 UTC
Message-ID
<alpine.LSU.2.01.1002052351060.30204@obet.zrqbmnf.qr>
Greetings.

Just about now I wanted to grep for accesses of a particular struct member. Needless to say that it was not a very amusing experience. I would expect that (1) probably fails:

(1)	$ git grep '->cnt' net/ipv4/netfilter/
	error: unknown switch `>'

So far so good, seems reasonable and matches what I would expect from most other userspace tools. So let's add -- to terminate the option list:

(2)	$ git grep -- '->cnt' net/ipv4/netfilter/
	fatal: bad flag '->cnt' used after filename

*bzzt*. This does not match typical behavior. Let alone that "--" is not a filename.

What works is (3).
(3)	$ git grep -- -- '->cnt' net/ipv4/netfilter/

But it almost looks like Morse code. Or Perl. Imagine I were to approxmiately search for all options in iptables's in-code help texts:

	git grep -- -- -- .

I think that overloading "--" was a bad choice. The option parser has many more awkward behavior, such as not allowing to bundle most options (`git log -z -p` vs. `git log -zp`) yet forcing it on other options (`git log -Spattern` vs `git log -S pattern`). The use of historic counts (cf. `git log -30` and `tail -30`) compared to a more modern `tail -n30`) also prohibits using many standard parsers (most notably getopt(3)), as they would recognize that as -3 -0.

As I said, it's a mess. And I know not whether any code can convince the "but we need to watch compatibility"-sayers, because this would definitely be a flag change.

Next: Jan Engelhardt
Message 1 of 12 in “git-grep: option parsing conflicts with prefix-dash searches”
  1. Jan EngelhardtFeb 5, 2010
  2. Jan EngelhardtFeb 5, 2010
  3. Santi BéjarFeb 5, 2010
  4. Junio C HamanoFeb 5, 2010
  5. Junio C HamanoFeb 5, 2010
  6. Jeff KingFeb 6, 2010
  7. Junio C HamanoFeb 6, 2010
  8. Miles BaderFeb 6, 2010
  9. Jeff KingFeb 6, 2010
  10. Junio C HamanoFeb 6, 2010
  11. Jeff KingFeb 7, 2010
  12. Junio C HamanoFeb 8, 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.