From: Antoine Pelisse <apelisse@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jeff King <peff@peff.net>, git <git@vger.kernel.org>,
Antoine Pelisse <apelisse@gmail.com>
Subject: [PATCH] commit: search author pattern against mailmap
Date: Sat, 24 Aug 2013 16:07:47 +0200 [thread overview]
Message-ID: <1377353267-3886-1-git-send-email-apelisse@gmail.com> (raw)
In-Reply-To: <xmqqsiy0nnlr.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>
---
builtin/commit.c | 7 ++++++-
t/t4203-mailmap.sh | 11 +++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 10acc53..21e0f95 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,16 @@ 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);
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
next prev parent reply other threads:[~2013-08-24 14:08 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-23 13:48 [PATCH] git-commit: search author pattern against mailmap Antoine Pelisse
2013-08-23 17:44 ` Junio C Hamano
2013-08-23 18:35 ` Jeff King
2013-08-23 19:03 ` Junio C Hamano
2013-08-23 19:47 ` Antoine Pelisse
2013-08-23 20:44 ` Junio C Hamano
2013-08-24 14:07 ` Antoine Pelisse [this message]
2013-08-25 4:01 ` [PATCH] commit: " Jeff King
2013-08-25 5:16 ` Junio C Hamano
2013-08-25 9:47 ` Antoine Pelisse
2013-08-25 10:01 ` Antoine Pelisse
2013-08-25 10:30 ` Jeff King
2013-08-25 13:37 ` Antoine Pelisse
2013-08-25 16:51 ` Jeff King
2013-08-25 20:42 ` Antoine Pelisse
2013-08-26 5:27 ` Junio C Hamano
2013-08-26 21:38 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1377353267-3886-1-git-send-email-apelisse@gmail.com \
--to=apelisse@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).