]> git.scripts.mit.edu Git - git.git/commitdiff
shortlog: ignore commits with missing authors
authorJeff King <peff@peff.net>
Wed, 18 Sep 2013 21:14:00 +0000 (17:14 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Sep 2013 21:41:19 +0000 (14:41 -0700)
Most of git's traversals are robust against minor breakages
in commit data. For example, "git log" will still output an
entry for a commit that has a broken encoding or missing
author, and will not abort the whole operation.

Shortlog, on the other hand, will die as soon as it sees a
commit without an author, meaning that a repository with
a broken commit cannot get any shortlog output at all.

Let's downgrade this fatal error to a warning, and continue
the operation.

We simply ignore the commit and do not count it in the total
(since we do not have any author under which to file it).
Alternatively, we could output some kind of "<empty>" record
to collect these bogus commits. It is probably not worth it,
though; we have already warned to stderr, so the user is
aware that such bogosities exist, and any placeholder we
came up with would either be syntactically invalid, or would
potentially conflict with real data.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/shortlog.c
t/t4201-shortlog.sh

index 1fd6f8ac5977ee670bf8ba230cec8553393baafd..dca7fa1f91cecacba9e09dff9875260f08a79386 100644 (file)
@@ -127,9 +127,11 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
                        author = buffer + 7;
                buffer = eol;
        }
-       if (!author)
-               die(_("Missing author: %s"),
+       if (!author) {
+               warning(_("Missing author: %s"),
                    sha1_to_hex(commit->object.sha1));
+               return;
+       }
        if (log->user_format) {
                struct pretty_print_context ctx = {0};
                ctx.fmt = CMIT_FMT_USERFORMAT;
index 5493500ef15d2f561bd14ca0bdf5f519ec6f49be..42866992cfe65657019dced508d3490b3851a6c7 100755 (executable)
@@ -172,4 +172,20 @@ test_expect_success 'shortlog encoding' '
        git shortlog HEAD~2.. > out &&
 test_cmp expect out'
 
+test_expect_success 'shortlog ignores commits with missing authors' '
+       git commit --allow-empty -m normal &&
+       git commit --allow-empty -m soon-to-be-broken &&
+       git cat-file commit HEAD >commit.tmp &&
+       sed "/^author/d" commit.tmp >broken.tmp &&
+       commit=$(git hash-object -w -t commit --stdin <broken.tmp) &&
+       git update-ref HEAD $commit &&
+       cat >expect <<-\EOF &&
+       A U Thor (1):
+             normal
+
+       EOF
+       git shortlog HEAD~2.. >actual &&
+       test_cmp expect actual
+'
+
 test_done