git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH/RFC] grep: fix "--quiet" overwriting current output
@ 2015-03-18 18:00 Wilhelm Schuermann
  2015-03-18 19:01 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: Wilhelm Schuermann @ 2015-03-18 18:00 UTC (permalink / raw)
  To: git; +Cc: Wilhelm Schuermann

When grep is called with the --quiet option, the pager is initialized
despite not being used.  When the pager is "less", anything output by
previous commands and not ended with a newline is overwritten.

$ echo -n aaa; echo bbb
aaabbb
$ echo -n aaa; git grep -q foo; echo bbb
bbb

This can be worked around, for example, by making sure STDOUT is not a
TTY or more directly by setting git's pager to "cat":

$ echo -n aaa; git grep -q foo > /dev/null; echo bbb
aaabbb
$ echo -n aaa; PAGER=cat git grep -q foo; echo bbb
aaabbb

This patch prevents calling the pager in the first place, saving an
unnecessary fork() call.

Signed-off-by: Wilhelm Schuermann <wimschuermann@googlemail.com>
---
 builtin/grep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/grep.c b/builtin/grep.c
index e77f7cf..fe7b9fd 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -885,7 +885,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 		}
 	}
 
-	if (!show_in_pager)
+	if (!show_in_pager && !opt.status_only)
 		setup_pager();
 
 	if (!use_index && (untracked || cached))
-- 
2.3.3.dirty

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH/RFC] grep: fix "--quiet" overwriting current output
  2015-03-18 18:00 [PATCH/RFC] grep: fix "--quiet" overwriting current output Wilhelm Schuermann
@ 2015-03-18 19:01 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2015-03-18 19:01 UTC (permalink / raw)
  To: Wilhelm Schuermann; +Cc: git

On Wed, Mar 18, 2015 at 07:00:13PM +0100, Wilhelm Schuermann wrote:

> When grep is called with the --quiet option, the pager is initialized
> despite not being used.  When the pager is "less", anything output by
> previous commands and not ended with a newline is overwritten.
> [...]
> This patch prevents calling the pager in the first place, saving an
> unnecessary fork() call.

Thanks, I think this makes sense. We do a similar thing for "git diff
--quiet". If you do not set "-F" in your $LESS variable, it is even more
annoying. E.g., with:

  if git grep -q foo; then
    : do something
  fi

which will pause, waiting for the user to hit 'q'.

> diff --git a/builtin/grep.c b/builtin/grep.c
> index e77f7cf..fe7b9fd 100644
> --- a/builtin/grep.c
> +++ b/builtin/grep.c
> @@ -885,7 +885,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
>  		}
>  	}
>  
> -	if (!show_in_pager)
> +	if (!show_in_pager && !opt.status_only)
>  		setup_pager();

Patch looks obviously correct.

-Peff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-18 19:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-18 18:00 [PATCH/RFC] grep: fix "--quiet" overwriting current output Wilhelm Schuermann
2015-03-18 19:01 ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).