From: Junio C Hamano Date: Fri, 10 Mar 2017 21:24:24 +0000 (-0800) Subject: Merge branch 'rs/log-email-subject' X-Git-Tag: v2.13.0-rc0~134 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/0a246106802b147ad81626f52c0aaa37398ba918?ds=inline;hp=-c Merge branch 'rs/log-email-subject' Code clean-up. * rs/log-email-subject: pretty: use fmt_output_email_subject() log-tree: factor out fmt_output_email_subject() --- 0a246106802b147ad81626f52c0aaa37398ba918 diff --combined builtin/shortlog.c index c9585d475d,21402ae8b7..f78bb4818d --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@@ -117,15 -117,11 +117,15 @@@ static void read_from_stdin(struct shor { struct strbuf author = STRBUF_INIT; struct strbuf oneline = STRBUF_INIT; + static const char *author_match[2] = { "Author: ", "author " }; + static const char *committer_match[2] = { "Commit: ", "committer " }; + const char **match; + match = log->committer ? committer_match : author_match; while (strbuf_getline_lf(&author, stdin) != EOF) { const char *v; - if (!skip_prefix(author.buf, "Author: ", &v) && - !skip_prefix(author.buf, "author ", &v)) + if (!skip_prefix(author.buf, match[0], &v) && + !skip_prefix(author.buf, match[1], &v)) continue; while (strbuf_getline_lf(&oneline, stdin) != EOF && oneline.len) @@@ -144,18 -140,15 +144,18 @@@ void shortlog_add_commit(struct shortlo struct strbuf author = STRBUF_INIT; struct strbuf oneline = STRBUF_INIT; struct pretty_print_context ctx = {0}; + const char *fmt; ctx.fmt = CMIT_FMT_USERFORMAT; ctx.abbrev = log->abbrev; - ctx.subject = ""; + ctx.print_email_subject = 1; ctx.after_subject = ""; ctx.date_mode.type = DATE_NORMAL; ctx.output_encoding = get_log_output_encoding(); - format_commit_message(commit, "%an <%ae>", &author, &ctx); + fmt = log->committer ? "%cn <%ce>" : "%an <%ae>"; + + format_commit_message(commit, fmt, &author, &ctx); if (!log->summary) { if (log->user_format) pretty_print_commit(&ctx, commit, &oneline); @@@ -245,8 -238,6 +245,8 @@@ int cmd_shortlog(int argc, const char * int nongit = !startup_info->have_repository; const struct option options[] = { + OPT_BOOL('c', "committer", &log.committer, + N_("Group by committer rather than author")), OPT_BOOL('n', "numbered", &log.sort_by_number, N_("sort output according to the number of commits per author")), OPT_BOOL('s', "summary", &log.summary, diff --combined commit.h index 9c12abb911,e818aff07e..528272ac9b --- a/commit.h +++ b/commit.h @@@ -142,21 -142,24 +142,24 @@@ static inline int cmit_fmt_is_mail(enu return (fmt == CMIT_FMT_EMAIL || fmt == CMIT_FMT_MBOXRD); } + struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */ + struct pretty_print_context { /* * Callers should tweak these to change the behavior of pp_* functions. */ enum cmit_fmt fmt; int abbrev; - const char *subject; const char *after_subject; int preserve_subject; struct date_mode date_mode; unsigned date_mode_explicit:1; + int print_email_subject; int expand_tabs_in_log; int need_8bit_cte; char *notes_message; struct reflog_walk_info *reflog_info; + struct rev_info *rev; const char *output_encoding; struct string_list *mailmap; int color; @@@ -175,7 -178,6 +178,6 @@@ struct userformat_want }; extern int has_non_ascii(const char *text); - struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */ extern const char *logmsg_reencode(const struct commit *commit, char **commit_encoding, const char *output_encoding); @@@ -355,7 -357,7 +357,7 @@@ extern const char *find_commit_header(c size_t *out_len); /* Find the end of the log message, the right place for a new trailer. */ -extern int ignore_non_trailer(struct strbuf *sb); +extern int ignore_non_trailer(const char *buf, size_t len); typedef void (*each_mergetag_fn)(struct commit *commit, struct commit_extra_header *extra, void *cb_data); diff --combined pretty.c index 5e683830d9,faeb3d97f6..d0f86f5d85 --- a/pretty.c +++ b/pretty.c @@@ -10,7 -10,6 +10,7 @@@ #include "color.h" #include "reflog-walk.h" #include "gpg-interface.h" +#include "trailer.h" static char *user_format; static struct cmt_fmt_map { @@@ -890,16 -889,6 +890,16 @@@ const char *format_subject(struct strbu return msg; } +static void format_trailers(struct strbuf *sb, const char *msg) +{ + struct trailer_info info; + + trailer_info_get(&info, msg); + strbuf_add(sb, info.trailer_start, + info.trailer_end - info.trailer_start); + trailer_info_release(&info); +} + static void parse_commit_message(struct format_commit_context *c) { const char *msg = c->message + c->message_off; @@@ -1303,12 -1292,6 +1303,12 @@@ static size_t format_commit_one(struct strbuf_addstr(sb, msg + c->body_off); return 1; } + + if (starts_with(placeholder, "(trailers)")) { + format_trailers(sb, msg + c->subject_off); + return strlen("(trailers)"); + } + return 0; /* unknown placeholder */ } @@@ -1607,8 -1590,9 +1607,9 @@@ void pp_title_line(struct pretty_print_ pp->preserve_subject ? "\n" : " "); strbuf_grow(sb, title.len + 1024); - if (pp->subject) { - strbuf_addstr(sb, pp->subject); + if (pp->print_email_subject) { + if (pp->rev) + fmt_output_email_subject(sb, pp->rev); if (needs_rfc2047_encoding(title.buf, title.len, RFC2047_SUBJECT)) add_rfc2047(sb, title.buf, title.len, encoding, RFC2047_SUBJECT); @@@ -1818,7 -1802,7 +1819,7 @@@ void pretty_print_commit(struct pretty_ } pp_header(pp, encoding, commit, &msg, sb); - if (pp->fmt != CMIT_FMT_ONELINE && !pp->subject) { + if (pp->fmt != CMIT_FMT_ONELINE && !pp->print_email_subject) { strbuf_addch(sb, '\n'); }