shortlog: group by committer information

In some situations you may want to group the commits not by author, but by committer instead. For example, when I just wanted to look up what I'm still missing from linux-next in the current merge window, I don't care so much about who wrote a patch, as what git tree it came from, which generally boils down to "who committed it". So make git shortlog take a "-c" or "--committer" option to switch grouping to that. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Oct 11, 2016 at 11:45 UTC fbfda15fb8daf7388a19b8bed2f319a8c1b6c5f1
2 files changed +13 -3
builtin/shortlog.c
+12 -3
@@ -117,11 +117,15 @@ static void read_from_stdin(struct shortlog *log)
117 {
118 struct strbuf author = STRBUF_INIT;
119 struct strbuf oneline = STRBUF_INIT;
120 + static const char *author_match[2] = { "Author: ", "author " };
121 + static const char *committer_match[2] = { "Commit: ", "committer " };
122 + const char **match;
123
124 + match = log->committer ? committer_match : author_match;
125 while (strbuf_getline_lf(&author, stdin) != EOF) {
126 const char *v;
123 - if (!skip_prefix(author.buf, "Author: ", &v) &&
124 - !skip_prefix(author.buf, "author ", &v))
127 + if (!skip_prefix(author.buf, match[0], &v) &&
128 + !skip_prefix(author.buf, match[1], &v))
129 continue;
130 while (strbuf_getline_lf(&oneline, stdin) != EOF &&
131 oneline.len)
@@ -140,6 +144,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
144 struct strbuf author = STRBUF_INIT;
145 struct strbuf oneline = STRBUF_INIT;
146 struct pretty_print_context ctx = {0};
147 + const char *fmt;
148
149 ctx.fmt = CMIT_FMT_USERFORMAT;
150 ctx.abbrev = log->abbrev;
@@ -148,7 +153,9 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
153 ctx.date_mode.type = DATE_NORMAL;
154 ctx.output_encoding = get_log_output_encoding();
155
151 - format_commit_message(commit, "%an <%ae>", &author, &ctx);
156 + fmt = log->committer ? "%cn <%ce>" : "%an <%ae>";
157 +
158 + format_commit_message(commit, fmt, &author, &ctx);
159 if (!log->summary) {
160 if (log->user_format)
161 pretty_print_commit(&ctx, commit, &oneline);
@@ -238,6 +245,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
245 int nongit = !startup_info->have_repository;
246
247 const struct option options[] = {
248 + OPT_BOOL('c', "committer", &log.committer,
249 + N_("Group by committer rather than author")),
250 OPT_BOOL('n', "numbered", &log.sort_by_number,
251 N_("sort output according to the number of commits per author")),
252 OPT_BOOL('s', "summary", &log.summary,
shortlog.h
+1
@@ -13,6 +13,7 @@ struct shortlog {
13 int in2;
14 int user_format;
15 int abbrev;
16 + int committer;
17
18 char *common_repo_prefix;
19 int email;