grep: set default output method

Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Mar 17, 2017 at 11:41 UTC 379642bcd8d89db52feba88a651e4e56d6ac5767
1 file changed +7 -5
grep.c
+7 -5
@@ -12,6 +12,11 @@ static int grep_source_is_binary(struct grep_source *gs);
12
13 static struct grep_opt grep_defaults;
14
15 +static void std_output(struct grep_opt *opt, const void *buf, size_t size)
16 +{
17 + fwrite(buf, size, 1, stdout);
18 +}
19 +
20 /*
21 * Initialize the grep_defaults template with hardcoded defaults.
22 * We could let the compiler do this, but without C99 initializers
@@ -42,6 +47,7 @@ void init_grep_defaults(void)
47 color_set(opt->color_selected, "");
48 color_set(opt->color_sep, GIT_COLOR_CYAN);
49 opt->color = -1;
50 + opt->output = std_output;
51 }
52
53 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)
158 opt->pathname = def->pathname;
159 opt->regflags = def->regflags;
160 opt->relative = def->relative;
161 + opt->output = def->output;
162
163 color_set(opt->color_context, def->color_context);
164 color_set(opt->color_filename, def->color_filename);
@@ -1379,11 +1386,6 @@ static int look_ahead(struct grep_opt *opt,
1386 return 0;
1387 }
1388
1382 -static void std_output(struct grep_opt *opt, const void *buf, size_t size)
1383 -{
1384 - fwrite(buf, size, 1, stdout);
1385 -}
1386 -
1389 static int fill_textconv_grep(struct userdiff_driver *driver,
1390 struct grep_source *gs)
1391 {