summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 08303c3)
raw | patch | inline | side by side (parent: 08303c3)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Sun, 5 Jun 2011 15:24:25 +0000 (17:24 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 6 Jun 2011 01:15:26 +0000 (18:15 -0700) |
With --break, an empty line is printed between matches from different
files, increasing readability. This option is taken from ack
(http://betterthangrep.com/).
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
files, increasing readability. This option is taken from ack
(http://betterthangrep.com/).
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-grep.txt | patch | blob | history | |
builtin/grep.c | patch | blob | history | |
grep.c | patch | blob | history | |
grep.h | patch | blob | history | |
t/t7810-grep.sh | patch | blob | history |
index e150c77cffb5d082822bd65c7bfbeb1f431fc42f..dea7cad0c2a617530be8fa132d9e14abbd9c1273 100644 (file)
gives the default to color output.
Same as `--color=never`.
+--break::
+ Print an empty line between matches from different files.
+
-[ABC] <context>::
Show `context` trailing (`A` -- after), or leading (`B`
-- before), or both (`C` -- context) lines, and place a
diff --git a/builtin/grep.c b/builtin/grep.c
index 0d5a90b94b5153c17f8834455b8dbb7e252c5284..42bb87f5446b129c1db3f8e6c23e5a058c641266 100644 (file)
--- a/builtin/grep.c
+++ b/builtin/grep.c
OPT_BOOLEAN('c', "count", &opt.count,
"show the number of matches instead of matching lines"),
OPT__COLOR(&opt.color, "highlight matches"),
+ OPT_BOOLEAN(0, "break", &opt.file_break,
+ "print empty line between matches from different files"),
OPT_GROUP(""),
OPT_CALLBACK('C', NULL, &opt, "n",
"show <n> context lines before and after matches",
use_threads = 0;
if (use_threads) {
- if (opt.pre_context || opt.post_context)
+ if (opt.pre_context || opt.post_context || opt.file_break)
skip_first_line = 1;
start_threads(&opt);
}
index 3f15085d0e8bc82a0e098b9f3750d69bacc62590..b0b860a984d6516caf960fae847aea6272959c20 100644 (file)
--- a/grep.c
+++ b/grep.c
int rest = eol - bol;
char *line_color = NULL;
- if (opt->pre_context || opt->post_context) {
+ if (opt->file_break && opt->last_shown == 0) {
+ if (opt->show_hunk_mark)
+ opt->output(opt, "\n", 1);
+ } else if (opt->pre_context || opt->post_context) {
if (opt->last_shown == 0) {
if (opt->show_hunk_mark) {
output_color(opt, "--", 2, opt->color_sep);
if (!opt->output)
opt->output = std_output;
- if (opt->pre_context || opt->post_context) {
+ if (opt->pre_context || opt->post_context || opt->file_break) {
/* Show hunk marks, except for the first file. */
if (opt->last_shown)
opt->show_hunk_mark = 1;
index cd055cdfa8cac903382d592f1ec7e2a22bf7f897..638bee848d4fc36edb80e57fd8b8b550dc2c6e72 100644 (file)
--- a/grep.h
+++ b/grep.h
unsigned post_context;
unsigned last_shown;
int show_hunk_mark;
+ int file_break;
void *priv;
void (*output)(struct grep_opt *opt, const void *data, size_t size);
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 539a8fe6e9391f27d24cd8b85140209b60f10f39..f55793e3cb25c731215c82d1b68ebca097670037 100755 (executable)
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
test_cmp expected actual
'
+cat >expected <<EOF
+hello.c:int main(int argc, const char **argv)
+hello.c: /* char ?? */
+
+hello_world:Hello_world
+EOF
+
+test_expect_success 'grep --break' '
+ git grep --break -e char -e lo_w hello.c hello_world >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF
+hello.c:int main(int argc, const char **argv)
+hello.c-{
+--
+hello.c: /* char ?? */
+hello.c-}
+
+hello_world:Hello_world
+hello_world-HeLLo_world
+EOF
+
+test_expect_success 'grep --break with context' '
+ git grep --break -A1 -e char -e lo_w hello.c hello_world >actual &&
+ test_cmp expected actual
+'
+
test_done