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
maint
Junio C Hamano 2017-03-28 14:05:57 -07:00
commit ff8b7e63de
2 changed files with 16 additions and 17 deletions

View File

@ -538,7 +538,7 @@ static int grep_submodule_launch(struct grep_opt *opt,
int status, i; int status, i;
const char *end_of_base; const char *end_of_base;
const char *name; const char *name;
struct work_item *w = opt->output_priv; struct strbuf child_output = STRBUF_INIT;


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


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


grep_source_init(&w.source, GREP_SOURCE_SUBMODULE, grep_source_init(&gs, GREP_SOURCE_SUBMODULE,
filename, path, sha1); filename, path, sha1);
strbuf_init(&w.out, 0); hit = grep_submodule_launch(opt, &gs);
opt->output_priv = &w;
hit = grep_submodule_launch(opt, &w.source);


write_or_die(1, w.out.buf, w.out.len); grep_source_clear(&gs);

grep_source_clear(&w.source);
strbuf_release(&w.out);
return hit; return hit;
} }
} }

12
grep.c
View File

@ -12,6 +12,11 @@ static int grep_source_is_binary(struct grep_source *gs);


static struct grep_opt grep_defaults; static struct grep_opt grep_defaults;


static void std_output(struct grep_opt *opt, const void *buf, size_t size)
{
fwrite(buf, size, 1, stdout);
}

/* /*
* Initialize the grep_defaults template with hardcoded defaults. * Initialize the grep_defaults template with hardcoded defaults.
* We could let the compiler do this, but without C99 initializers * We could let the compiler do this, but without C99 initializers
@ -42,6 +47,7 @@ void init_grep_defaults(void)
color_set(opt->color_selected, ""); color_set(opt->color_selected, "");
color_set(opt->color_sep, GIT_COLOR_CYAN); color_set(opt->color_sep, GIT_COLOR_CYAN);
opt->color = -1; opt->color = -1;
opt->output = std_output;
} }


static int parse_pattern_type_arg(const char *opt, const char *arg) 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)
opt->pathname = def->pathname; opt->pathname = def->pathname;
opt->regflags = def->regflags; opt->regflags = def->regflags;
opt->relative = def->relative; opt->relative = def->relative;
opt->output = def->output;


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


static void std_output(struct grep_opt *opt, const void *buf, size_t size)
{
fwrite(buf, size, 1, stdout);
}

static int fill_textconv_grep(struct userdiff_driver *driver, static int fill_textconv_grep(struct userdiff_driver *driver,
struct grep_source *gs) struct grep_source *gs)
{ {