Skip to content

Commit 2225e1e

Browse files
bmwillgitster
authored andcommitted
grep: fix builds with with no thread support
Commit 0281e48 ("grep: optionally recurse into submodules") added functions grep_submodule() and grep_submodule_launch() which use "struct work_item" which is defined only when thread support is available. The original implementation of grep_submodule() used the "struct work_item" in order to gain access to a strbuf to store its output which was to be printed at a later point in time. This differs from how both grep_file() and grep_sha1() handle their output. This patch eliminates the reliance on the "struct work_item" and instead opts to use the output function stored in the output field of the "struct grep_opt" object directly, making it behave similarly to both grep_file() and grep_sha1(). Reported-by: Rahul Bedarkar <[email protected]> Signed-off-by: Brandon Williams <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 379642b commit 2225e1e

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
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
}

0 commit comments

Comments
 (0)