Commit fbfda15f authored by Linus Torvalds's avatar Linus Torvalds Committed by Junio C Hamano

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: default avatarLinus Torvalds <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent a274e0a0
...@@ -117,11 +117,15 @@ static void read_from_stdin(struct shortlog *log) ...@@ -117,11 +117,15 @@ static void read_from_stdin(struct shortlog *log)
{ {
struct strbuf author = STRBUF_INIT; struct strbuf author = STRBUF_INIT;
struct strbuf oneline = 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) { while (strbuf_getline_lf(&author, stdin) != EOF) {
const char *v; const char *v;
if (!skip_prefix(author.buf, "Author: ", &v) && if (!skip_prefix(author.buf, match[0], &v) &&
!skip_prefix(author.buf, "author ", &v)) !skip_prefix(author.buf, match[1], &v))
continue; continue;
while (strbuf_getline_lf(&oneline, stdin) != EOF && while (strbuf_getline_lf(&oneline, stdin) != EOF &&
oneline.len) oneline.len)
...@@ -140,6 +144,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) ...@@ -140,6 +144,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
struct strbuf author = STRBUF_INIT; struct strbuf author = STRBUF_INIT;
struct strbuf oneline = STRBUF_INIT; struct strbuf oneline = STRBUF_INIT;
struct pretty_print_context ctx = {0}; struct pretty_print_context ctx = {0};
const char *fmt;
ctx.fmt = CMIT_FMT_USERFORMAT; ctx.fmt = CMIT_FMT_USERFORMAT;
ctx.abbrev = log->abbrev; ctx.abbrev = log->abbrev;
...@@ -148,7 +153,9 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) ...@@ -148,7 +153,9 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
ctx.date_mode.type = DATE_NORMAL; ctx.date_mode.type = DATE_NORMAL;
ctx.output_encoding = get_log_output_encoding(); 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->summary) {
if (log->user_format) if (log->user_format)
pretty_print_commit(&ctx, commit, &oneline); pretty_print_commit(&ctx, commit, &oneline);
...@@ -238,6 +245,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) ...@@ -238,6 +245,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
int nongit = !startup_info->have_repository; int nongit = !startup_info->have_repository;
const struct option options[] = { 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, OPT_BOOL('n', "numbered", &log.sort_by_number,
N_("sort output according to the number of commits per author")), N_("sort output according to the number of commits per author")),
OPT_BOOL('s', "summary", &log.summary, OPT_BOOL('s', "summary", &log.summary,
......
...@@ -13,6 +13,7 @@ struct shortlog { ...@@ -13,6 +13,7 @@ struct shortlog {
int in2; int in2;
int user_format; int user_format;
int abbrev; int abbrev;
int committer;
char *common_repo_prefix; char *common_repo_prefix;
int email; int email;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment