Re: [PATCH 2/2] grep.c: teach 'git grep --only-matching'
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Jun 27, 2018, 21:22 UTC
- Message-ID
- <20180627212248.GA1282@syl.attlocal.net>
- In-Reply-To
- <xmqq6024djf2.fsf@gitster-ct.c.googlers.com>
On Wed, Jun 27, 2018 at 02:11:13PM -0700, Junio C Hamano wrote:
Show 24 quoted lines
> Taylor Blau <me@ttaylorr.com> writes:
>
> >> Just initializing match_color where it is defined at the beginning of
> >> show_line() should be sufficient, I think.
> >
> > I think that we could also use the following, and leave the `if
> > (opt->color)` conditional where it is:
> >
> > diff --git a/grep.c b/grep.c
> > index 48cca6723e..b985fb3ee0 100644
> > --- a/grep.c
> > +++ b/grep.c
> > @@ -1448,7 +1448,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
> > const char *name, unsigned lno, ssize_t cno, char sign)
> > {
> > int rest = eol - bol;
> > - const char *match_color, *line_color = NULL;
> > + const char *match_color = NULL, *line_color = NULL;
> >
> > if (opt->file_break && opt->last_shown == 0) {
> > if (opt->show_hunk_mark)
>
> You say "we could also", but the above is exactly what I suggested,
> so we seem to be on the same page, which is good ;-)Ah, sorry -- I misinterpreted your meaning "initializing match_color where it is defined" to mean bringing the large `if (opt->color)` conditional up, instead of just assigning to NULL.
Let's do that and leave the `if (opt->color)` block where it is?
Thanks, Taylor