diff options
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | 2010-03-15 17:21:10 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-03-15 15:26:35 -0700 |
commit | 431d6e7bc85f693fe49a04142a8ab4d2d72b0257 (patch) | |
tree | dbe24237e8e38fddb6c24f01f7ec1d3dc025b347 /grep.c | |
parent | c24138bc55bcbbde2ea8601c504752e5a39f53f2 (diff) | |
download | git-431d6e7bc85f693fe49a04142a8ab4d2d72b0257.tar.gz |
grep: enable threading for context line printing
If context lines are to be printed, grep separates them with hunk marks
("--\n"). These marks are printed between matches from different files,
too. They are not printed before the first file, though.
Threading was disabled when context line printing was enabled because
avoiding to print the mark before the first line was an unsolved
synchronisation problem. This patch separates the code for printing
hunk marks for the threaded and the unthreaded case, allowing threading
to be turned on together with the common -ABC options.
->show_hunk_mark, which controls printing of hunk marks between files in
show_line(), is now set in grep_buffer_1(), but only if some results
have already been printed and threading is disabled. The threaded case
is handled in work_done().
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.c | 17 |
1 files changed, 5 insertions, 12 deletions
@@ -551,8 +551,6 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol, if (opt->last_shown == 0) { if (opt->show_hunk_mark) opt->output(opt, "--\n", 3); - else - opt->show_hunk_mark = 1; } else if (lno > opt->last_shown + 1) opt->output(opt, "--\n", 3); } @@ -750,14 +748,6 @@ int grep_threads_ok(const struct grep_opt *opt) !opt->name_only) return 0; - /* If we are showing hunk marks, we should not do it for the - * first match. The synchronization problem we get for this - * constraint is not yet solved, so we disable threading in - * this case. - */ - if (opt->pre_context || opt->post_context) - return 0; - return 1; } @@ -779,11 +769,14 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name, enum grep_context ctx = GREP_CONTEXT_HEAD; xdemitconf_t xecfg; - opt->last_shown = 0; - if (!opt->output) opt->output = std_output; + if (opt->last_shown && (opt->pre_context || opt->post_context) && + opt->output == std_output) + opt->show_hunk_mark = 1; + opt->last_shown = 0; + if (buffer_is_binary(buf, size)) { switch (opt->binary) { case GREP_BINARY_DEFAULT: |