Skip to content

Commit 379642b

Browse files
bmwillgitster
authored andcommitted
grep: set default output method
Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6fac7f commit 379642b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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)