Jonathan Nieder [off-list ref] writes:
quoted hunk
diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index 8fdd8e1..d89ec32 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]
+ [(-O | --open-files-in-pager) [<pager>]]
[-z | --null]
[-c | --count] [--all-match] [-q | --quiet]
[--max-depth <depth>]
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?
quoted hunk
diff --git a/builtin/grep.c b/builtin/grep.c
index 1e8b946..f32fbbc 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -828,7 +828,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
int cached = 0;
int seen_dashdash = 0;
int external_grep_allowed__ignored;
- int show_in_pager = 0;
+ 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? IOW, if the patch were:
+ const char *show_in_pager = NULL, *default_pager = "dummy";
+ const char *another_dummy = "dummy";
could another_dummy and default_pager start out with the same value?
This is just out of curiosity and does not affect correctness of the code,
but I am wondering...
quoted
- [-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?
The latter.
quoted
+ 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? IOW, if the patch were:
quoted
+ const char *show_in_pager = NULL, *default_pager = "dummy";
+ const char *another_dummy = "dummy";
could another_dummy and default_pager start out with the same value?
In the same file, the compiler will do it already today. In another
file, no (except if it does link-time optimization of course).
Paolo
Junio C Hamano wrote:
Jonathan Nieder [off-list ref] writes:
quoted
- [-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.
quoted
+ 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 [off-list ref]
Signed-off-by: Jonathan Nieder <redacted>
---
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