Skip to content

Commit ff8b7e6

Browse files
committed
Merge branch 'bw/grep-recurse-submodules'
Build fix for NO_PTHREADS build. * bw/grep-recurse-submodules: grep: fix builds with with no thread support grep: set default output method
2 parents e0ef7fe + 2225e1e commit ff8b7e6

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

builtin/grep.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ static int grep_submodule_launch(struct grep_opt *opt,
538538
int status, i;
539539
const char *end_of_base;
540540
const char *name;
541-
struct work_item *w = opt->output_priv;
541+
struct strbuf child_output = STRBUF_INIT;
542542

543543
end_of_base = strchr(gs->name, ':');
544544
if (gs->identifier && end_of_base)
@@ -593,14 +593,16 @@ static int grep_submodule_launch(struct grep_opt *opt,
593593
* child process. A '0' indicates a hit, a '1' indicates no hit and
594594
* anything else is an error.
595595
*/
596-
status = capture_command(&cp, &w->out, 0);
596+
status = capture_command(&cp, &child_output, 0);
597597
if (status && (status != 1)) {
598598
/* flush the buffer */
599-
write_or_die(1, w->out.buf, w->out.len);
599+
write_or_die(1, child_output.buf, child_output.len);
600600
die("process for submodule '%s' failed with exit code: %d",
601601
gs->name, status);
602602
}
603603

604+
opt->output(opt, child_output.buf, child_output.len);
605+
strbuf_release(&child_output);
604606
/* invert the return code to make a hit equal to 1 */
605607
return !status;
606608
}
@@ -641,19 +643,14 @@ static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1,
641643
} else
642644
#endif
643645
{
644-
struct work_item w;
646+
struct grep_source gs;
645647
int hit;
646648

647-
grep_source_init(&w.source, GREP_SOURCE_SUBMODULE,
649+
grep_source_init(&gs, GREP_SOURCE_SUBMODULE,
648650
filename, path, sha1);
649-
strbuf_init(&w.out, 0);
650-
opt->output_priv = &w;
651-
hit = grep_submodule_launch(opt, &w.source);
651+
hit = grep_submodule_launch(opt, &gs);
652652

653-
write_or_die(1, w.out.buf, w.out.len);
654-
655-
grep_source_clear(&w.source);
656-
strbuf_release(&w.out);
653+
grep_source_clear(&gs);
657654
return hit;
658655
}
659656
}

grep.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ static int grep_source_is_binary(struct grep_source *gs);
1212

1313
static struct grep_opt grep_defaults;
1414

15+
static void std_output(struct grep_opt *opt, const void *buf, size_t size)
16+
{
17+
fwrite(buf, size, 1, stdout);
18+
}
19+
1520
/*
1621
* Initialize the grep_defaults template with hardcoded defaults.
1722
* We could let the compiler do this, but without C99 initializers
@@ -42,6 +47,7 @@ void init_grep_defaults(void)
4247
color_set(opt->color_selected, "");
4348
color_set(opt->color_sep, GIT_COLOR_CYAN);
4449
opt->color = -1;
50+
opt->output = std_output;
4551
}
4652

4753
static int parse_pattern_type_arg(const char *opt, const char *arg)
@@ -152,6 +158,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)
152158
opt->pathname = def->pathname;
153159
opt->regflags = def->regflags;
154160
opt->relative = def->relative;
161+
opt->output = def->output;
155162

156163
color_set(opt->color_context, def->color_context);
157164
color_set(opt->color_filename, def->color_filename);
@@ -1379,11 +1386,6 @@ static int look_ahead(struct grep_opt *opt,
13791386
return 0;
13801387
}
13811388

1382-
static void std_output(struct grep_opt *opt, const void *buf, size_t size)
1383-
{
1384-
fwrite(buf, size, 1, stdout);
1385-
}
1386-
13871389
static int fill_textconv_grep(struct userdiff_driver *driver,
13881390
struct grep_source *gs)
13891391
{

0 commit comments

Comments
 (0)