Merge branch 'rs/threaded-grep-context'
* rs/threaded-grep-context: grep: enable threading for context line printing Conflicts: grep.c
This commit is contained in:
commit
07b838f087
@ -96,6 +96,9 @@ static pthread_cond_t cond_write;
|
|||||||
/* Signalled when we are finished with everything. */
|
/* Signalled when we are finished with everything. */
|
||||||
static pthread_cond_t cond_result;
|
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)
|
static void add_work(enum work_type type, char *name, void *id)
|
||||||
{
|
{
|
||||||
grep_lock();
|
grep_lock();
|
||||||
@ -159,7 +162,12 @@ static void work_done(struct work_item *w)
|
|||||||
for(; todo[todo_done].done && todo_done != todo_start;
|
for(; todo[todo_done].done && todo_done != todo_start;
|
||||||
todo_done = (todo_done+1) % ARRAY_SIZE(todo)) {
|
todo_done = (todo_done+1) % ARRAY_SIZE(todo)) {
|
||||||
w = &todo[todo_done];
|
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->name);
|
||||||
free(w->identifier);
|
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))
|
if (online_cpus() == 1 || !grep_threads_ok(&opt))
|
||||||
use_threads = 0;
|
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);
|
start_threads(&opt);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
use_threads = 0;
|
use_threads = 0;
|
||||||
#endif
|
#endif
|
||||||
|
18
grep.c
18
grep.c
@ -570,8 +570,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
|
|||||||
if (opt->show_hunk_mark) {
|
if (opt->show_hunk_mark) {
|
||||||
output_color(opt, "--", 2, opt->color_sep);
|
output_color(opt, "--", 2, opt->color_sep);
|
||||||
opt->output(opt, "\n", 1);
|
opt->output(opt, "\n", 1);
|
||||||
} else
|
}
|
||||||
opt->show_hunk_mark = 1;
|
|
||||||
} else if (lno > opt->last_shown + 1) {
|
} else if (lno > opt->last_shown + 1) {
|
||||||
output_color(opt, "--", 2, opt->color_sep);
|
output_color(opt, "--", 2, opt->color_sep);
|
||||||
opt->output(opt, "\n", 1);
|
opt->output(opt, "\n", 1);
|
||||||
@ -772,14 +771,6 @@ int grep_threads_ok(const struct grep_opt *opt)
|
|||||||
!opt->name_only)
|
!opt->name_only)
|
||||||
return 0;
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,11 +792,14 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
|
|||||||
enum grep_context ctx = GREP_CONTEXT_HEAD;
|
enum grep_context ctx = GREP_CONTEXT_HEAD;
|
||||||
xdemitconf_t xecfg;
|
xdemitconf_t xecfg;
|
||||||
|
|
||||||
opt->last_shown = 0;
|
|
||||||
|
|
||||||
if (!opt->output)
|
if (!opt->output)
|
||||||
opt->output = std_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)) {
|
if (buffer_is_binary(buf, size)) {
|
||||||
switch (opt->binary) {
|
switch (opt->binary) {
|
||||||
case GREP_BINARY_DEFAULT:
|
case GREP_BINARY_DEFAULT:
|
||||||
|
Loading…
Reference in New Issue
Block a user