commit: search author pattern against mailmap

"git commit --author=$name" sets the author to one whose name matches the given string from existing commits, when $name is not in the "Name <e-mail>" format. However, it does not honor the mailmap to use the canonical name for the author found this way. Fix it by telling the logic to find a matching existing author to honor the mailmap, and use the name and email after applying the mailmap. Signed-off-by: Antoine Pelisse <apelisse@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Antoine Pelisse committed Aug 23, 2013 at 15:48 UTC ea16794e4303e79f8acb01a93fb6b1762972ab86
2 files changed +18 -1
builtin/commit.c
+7 -1
@@ -30,6 +30,7 @@
30 #include "column.h"
31 #include "sequencer.h"
32 #include "notes-utils.h"
33 +#include "mailmap.h"
34
35 static const char * const builtin_commit_usage[] = {
36 N_("git commit [options] [--] <pathspec>..."),
@@ -935,6 +936,7 @@ static const char *find_author_by_nickname(const char *name)
936 struct rev_info revs;
937 struct commit *commit;
938 struct strbuf buf = STRBUF_INIT;
939 + struct string_list mailmap = STRING_LIST_INIT_NODUP;
940 const char *av[20];
941 int ac = 0;
942
@@ -945,13 +947,17 @@ static const char *find_author_by_nickname(const char *name)
947 av[++ac] = buf.buf;
948 av[++ac] = NULL;
949 setup_revisions(ac, av, &revs, NULL);
950 + revs.mailmap = &mailmap;
951 + read_mailmap(revs.mailmap, NULL);
952 +
953 prepare_revision_walk(&revs);
954 commit = get_revision(&revs);
955 if (commit) {
956 struct pretty_print_context ctx = {0};
957 ctx.date_mode = DATE_NORMAL;
958 strbuf_release(&buf);
954 - format_commit_message(commit, "%an <%ae>", &buf, &ctx);
959 + format_commit_message(commit, "%aN <%aE>", &buf, &ctx);
960 + clear_mailmap(&mailmap);
961 return strbuf_detach(&buf, NULL);
962 }
963 die(_("No existing author found with '%s'"), name);
t/t4203-mailmap.sh
+11
@@ -470,4 +470,15 @@ test_expect_success 'Blame output (complex mapping)' '
470 test_cmp expect actual.fuzz
471 '
472
473 +cat >expect <<\EOF
474 +Some Dude <some@dude.xx>
475 +EOF
476 +
477 +test_expect_success 'commit --author honors mailmap' '
478 + test_must_fail git commit --author "nick" --allow-empty -meight &&
479 + git commit --author "Some Dude" --allow-empty -meight &&
480 + git show --pretty=format:"%an <%ae>%n" >actual &&
481 + test_cmp expect actual
482 +'
483 +
484 test_done