Skip to content

Commit ad1b4e2

Browse files
committed
Merge branch 'lt/shortlog-by-committer'
"git shortlog" learned "--committer" option to group commits by committer, instead of author. * lt/shortlog-by-committer: t4201: make tests work with and without the MINGW prerequiste shortlog: test and document --committer option shortlog: group by committer information
2 parents c5139e0 + bc44f93 commit ad1b4e2

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

Documentation/git-shortlog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ OPTIONS
4747

4848
Each pretty-printed commit will be rewrapped before it is shown.
4949

50+
-c::
51+
--committer::
52+
Collect and show committer identities instead of authors.
53+
5054
-w[<width>[,<indent1>[,<indent2>]]]::
5155
Linewrap the output by wrapping each line at `width`. The first
5256
line of each entry is indented by `indent1` spaces, and the second

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;

t/t4201-shortlog.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,23 @@ test_expect_success 'shortlog with --output=<file>' '
190190
test_line_count = 3 shortlog
191191
'
192192

193+
test_expect_success 'shortlog --committer (internal)' '
194+
git checkout --orphan side &&
195+
git commit --allow-empty -m one &&
196+
git commit --allow-empty -m two &&
197+
GIT_COMMITTER_NAME="Sin Nombre" git commit --allow-empty -m three &&
198+
199+
cat >expect <<-\EOF &&
200+
2 C O Mitter
201+
1 Sin Nombre
202+
EOF
203+
git shortlog -nsc HEAD >actual &&
204+
test_cmp expect actual
205+
'
206+
207+
test_expect_success 'shortlog --committer (external)' '
208+
git log --format=full | git shortlog -nsc >actual &&
209+
test_cmp expect actual
210+
'
211+
193212
test_done

0 commit comments

Comments
 (0)