1 From 2225e1ea20481a7c0da526891470abf9ece623e7 Mon Sep 17 00:00:00 2001
2 From: Brandon Williams <bmwill@google.com>
3 Date: Fri, 17 Mar 2017 11:41:55 -0700
4 Subject: [PATCH] grep: fix builds with with no thread support
6 Commit 0281e487fd91 ("grep: optionally recurse into submodules")
7 added functions grep_submodule() and grep_submodule_launch() which
8 use "struct work_item" which is defined only when thread support
11 The original implementation of grep_submodule() used the "struct
12 work_item" in order to gain access to a strbuf to store its output which
13 was to be printed at a later point in time. This differs from how both
14 grep_file() and grep_sha1() handle their output. This patch eliminates
15 the reliance on the "struct work_item" and instead opts to use the
16 output function stored in the output field of the "struct grep_opt"
17 object directly, making it behave similarly to both grep_file() and
20 Reported-by: Rahul Bedarkar <rahul.bedarkar@imgtec.com>
21 Signed-off-by: Brandon Williams <bmwill@google.com>
22 Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
23 Signed-off-by: Junio C Hamano <gitster@pobox.com>
24 Signed-off-by: Rahul Bedarkar <rahul.bedarkar@imgtec.com>
26 builtin/grep.c | 21 +++++++++------------
27 1 file changed, 9 insertions(+), 12 deletions(-)
29 diff --git a/builtin/grep.c b/builtin/grep.c
30 index 2c727ef..33561f2 100644
33 @@ -538,7 +538,7 @@ static int grep_submodule_launch(struct grep_opt *opt,
35 const char *end_of_base;
37 - struct work_item *w = opt->output_priv;
38 + struct strbuf child_output = STRBUF_INIT;
40 end_of_base = strchr(gs->name, ':');
41 if (gs->identifier && end_of_base)
42 @@ -593,14 +593,16 @@ static int grep_submodule_launch(struct grep_opt *opt,
43 * child process. A '0' indicates a hit, a '1' indicates no hit and
44 * anything else is an error.
46 - status = capture_command(&cp, &w->out, 0);
47 + status = capture_command(&cp, &child_output, 0);
48 if (status && (status != 1)) {
49 /* flush the buffer */
50 - write_or_die(1, w->out.buf, w->out.len);
51 + write_or_die(1, child_output.buf, child_output.len);
52 die("process for submodule '%s' failed with exit code: %d",
56 + opt->output(opt, child_output.buf, child_output.len);
57 + strbuf_release(&child_output);
58 /* invert the return code to make a hit equal to 1 */
61 @@ -641,19 +643,14 @@ static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1,
66 + struct grep_source gs;
69 - grep_source_init(&w.source, GREP_SOURCE_SUBMODULE,
70 + grep_source_init(&gs, GREP_SOURCE_SUBMODULE,
71 filename, path, sha1);
72 - strbuf_init(&w.out, 0);
73 - opt->output_priv = &w;
74 - hit = grep_submodule_launch(opt, &w.source);
75 + hit = grep_submodule_launch(opt, &gs);
77 - write_or_die(1, w.out.buf, w.out.len);
79 - grep_source_clear(&w.source);
80 - strbuf_release(&w.out);
81 + grep_source_clear(&gs);