X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin%2Fgrep.c;h=b194ea3cea531f3a6c81d6d27b5b3028641ba9ce;hb=91788cf26e86c5bfb54431e7af34783d4c71dda0;hp=9d30ddb28df16f834c9fbb3bf6ba8cc172a502b3;hpb=a59cb82a2f77c510d62d7d27f197451545f386ab;p=git.git diff --git a/builtin/grep.c b/builtin/grep.c index 9d30ddb28..b194ea3ce 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -17,8 +17,8 @@ #include "dir.h" #ifndef NO_PTHREADS -#include "thread-utils.h" #include +#include "thread-utils.h" #endif static char const * const grep_usage[] = { @@ -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