Hamza Mahfooz <someguy@xxxxxxxxxxxxxxxxxxx> writes: > +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, ... > } 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.