{"thread":{"id":"38848","subject":"[PATCH/RFC] grep: fix \"--quiet\" overwriting current output","startedAt":"2015-03-18T18:00:13Z","lastAt":"2015-03-18T19:01:08Z","messageCount":2,"participants":["Wilhelm Schuermann","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"257967","messageId":"1426701613-12533-1-git-send-email-wimschuermann@googlemail.com","threadId":"38848","inReplyTo":null,"subject":"[PATCH/RFC] grep: fix \"--quiet\" overwriting current output","fromName":"Wilhelm Schuermann","fromEmail":"wimschuermann@googlemail.com","sentAt":"2015-03-18T18:00:13Z","receivedAt":"2015-03-18T18:00:13Z","isPatch":true,"sender":{"key":"wimschuermann@googlemail.com","avatar":null},"body":"When grep is called with the --quiet option, the pager is initialized\ndespite not being used.  When the pager is \"less\", anything output by\nprevious commands and not ended with a newline is overwritten.\n\n$ echo -n aaa; echo bbb\naaabbb\n$ echo -n aaa; git grep -q foo; echo bbb\nbbb\n\nThis can be worked around, for example, by making sure STDOUT is not a\nTTY or more directly by setting git's pager to \"cat\":\n\n$ echo -n aaa; git grep -q foo > /dev/null; echo bbb\naaabbb\n$ echo -n aaa; PAGER=cat git grep -q foo; echo bbb\naaabbb\n\nThis patch prevents calling the pager in the first place, saving an\nunnecessary fork() call.\n\nSigned-off-by: Wilhelm Schuermann <wimschuermann@googlemail.com>\n---\n builtin/grep.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex e77f7cf..fe7b9fd 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -885,7 +885,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\tif (!show_in_pager)\n+\tif (!show_in_pager && !opt.status_only)\n \t\tsetup_pager();\n \n \tif (!use_index && (untracked || cached))\n-- \n2.3.3.dirty\n"},{"id":"257971","messageId":"20150318190107.GB650@peff.net","threadId":"38848","inReplyTo":"1426701613-12533-1-git-send-email-wimschuermann@googlemail.com","subject":"Re: [PATCH/RFC] grep: fix \"--quiet\" overwriting current output","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-03-18T19:01:08Z","receivedAt":"2015-03-18T19:01:08Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Mar 18, 2015 at 07:00:13PM +0100, Wilhelm Schuermann wrote:\n\n> When grep is called with the --quiet option, the pager is initialized\n> despite not being used.  When the pager is \"less\", anything output by\n> previous commands and not ended with a newline is overwritten.\n> [...]\n> This patch prevents calling the pager in the first place, saving an\n> unnecessary fork() call.\n\nThanks, I think this makes sense. We do a similar thing for \"git diff\n--quiet\". If you do not set \"-F\" in your $LESS variable, it is even more\nannoying. E.g., with:\n\n  if git grep -q foo; then\n    : do something\n  fi\n\nwhich will pause, waiting for the user to hit 'q'.\n\n> diff --git a/builtin/grep.c b/builtin/grep.c\n> index e77f7cf..fe7b9fd 100644\n> --- a/builtin/grep.c\n> +++ b/builtin/grep.c\n> @@ -885,7 +885,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n>  \t\t}\n>  \t}\n>  \n> -\tif (!show_in_pager)\n> +\tif (!show_in_pager && !opt.status_only)\n>  \t\tsetup_pager();\n\nPatch looks obviously correct.\n\n-Peff\n"}]}