git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] commit: search author pattern against mailmap

From
Antoine Pelisse <apelisse@gmail.com>
Date
Aug 25, 2013, 10:01 UTC
Message-ID
<1377424889-15399-1-git-send-email-apelisse@gmail.com>
In-Reply-To
<xmqqob8ml588.fsf@gitster.dls.corp.google.com>

"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>
---
Hey,
So I kept clear_mailmap() where you put it, but I think it could be moved
right after get_revision(). That is because I think format_commit_message()
will run another read_mailmap() with an heap-allocated string_list.
Anyway, I'm not sure it makes a big difference here.

Thanks, Antoine

 builtin/commit.c   |  8 +++++++-
 t/t4203-mailmap.sh | 11 +++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 10acc53..a48a7fe 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -30,6 +30,7 @@
 #include "column.h"
 #include "sequencer.h"
 #include "notes-utils.h"
+#include "mailmap.h"

 static const char * const builtin_commit_usage[] = {
 	N_("git commit [options] [--] <pathspec>..."),
@@ -935,6 +936,7 @@ static const char *find_author_by_nickname(const char *name)
 	struct rev_info revs;
 	struct commit *commit;
 	struct strbuf buf = STRBUF_INIT;
+	struct string_list mailmap = STRING_LIST_INIT_NODUP;
 	const char *av[20];
 	int ac = 0;

@@ -945,13 +947,17 @@ static const char *find_author_by_nickname(const char *name)
 	av[++ac] = buf.buf;
 	av[++ac] = NULL;
 	setup_revisions(ac, av, &revs, NULL);
+	revs.mailmap = &mailmap;
+	read_mailmap(revs.mailmap, NULL);
+
 	prepare_revision_walk(&revs);
 	commit = get_revision(&revs);
 	if (commit) {
 		struct pretty_print_context ctx = {0};
 		ctx.date_mode = DATE_NORMAL;
 		strbuf_release(&buf);
-		format_commit_message(commit, "%an <%ae>", &buf, &ctx);
+		format_commit_message(commit, "%aN <%aE>", &buf, &ctx);
+		clear_mailmap(&mailmap);
 		return strbuf_detach(&buf, NULL);
 	}
 	die(_("No existing author found with '%s'"), name);
diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh
index baa4685..4d715f0 100755
--- a/t/t4203-mailmap.sh
+++ b/t/t4203-mailmap.sh
@@ -470,4 +470,15 @@ test_expect_success 'Blame output (complex mapping)' '
 	test_cmp expect actual.fuzz
 '

+cat >expect <<\EOF
+Some Dude <some@dude.xx>
+EOF
+
+test_expect_success 'commit --author honors mailmap' '
+	test_must_fail git commit --author "nick" --allow-empty -meight &&
+	git commit --author "Some Dude" --allow-empty -meight &&
+	git show --pretty=format:"%an <%ae>%n" >actual &&
+	test_cmp expect actual
+'
+
 test_done
--
1.8.4.rc4.2.g8483dfa.dirty
Previous: Antoine PelisseNext: Jeff King
Message 11 of 17 in “git-commit: search author pattern against mailmap”
  1. git-commit: search author pattern against mailmapAntoine Pelisse, Aug 23, 2013
  2. Junio C HamanoAug 23, 2013
  3. Jeff KingAug 23, 2013
  4. Junio C HamanoAug 23, 2013
  5. Antoine PelisseAug 23, 2013
  6. Junio C HamanoAug 23, 2013
  7. commit: search author pattern against mailmapAntoine Pelisse, Aug 24, 2013
  8. Jeff KingAug 25, 2013
  9. Junio C HamanoAug 25, 2013
  10. Antoine PelisseAug 25, 2013
  11. commit: search author pattern against mailmapAntoine Pelisse, Aug 25, 2013
  12. Jeff KingAug 25, 2013
  13. Antoine PelisseAug 25, 2013
  14. Jeff KingAug 25, 2013
  15. Antoine PelisseAug 25, 2013
  16. Junio C HamanoAug 26, 2013
  17. Jeff KingAug 26, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.