Merge branch 'lt/shortlog-by-committer'
authorJunio C Hamano <gitster@pobox.com>
Tue, 27 Dec 2016 08:11:44 +0000 (00:11 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Dec 2016 08:11:44 +0000 (00:11 -0800)
"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

Documentation/git-shortlog.txt
builtin/shortlog.c
shortlog.h
t/t4201-shortlog.sh
index 31af7f27360d277ccdc3e5bd59b4788c83934b8e..ee6c5476c1d2bf3b2a708e6152ebaba5882cc4f7 100644 (file)
@@ -47,6 +47,10 @@ OPTIONS
 
        Each pretty-printed commit will be rewrapped before it is shown.
 
+-c::
+--committer::
+       Collect and show committer identities instead of authors.
+
 -w[<width>[,<indent1>[,<indent2>]]]::
        Linewrap the output by wrapping each line at `width`.  The first
        line of each entry is indented by `indent1` spaces, and the second
index ba0e1154a9f0b95f60e5bcb6cdb716bf0f6ef366..c9585d475d90c41554465f870e530c16ab93199f 100644 (file)
@@ -117,11 +117,15 @@ static void read_from_stdin(struct shortlog *log)
 {
        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)
@@ -140,6 +144,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
        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;
@@ -148,7 +153,9 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
        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);
@@ -238,6 +245,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
        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,
index 5a326c68602610d856ac543b8bd034542d83f64b..5d64cfe929684807fcfa004ec3edf10d720189c9 100644 (file)
@@ -13,6 +13,7 @@ struct shortlog {
        int in2;
        int user_format;
        int abbrev;
+       int committer;
 
        char *common_repo_prefix;
        int email;
index ae08b57712e382a4cba7f7a51a499b4621a38c84..9df054bf05b8cd40011c0577aa0ce0f30cb8c23f 100755 (executable)
@@ -190,4 +190,23 @@ test_expect_success 'shortlog with --output=<file>' '
        test_line_count = 3 shortlog
 '
 
+test_expect_success 'shortlog --committer (internal)' '
+       git checkout --orphan side &&
+       git commit --allow-empty -m one &&
+       git commit --allow-empty -m two &&
+       GIT_COMMITTER_NAME="Sin Nombre" git commit --allow-empty -m three &&
+
+       cat >expect <<-\EOF &&
+            2  C O Mitter
+            1  Sin Nombre
+       EOF
+       git shortlog -nsc HEAD >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'shortlog --committer (external)' '
+       git log --format=full | git shortlog -nsc >actual &&
+       test_cmp expect actual
+'
+
 test_done