git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wilhelm Schuermann <wimschuermann@googlemail.com>
To: git@vger.kernel.org
Cc: Wilhelm Schuermann <wimschuermann@googlemail.com>
Subject: [PATCH/RFC] grep: fix "--quiet" overwriting current output
Date: Wed, 18 Mar 2015 19:00:13 +0100	[thread overview]
Message-ID: <1426701613-12533-1-git-send-email-wimschuermann@googlemail.com> (raw)

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

             reply	other threads:[~2015-03-18 18:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-18 18:00 Wilhelm Schuermann [this message]
2015-03-18 19:01 ` [PATCH/RFC] grep: fix "--quiet" overwriting current output Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426701613-12533-1-git-send-email-wimschuermann@googlemail.com \
    --to=wimschuermann@googlemail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).