grep: --name-only over binary
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
May 22, 2010 at 23:30 UTC
321ffcc0556a94c461ac84667b35494c193804ec
2 files changed
+10
-4
grep.c
+4
-4
@@ -873,6 +873,10 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
873
count++;
874
if (opt->status_only)
875
return 1;
876
+ if (opt->name_only) {
877
+ show_name(opt, name);
878
+ return 1;
879
+ }
880
if (opt->count)
881
goto next_line;
882
if (binary_match_only) {
@@ -882,10 +886,6 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
886
opt->output(opt, " matches\n", 9);
887
return 1;
888
}
885
- if (opt->name_only) {
886
- show_name(opt, name);
887
- return 1;
888
- }
889
/* Hit at this line. If we haven't shown the
890
* pre-context lines, we would need to show them.
891
*/
t/t7008-grep-binary.sh
+6
@@ -33,6 +33,12 @@ test_expect_success 'git grep -c ina a' '
33
test_cmp expect actual
34
'
35
36
+test_expect_success 'git grep -l ina a' '
37
+ echo a >expect &&
38
+ git grep -l ina a >actual &&
39
+ test_cmp expect actual
40
+'
41
+
42
test_expect_success 'git grep -L bar a' '
43
echo a >expect &&
44
git grep -L bar a >actual &&