aboutsummaryrefslogtreecommitdiff
path: root/builtin/grep.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-04-03 12:28:39 -0700
committerJunio C Hamano <gitster@pobox.com>2010-04-03 12:28:39 -0700
commit07b838f087a1535e387d5d4a1414b2b545b73265 (patch)
tree8779dd5e4854e5dd9c3dbe09daa80eea0ed0c7da /builtin/grep.c
parentd718dd0732c125306670d61880652f1b596a0c3e (diff)
parent431d6e7bc85f693fe49a04142a8ab4d2d72b0257 (diff)
downloadgit-07b838f087a1535e387d5d4a1414b2b545b73265.tar.gz
git-07b838f087a1535e387d5d4a1414b2b545b73265.tar.xz
Merge branch 'rs/threaded-grep-context'
* rs/threaded-grep-context: grep: enable threading for context line printing Conflicts: grep.c
Diffstat (limited to 'builtin/grep.c')
-rw-r--r--builtin/grep.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index 9d30ddb28..8e928e217 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -96,6 +96,9 @@ static pthread_cond_t cond_write;
/* Signalled when we are finished with everything. */
static pthread_cond_t cond_result;
+static int print_hunk_marks_between_files;
+static int printed_something;
+
static void add_work(enum work_type type, char *name, void *id)
{
grep_lock();
@@ -159,7 +162,12 @@ static void work_done(struct work_item *w)
for(; todo[todo_done].done && todo_done != todo_start;
todo_done = (todo_done+1) % ARRAY_SIZE(todo)) {
w = &todo[todo_done];
- write_or_die(1, w->out.buf, w->out.len);
+ if (w->out.len) {
+ if (print_hunk_marks_between_files && printed_something)
+ write_or_die(1, "--\n", 3);
+ write_or_die(1, w->out.buf, w->out.len);
+ printed_something = 1;
+ }
free(w->name);
free(w->identifier);
}
@@ -946,8 +954,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
if (online_cpus() == 1 || !grep_threads_ok(&opt))
use_threads = 0;
- if (use_threads)
+ if (use_threads) {
+ if (opt.pre_context || opt.post_context)
+ print_hunk_marks_between_files = 1;
start_threads(&opt);
+ }
#else
use_threads = 0;
#endif