Skip to content

Commit fbfda15

Browse files
torvaldsgitster
authored andcommitted
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>
1 parent a274e0a commit fbfda15

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

builtin/shortlog.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,15 @@ static void read_from_stdin(struct shortlog *log)
117117
{
118118
struct strbuf author = STRBUF_INIT;
119119
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;
120123

124+
match = log->committer ? committer_match : author_match;
121125
while (strbuf_getline_lf(&author, stdin) != EOF) {
122126
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))
125129
continue;
126130
while (strbuf_getline_lf(&oneline, stdin) != EOF &&
127131
oneline.len)
@@ -140,6 +144,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
140144
struct strbuf author = STRBUF_INIT;
141145
struct strbuf oneline = STRBUF_INIT;
142146
struct pretty_print_context ctx = {0};
147+
const char *fmt;
143148

144149
ctx.fmt = CMIT_FMT_USERFORMAT;
145150
ctx.abbrev = log->abbrev;
@@ -148,7 +153,9 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
148153
ctx.date_mode.type = DATE_NORMAL;
149154
ctx.output_encoding = get_log_output_encoding();
150155

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);
152159
if (!log->summary) {
153160
if (log->user_format)
154161
pretty_print_commit(&ctx, commit, &oneline);
@@ -238,6 +245,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
238245
int nongit = !startup_info->have_repository;
239246

240247
const struct option options[] = {
248+
OPT_BOOL('c', "committer", &log.committer,
249+
N_("Group by committer rather than author")),
241250
OPT_BOOL('n', "numbered", &log.sort_by_number,
242251
N_("sort output according to the number of commits per author")),
243252
OPT_BOOL('s', "summary", &log.summary,

shortlog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct shortlog {
1313
int in2;
1414
int user_format;
1515
int abbrev;
16+
int committer;
1617

1718
char *common_repo_prefix;
1819
int email;

0 commit comments

Comments
 (0)