Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
grep: support -h (no header) with --count
author
René Scharfe
<l.s.r@web.de>
Tue, 11 Mar 2014 21:15:49 +0000
(22:15 +0100)
committer
Junio C Hamano
<gitster@pobox.com>
Tue, 11 Mar 2014 22:05:28 +0000
(15:05 -0700)
Suppress printing the header (filename) with -h even if in -c/--count
mode. GNU grep and OpenBSD's grep do the same.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
grep.c
patch
|
blob
|
history
t/t7810-grep.sh
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
9afad7a
)
diff --git
a/grep.c
b/grep.c
index c668034739258d0cd1e7108357da80d44891221f..94f7290eb764119bfdca8d0497730f082731a24e 100644
(file)
--- a/
grep.c
+++ b/
grep.c
@@
-1562,8
+1562,11
@@
static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
*/
if (opt->count && count) {
char buf[32];
*/
if (opt->count && count) {
char buf[32];
- output_color(opt, gs->name, strlen(gs->name), opt->color_filename);
- output_sep(opt, ':');
+ if (opt->pathname) {
+ output_color(opt, gs->name, strlen(gs->name),
+ opt->color_filename);
+ output_sep(opt, ':');
+ }
snprintf(buf, sizeof(buf), "%u\n", count);
opt->output(opt, buf, strlen(buf));
return 1;
snprintf(buf, sizeof(buf), "%u\n", count);
opt->output(opt, buf, strlen(buf));
return 1;
diff --git
a/t/t7810-grep.sh
b/t/t7810-grep.sh
index 46aaebc475e589babb49780889e65858ca5d2cf0..63b303924307ad3a1d0658ec3b69a3ebf9e5670e 100755
(executable)
--- a/
t/t7810-grep.sh
+++ b/
t/t7810-grep.sh
@@
-328,6
+328,18
@@
do
grep "a+b*c" $H ab >actual &&
test_cmp expected actual
'
grep "a+b*c" $H ab >actual &&
test_cmp expected actual
'
+
+ test_expect_success "grep --count $L" '
+ echo ${HC}ab:3 >expected &&
+ git grep --count -e b $H -- ab >actual &&
+ test_cmp expected actual
+ '
+
+ test_expect_success "grep --count -h $L" '
+ echo 3 >expected &&
+ git grep --count -h -e b $H -- ab >actual &&
+ test_cmp expected actual
+ '
done
cat >expected <<EOF
done
cat >expected <<EOF