Re: [PATCH v8 2/2] pretty: colorize pattern matches in commit messages
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 28, 2021, 00:03 UTC
- Message-ID
- <xmqqilylmuqx.fsf@gitster.g>
- In-Reply-To
- <20210924155000.1259649-2-someguy@effective-light.com>
Hamza Mahfooz <someguy@effective-light.com> writes:
Show 19 quoted lines
> +static void append_line_with_color(struct strbuf *sb, struct grep_opt *opt,
> + const char *line, size_t linelen,
> + int color, enum grep_context ctx,
> + enum grep_header_field field)
> +{
> + const char *buf, *eol, *line_color, *match_color;
> + regmatch_t match;
> + int eflags = 0;
> +
> + buf = line;
> + eol = buf + linelen;
> +
> + if (!opt || !want_color(color) || opt->invert)
> + goto end;
> +
> + line_color = opt->colors[GREP_COLOR_SELECTED];
> + match_color = opt->colors[GREP_COLOR_MATCH_SELECTED];
> +
> + while (grep_next_match(opt, buf, eol, ctx, &match, field, eflags)) {So, this expects <buf, eol> to be only payload without "author " or timestamp, ...
Show 22 quoted lines
> } else {
> - strbuf_addf(sb, "%s: %.*s%.*s <%.*s>\n", what,
> - (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0, " ",
> - (int)namelen, namebuf, (int)maillen, mailbuf);
> + struct strbuf id = STRBUF_INIT;
> + enum grep_header_field field = GREP_HEADER_FIELD_MAX;
> + struct grep_opt *opt = pp->rev ? &pp->rev->grep_filter : NULL;
> +
> + if (!strcmp(what, "Author"))
> + field = GREP_HEADER_AUTHOR;
> + else if (!strcmp(what, "Commit"))
> + field = GREP_HEADER_COMMITTER;
> +
> + strbuf_addf(sb, "%s: ", what);
> + if (pp->fmt == CMIT_FMT_FULLER)
> + strbuf_addchars(sb, ' ', 4);
> +
> + strbuf_addf(&id, "%.*s <%.*s>", (int)namelen, namebuf,
> + (int)maillen, mailbuf);
> +
> + append_line_with_color(sb, opt, id.buf, id.len, pp->color,
> + GREP_CONTEXT_HEAD, field);... which is exactly what this caller is doing.
Very nice.