[PATCH] git-commit: search author pattern against mailmap

2013-08-23 Thread Antoine Pelisse
When committing for someone else, using the --author option, it can be
nice to use the mailmap file to find the correct name spelling and email
address.

Currently, you would have to find the correct mapping in mailmap file
first, and then use the full ident form when committing.

Let's allow git-commit to find if an entry exists in mailmap file for
that pattern, and use that instead.

Signed-off-by: Antoine Pelisse apeli...@gmail.com
---
Hi,
I would use that feature at work where I happen to commit some work for
other colleagues, while we heavily rely on mailmap file to have decent indents.

On the other hand, I'm kind of embarrassed to add this new option to
git-commit.

 Documentation/git-commit.txt |  6 +-
 builtin/commit.c | 16 +++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 1a7616c..9e3fe04 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -12,7 +12,7 @@ SYNOPSIS
   [--dry-run] [(-c | -C | --fixup | --squash) commit]
   [-F file | -m msg] [--reset-author] [--allow-empty]
   [--allow-empty-message] [--no-verify] [-e] [--author=author]
-  [--date=date] [--cleanup=mode] [--[no-]status]
+  [--use-mailmap] [--date=date] [--cleanup=mode] [--[no-]status]
   [-i | -o] [-S[keyid]] [--] [file...]

 DESCRIPTION
@@ -131,6 +131,10 @@ OPTIONS
commit by that author (i.e. rev-list --all -i --author=author);
the commit author is then copied from the first such commit found.

+--use-mailmap::
+   When used with `--author=author`, match the author pattern
+   against mapped name and email. See linkgit:git-shortlog[1].
+
 --date=date::
Override the author date used in the commit.

diff --git a/builtin/commit.c b/builtin/commit.c
index 10acc53..fbd0664 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...),
@@ -87,6 +88,7 @@ static enum {
 } commit_style;

 static const char *logfile, *force_author;
+static int mailmap;
 static const char *template_file;
 /*
  * The _message variables are commit names from which to take
@@ -945,13 +947,24 @@ static const char *find_author_by_nickname(const char 
*name)
av[++ac] = buf.buf;
av[++ac] = NULL;
setup_revisions(ac, av, revs, NULL);
+   if (mailmap) {
+   revs.mailmap = xcalloc(1, sizeof(struct string_list));
+   read_mailmap(revs.mailmap, NULL);
+   }
prepare_revision_walk(revs);
commit = get_revision(revs);
if (commit) {
struct pretty_print_context ctx = {0};
+   const char *format;
+
+   if (mailmap)
+   format = %aN %aE;
+   else
+   format = %an %ae;
+
ctx.date_mode = DATE_NORMAL;
strbuf_release(buf);
-   format_commit_message(commit, %an %ae, buf, ctx);
+   format_commit_message(commit, format, buf, ctx);
return strbuf_detach(buf, NULL);
}
die(_(No existing author found with '%s'), name);
@@ -1428,6 +1441,7 @@ int cmd_commit(int argc, const char **argv, const char 
*prefix)
OPT_GROUP(N_(Commit message options)),
OPT_FILENAME('F', file, logfile, N_(read message from 
file)),
OPT_STRING(0, author, force_author, N_(author), 
N_(override author for commit)),
+   OPT_BOOLEAN(0, use-mailmap, mailmap, N_(Use mailmap file 
when searching for author)),
OPT_STRING(0, date, force_date, N_(date), N_(override 
date for commit)),
OPT_CALLBACK('m', message, message, N_(message), 
N_(commit message), opt_parse_m),
OPT_STRING('c', reedit-message, edit_message, N_(commit), 
N_(reuse and edit message from specified commit)),
--
1.8.4.rc4.1.g0d8beaa.dirty

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] git-commit: search author pattern against mailmap

2013-08-23 Thread Junio C Hamano
Antoine Pelisse apeli...@gmail.com writes:

 When committing for someone else, using the --author option, it can be
 nice to use the mailmap file to find the correct name spelling and email
 address.

 Currently, you would have to find the correct mapping in mailmap file
 first, and then use the full ident form when committing.

 Let's allow git-commit to find if an entry exists in mailmap file for
 that pattern, and use that instead.

 Signed-off-by: Antoine Pelisse apeli...@gmail.com
 ---
 Hi,
 I would use that feature at work where I happen to commit some work for
 other colleagues, while we heavily rely on mailmap file to have decent 
 indents.

 On the other hand, I'm kind of embarrassed to add this new option to
 git-commit.

My initial reaction was Why should something as important as 'git
commit' should be playing a guessing-game? ;-) and I am kind of
ashamed to have added 146ea068 (git commit --author=$name: look
$name up in existing commits, 2008-08-26) and then am embarrased to
have completely forgotten about it. I never use the feature myself.

But for that old and established --author parameter that does not
use the standard format guesses feature to be useful, I agree that
it should honor the mailmap.

I wonder if it would hurt anybody if we made this unconditional, not
even with --no-mailmap override? Opinions?


  Documentation/git-commit.txt |  6 +-
  builtin/commit.c | 16 +++-
  2 files changed, 20 insertions(+), 2 deletions(-)

 diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
 index 1a7616c..9e3fe04 100644
 --- a/Documentation/git-commit.txt
 +++ b/Documentation/git-commit.txt
 @@ -12,7 +12,7 @@ SYNOPSIS
  [--dry-run] [(-c | -C | --fixup | --squash) commit]
  [-F file | -m msg] [--reset-author] [--allow-empty]
  [--allow-empty-message] [--no-verify] [-e] [--author=author]
 -[--date=date] [--cleanup=mode] [--[no-]status]
 +[--use-mailmap] [--date=date] [--cleanup=mode] [--[no-]status]
  [-i | -o] [-S[keyid]] [--] [file...]

  DESCRIPTION
 @@ -131,6 +131,10 @@ OPTIONS
   commit by that author (i.e. rev-list --all -i --author=author);
   the commit author is then copied from the first such commit found.

 +--use-mailmap::
 + When used with `--author=author`, match the author pattern
 + against mapped name and email. See linkgit:git-shortlog[1].
 +
  --date=date::
   Override the author date used in the commit.

 diff --git a/builtin/commit.c b/builtin/commit.c
 index 10acc53..fbd0664 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...),
 @@ -87,6 +88,7 @@ static enum {
  } commit_style;

  static const char *logfile, *force_author;
 +static int mailmap;
  static const char *template_file;
  /*
   * The _message variables are commit names from which to take
 @@ -945,13 +947,24 @@ static const char *find_author_by_nickname(const char 
 *name)
   av[++ac] = buf.buf;
   av[++ac] = NULL;
   setup_revisions(ac, av, revs, NULL);
 + if (mailmap) {
 + revs.mailmap = xcalloc(1, sizeof(struct string_list));
 + read_mailmap(revs.mailmap, NULL);
 + }
   prepare_revision_walk(revs);
   commit = get_revision(revs);
   if (commit) {
   struct pretty_print_context ctx = {0};
 + const char *format;
 +
 + if (mailmap)
 + format = %aN %aE;
 + else
 + format = %an %ae;
 +
   ctx.date_mode = DATE_NORMAL;
   strbuf_release(buf);
 - format_commit_message(commit, %an %ae, buf, ctx);
 + format_commit_message(commit, format, buf, ctx);
   return strbuf_detach(buf, NULL);
   }
   die(_(No existing author found with '%s'), name);
 @@ -1428,6 +1441,7 @@ int cmd_commit(int argc, const char **argv, const char 
 *prefix)
   OPT_GROUP(N_(Commit message options)),
   OPT_FILENAME('F', file, logfile, N_(read message from 
 file)),
   OPT_STRING(0, author, force_author, N_(author), 
 N_(override author for commit)),
 + OPT_BOOLEAN(0, use-mailmap, mailmap, N_(Use mailmap file 
 when searching for author)),
   OPT_STRING(0, date, force_date, N_(date), N_(override 
 date for commit)),
   OPT_CALLBACK('m', message, message, N_(message), 
 N_(commit message), opt_parse_m),
   OPT_STRING('c', reedit-message, edit_message, N_(commit), 
 N_(reuse and edit message from specified commit)),
 --
 1.8.4.rc4.1.g0d8beaa.dirty
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] git-commit: search author pattern against mailmap

2013-08-23 Thread Junio C Hamano
Jeff King p...@peff.net writes:

 But for that old and established --author parameter that does not
 use the standard format guesses feature to be useful, I agree that
 it should honor the mailmap.
 
 I wonder if it would hurt anybody if we made this unconditional, not
 even with --no-mailmap override? Opinions?

 I think it would be OK. You can always override by giving the actual
 full address you want instead of a partial one.

OK, so how about labelling it as a bugfix, like this perhaps?  We
obviously need a test or two, though.

-- 8 --
From: Antoine Pelisse apeli...@gmail.com
Date: Fri, 23 Aug 2013 15:48:31 +0200
Subject: [PATCH] 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 apeli...@gmail.com
Signed-off-by: Junio C Hamano gits...@pobox.com
---
 builtin/commit.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 10acc53..5b7d969 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...),
@@ -945,13 +946,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 = xcalloc(1, sizeof(struct string_list));
+   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);
-- 
1.8.4-rc4-299-g7e07a8d
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] git-commit: search author pattern against mailmap

2013-08-23 Thread Antoine Pelisse
On Fri, Aug 23, 2013 at 9:03 PM, Junio C Hamano gits...@pobox.com wrote:
 OK, so how about labelling it as a bugfix, like this perhaps?  We
 obviously need a test or two, though.

OK,
I will resubmit tomorrow with some tests.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] git-commit: search author pattern against mailmap

2013-08-23 Thread Junio C Hamano
Antoine Pelisse apeli...@gmail.com writes:

 On Fri, Aug 23, 2013 at 9:03 PM, Junio C Hamano gits...@pobox.com wrote:
 OK, so how about labelling it as a bugfix, like this perhaps?  We
 obviously need a test or two, though.

 OK,
 I will resubmit tomorrow with some tests.

Thanks.

Also, after I sent out that like this patch, I realized that the
mailmap string-list no longer has to be on the heap if we are doing
it unconditionally (it can be an auto variable in the function,
sitting next to struct strbuf buf).
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html