[PATCH 4/8] grep: --name-only over binary

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: René Scharfe
Date: Saturday, May 22, 2010 - 2:30 pm

As with the option -c/--count, git grep with the option -l/--name-only
should work the same with binary files as with text files because
there is no danger of messing up the terminal with control characters
from the contents of matching files.  GNU grep does the same.

Move the check for ->name_only before the one for binary_match_only,
thus making the latter irrelevant for git grep -l.

Reported-by: Dmitry Potapov <dpotapov@gmail.com>
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 grep.c                 |    8 ++++----
 t/t7008-grep-binary.sh |    6 ++++++
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/grep.c b/grep.c
index 35c18b7..22639cd 100644
--- a/grep.c
+++ b/grep.c
@@ -873,6 +873,10 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
 			count++;
 			if (opt->status_only)
 				return 1;
+			if (opt->name_only) {
+				show_name(opt, name);
+				return 1;
+			}
 			if (opt->count)
 				goto next_line;
 			if (binary_match_only) {
@@ -882,10 +886,6 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
 				opt->output(opt, " matches\n", 9);
 				return 1;
 			}
-			if (opt->name_only) {
-				show_name(opt, name);
-				return 1;
-			}
 			/* Hit at this line.  If we haven't shown the
 			 * pre-context lines, we would need to show them.
 			 */
diff --git a/t/t7008-grep-binary.sh b/t/t7008-grep-binary.sh
index 91970ea..4a12d97 100755
--- a/t/t7008-grep-binary.sh
+++ b/t/t7008-grep-binary.sh
@@ -33,6 +33,12 @@ test_expect_success 'git grep -c ina a' '
 	test_cmp expect actual
 '
 
+test_expect_success 'git grep -l ina a' '
+	echo a >expect &&
+	git grep -l ina a >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'git grep -L bar a' '
 	echo a >expect &&
 	git grep -L bar a >actual &&
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
What's cooking extra, Junio C Hamano, (Wed May 19, 7:33 am)
Re: What's cooking extra, A Large Angry SCM, (Wed May 19, 8:12 am)
Re: What's cooking extra, Finn Arne Gangstad, (Wed May 19, 10:06 am)
Re: What's cooking extra, Eyvind Bernhardsen, (Wed May 19, 1:09 pm)
Re: What's cooking extra, Ævar Arnfjörð Bjarmason, (Fri May 21, 9:16 am)
Re: What's cooking extra, Clemens Buchacher, (Sat May 22, 6:09 am)
Re: What's cooking extra, Eyvind Bernhardsen, (Sat May 22, 12:42 pm)
Re: What's cooking extra, René Scharfe, (Sat May 22, 2:24 pm)
[PATCH 3/8] grep: --count over binary, René Scharfe, (Sat May 22, 2:29 pm)
[PATCH 4/8] grep: --name-only over binary, René Scharfe, (Sat May 22, 2:30 pm)
[PATCH 5/8] grep: use memmem() for fixed string search, René Scharfe, (Sat May 22, 2:32 pm)
Re: What's cooking extra, Clemens Buchacher, (Sat May 22, 3:27 pm)
Re: What's cooking extra, Eyvind Bernhardsen, (Sun May 23, 3:36 am)
Re: What's cooking extra, Clemens Buchacher, (Sun May 23, 4:51 am)
Re: What's cooking extra, Eyvind Bernhardsen, (Sun May 23, 5:53 am)
Re: What's cooking extra, Ævar Arnfjörð Bjarmason, (Sun May 23, 6:26 am)
Re: What's cooking extra, Clemens Buchacher, (Mon May 24, 2:49 am)
Re: What's cooking extra, Dmitry Potapov, (Mon May 24, 5:12 am)
Re: What's cooking extra, Erik Faye-Lund, (Mon May 24, 5:22 am)
Re: What's cooking extra, Dmitry Potapov, (Mon May 24, 5:42 am)
Re: What's cooking extra, Dmitry Potapov, (Mon May 24, 5:47 am)
Re: What's cooking extra, Eyvind Bernhardsen, (Mon May 24, 1:45 pm)
Re: What's cooking extra, Clemens Buchacher, (Mon May 24, 1:56 pm)
Re: What's cooking extra, Eyvind Bernhardsen, (Mon May 24, 2:09 pm)
Re: What's cooking extra, Eyvind Bernhardsen, (Mon May 24, 2:11 pm)
Re: What's cooking extra, Clemens Buchacher, (Mon May 24, 3:11 pm)
Re: What's cooking extra, Eyvind Bernhardsen, (Mon May 24, 11:41 pm)
Re: What's cooking extra, Anthony Youngman, (Tue May 25, 1:27 am)
Re: What's cooking extra, Clemens Buchacher, (Tue May 25, 1:33 am)
Re: What's cooking extra, Eyvind Bernhardsen, (Mon Jun 7, 12:55 pm)