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

Re: [PATCH 4/4] grep -O: allow optional argument specifying the pager (or editor)

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jun 14, 2010, 06:31 UTC
Message-ID
<20100614063125.GA2006@burratino>
In-Reply-To
<7vvd9mevqy.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
> Jonathan Nieder <jrnieder@gmail.com> writes:
>> -	   [-O | --open-files-in-pager]
>> +	   [(-O | --open-files-in-pager) [<pager>]]
[...]
>
> Hmm, does "git grep -e Heh -O frotz" look for Heh and show in the frotz
> pager, or does it look for Heh in paths under frotz/ directory and show
> hits in the default pager?

As Paolo mentioned, it is the latter. Patch for squashing is below.

Show 6 quoted lines
>> +	const char *show_in_pager = NULL, *default_pager = "dummy";
>
> If there were another instance of constant string "dummy" elsewhere in the
> program, is a clever compiler-linker combo allowed to optimize memory use
> by allocating one instance of such a string and pointing default_pager
> pointer to it?

For a moment, you had me worried: would an (insane) compiler be allowed to intern strings that appear as arguments, making argv[i] actually compare equal to default_pager?

Luckily, the answer is no, because the strings pointed to in argv are guaranteed to be modifiable (see: Execution environments → Hosted environment → Program startup).

-- 8< --
Subject: grep -O: do not advertize non-"sticked" form in documentation

To avoid ambiguity in option parsing, the -O option will only take an argument if it is stuck to the option like -Ovi or --open-files-in-pager=vim. The un-sticked form -O vi means to search paths under 'vi' and show hits in the default pager.

Noticed-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 Documentation/git-grep.txt |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index d89ec32..0e12fe4 100644
--- a/Documentation/git-grep.txt
+++ b/Documentation/git-grep.txt
@@ -14,7 +14,7 @@ SYNOPSIS
 	   [-E | --extended-regexp] [-G | --basic-regexp]
 	   [-F | --fixed-strings] [-n]
 	   [-l | --files-with-matches] [-L | --files-without-match]
-	   [(-O | --open-files-in-pager) [<pager>]]
+	   [-O[<pager>] | --open-files-in-pager[=<pager>]]
 	   [-z | --null]
 	   [-c | --count] [--all-match] [-q | --quiet]
 	   [--max-depth <depth>]
@@ -106,7 +106,7 @@ OPTIONS
 	synonym for `--files-with-matches`.
 
--O [<pager>]::
---open-files-in-pager [<pager>]::
+-O[<pager>]::
+--open-files-in-pager=[<pager>]::
 	Open the matching files in the pager (not the output of 'grep').
 	If the pager happens to be "less" or "vi", and the user
 	specified only one pattern, the first file is positioned at
-- 
1.7.1.246.g398e5.dirty
Previous: Paolo BonziniNext: Johannes Schindelin
Message 16 of 20 in “Teach 'git grep' about --open-files-in-pager=[<pager>]”
  1. 0/2 Teach 'git grep' about --open-files-in-pager=[<pager>]Jonathan Nieder, Jun 5, 2010
  2. 1/2 grep: Add the option '--open-files-in-pager'Jonathan Nieder, Jun 5, 2010
  3. Jonathan NiederJun 5, 2010
  4. 2/2 grep -O: allow optional argument specifying the pager (or editor)Jonathan Nieder, Jun 5, 2010
  5. Johannes SchindelinJun 5, 2010
  6. Jonathan NiederJun 12, 2010
  7. Johannes SchindelinJun 12, 2010
  8. 0/4 Teach 'git grep' about --open-files-in-pager=[<pager>]Jonathan Nieder, Jun 12, 2010
  9. 1/4 grep: refactor grep_objects loop into its own functionJonathan Nieder, Jun 12, 2010
  10. 2/4 Unify code paths of threaded grepsJonathan Nieder, Jun 12, 2010
  11. 3/4 grep: Add the option '--open-files-in-pager'Jonathan Nieder, Jun 12, 2010
  12. 4/4 grep -O: allow optional argument specifying the pager (or editor)Jonathan Nieder, Jun 12, 2010
  13. Paolo BonziniJun 12, 2010
  14. Junio C HamanoJun 13, 2010
  15. Paolo BonziniJun 13, 2010
  16. Jonathan NiederJun 14, 2010
  17. Johannes SchindelinJun 12, 2010
  18. Jonathan NiederJun 12, 2010
  19. Paolo BonziniJun 12, 2010
  20. Jonathan NiederJun 12, 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.