From: René Scharfe Date: Thu, 13 May 2010 20:37:10 GMT Subject: [PATCH 3/7] grep: --count over binary Message-ID: <4BEC62F6.9050602@lsrfire.ath.cx> In-Reply-To: <4BEC6211.2000309@lsrfire.ath.cx> The intent of showing the message "Binary file xyz matches" for binary files is to avoid annoying users by potentially messing up their terminals by printing control characters. In --count mode, this precaution isn't necessary. Display counts of matches if -c/--count was specified, even if -a was not given. GNU grep does the same. Signed-off-by: Rene Scharfe --- grep.c | 2 +- t/t7008-grep-binary.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletions(-) diff --git a/grep.c b/grep.c index 2a8e879..4b6c02e 100644 --- a/grep.c +++ b/grep.c @@ -802,7 +802,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name, switch (opt->binary) { case GREP_BINARY_DEFAULT: - if (buffer_is_binary(buf, size)) + if (!opt->count && buffer_is_binary(buf, size)) binary_match_only = 1; break; case GREP_BINARY_NOMATCH: diff --git a/t/t7008-grep-binary.sh b/t/t7008-grep-binary.sh index f9fd5e6..5449dd9 100755 --- a/t/t7008-grep-binary.sh +++ b/t/t7008-grep-binary.sh @@ -27,4 +27,10 @@ test_expect_success 'git grep -I ina a' ' test_cmp expect actual ' +test_expect_success 'git grep -c ina a' ' + echo a:1 >expect && + git grep -c ina a >actual && + test_cmp expect actual +' + test_done -- 1.7.1