aboutsummaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2011-06-05 17:24:36 +0200
committerJunio C Hamano <gitster@pobox.com>2011-06-05 18:15:27 -0700
commit1d84f72ef1dee1f851e11a6d92e8ab3f1979b2a2 (patch)
treea84d8f3a9ee7118fd2ec26dc1c5c9041541187e3 /grep.c
parenta8f0e7649eba3ce78e1f09fc4dcbb2c3fcc3d866 (diff)
downloadgit-1d84f72ef1dee1f851e11a6d92e8ab3f1979b2a2.tar.gz
git-1d84f72ef1dee1f851e11a6d92e8ab3f1979b2a2.tar.xz
grep: add --heading
With --heading, the filename is printed once before matches from that file instead of at the start of each line, giving more screen space to the actual search results. This option is taken from ack (http://betterthangrep.com/). And now git grep can dress up like it: $ git config alias.ack "grep --break --heading --line-number" $ git ack -e --heading Documentation/git-grep.txt 154:--heading:: t/t7810-grep.sh 785:test_expect_success 'grep --heading' ' 786: git grep --heading -e char -e lo_w hello.c hello_world >actual && 808: git grep --break --heading -n --color \ Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/grep.c b/grep.c
index b0b860a98..04e9ba4ec 100644
--- a/grep.c
+++ b/grep.c
@@ -735,9 +735,13 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
opt->output(opt, "\n", 1);
}
}
+ if (opt->heading && opt->last_shown == 0) {
+ output_color(opt, name, strlen(name), opt->color_filename);
+ opt->output(opt, "\n", 1);
+ }
opt->last_shown = lno;
- if (opt->pathname) {
+ if (!opt->heading && opt->pathname) {
output_color(opt, name, strlen(name), opt->color_filename);
output_sep(opt, sign);
}