git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Antoine Pelisse <apelisse@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Rich Midwinter <rich.midwinter@gmail.com>,
	Antoine Pelisse <apelisse@gmail.com>
Subject: [PATCH 4/5] pretty: Use mailmap to display username and email
Date: Tue, 11 Dec 2012 23:21:32 +0100	[thread overview]
Message-ID: <1355264493-8298-5-git-send-email-apelisse@gmail.com> (raw)
In-Reply-To: <1355264493-8298-1-git-send-email-apelisse@gmail.com>

Use the mailmap information to display the correct
username and email address in all log commands.

Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
---
 pretty.c | 46 +++++++++++++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 15 deletions(-)

diff --git a/pretty.c b/pretty.c
index 6730add..e232aaa 100644
--- a/pretty.c
+++ b/pretty.c
@@ -387,6 +387,8 @@ void pp_user_info(const struct pretty_print_context *pp,
 		  const char *what, struct strbuf *sb,
 		  const char *line, const char *encoding)
 {
+	char person_name[1024];
+	char person_mail[1024];
 	struct ident_split ident;
 	int linelen, namelen;
 	char *line_end, *date;
@@ -405,41 +407,55 @@ void pp_user_info(const struct pretty_print_context *pp,
 	if (split_ident_line(&ident, line, linelen))
 		return;
 
-	namelen = ident.mail_end - ident.name_begin + 1;
+	memcpy(person_mail, ident.mail_begin, ident.mail_end - ident.mail_begin);
+	person_mail[ident.mail_end - ident.mail_begin] = 0;
+
+	memcpy(person_name, ident.name_begin, ident.name_end - ident.name_begin);
+	person_name[ident.name_end - ident.name_begin] = 0;
+
+	if (pp->mailmap)
+		map_user(pp->mailmap, person_mail, sizeof(person_mail),
+			 person_name, sizeof(person_name));
+
+	namelen = strlen(person_name) + strlen(person_mail);
 	time = strtoul(ident.date_begin, &date, 10);
 	tz = strtol(date, NULL, 10);
 
 	if (pp->fmt == CMIT_FMT_EMAIL) {
 		int display_name_length;
 
-		display_name_length = ident.name_end - ident.name_begin;
+		display_name_length = strlen(person_name);
 
 		strbuf_addstr(sb, "From: ");
-		if (needs_rfc2047_encoding(line, display_name_length, RFC2047_ADDRESS)) {
-			add_rfc2047(sb, line, display_name_length,
+		if (needs_rfc2047_encoding(person_name, display_name_length, RFC2047_ADDRESS)) {
+			add_rfc2047(sb, person_name, display_name_length,
 						encoding, RFC2047_ADDRESS);
 			max_length = 76; /* per rfc2047 */
-		} else if (needs_rfc822_quoting(line, display_name_length)) {
+		} else if (needs_rfc822_quoting(person_name,
+						display_name_length)) {
 			struct strbuf quoted = STRBUF_INIT;
-			add_rfc822_quoted(&quoted, line, display_name_length);
+			add_rfc822_quoted(&quoted, person_name,
+					  display_name_length);
 			strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len,
 							-6, 1, max_length);
 			strbuf_release(&quoted);
 		} else {
-			strbuf_add_wrapped_bytes(sb, line, display_name_length,
-							-6, 1, max_length);
+			strbuf_add_wrapped_bytes(sb, person_name,
+						 display_name_length,
+						 -6, 1, max_length);
 		}
-		if (namelen - display_name_length + last_line_length(sb) > max_length) {
+		if (namelen - display_name_length + last_line_length(sb) > max_length)
 			strbuf_addch(sb, '\n');
-			if (!isspace(ident.name_end[0]))
-				strbuf_addch(sb, ' ');
-		}
-		strbuf_add(sb, ident.name_end, namelen - display_name_length);
+
+		strbuf_addch(sb, ' ');
+		strbuf_addch(sb, '<');
+		strbuf_add(sb, person_mail, strlen(person_mail));
+		strbuf_addch(sb, '>');
 		strbuf_addch(sb, '\n');
 	} else {
-		strbuf_addf(sb, "%s: %.*s%.*s\n", what,
+		strbuf_addf(sb, "%s: %.*s%s <%s>\n", what,
 			      (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0,
-			      "    ", namelen, line);
+			    "    ", person_name, person_mail);
 	}
 	switch (pp->fmt) {
 	case CMIT_FMT_MEDIUM:
-- 
1.8.1.rc1.5.g7e0651a

  parent reply	other threads:[~2012-12-11 22:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-11 22:21 [PATCH 0/5] Allow git log to use mailmap file Antoine Pelisse
2012-12-11 22:21 ` [PATCH 1/5] Use split_ident_line to parse author and committer Antoine Pelisse
2012-12-11 22:21 ` [PATCH 2/5] mailmap: Remove buffer length limit in map_user Antoine Pelisse
2012-12-11 22:21 ` [PATCH 3/5] mailmap: Add mailmap structure to rev_info and pp Antoine Pelisse
2012-12-11 22:21 ` Antoine Pelisse [this message]
2012-12-11 22:46   ` [PATCH 4/5] pretty: Use mailmap to display username and email Junio C Hamano
2012-12-12 13:27     ` Antoine Pelisse
2012-12-11 22:21 ` [PATCH 5/5] log: Add --use-mailmap option Antoine Pelisse
2012-12-12 11:58   ` Antoine Pelisse
2012-12-12 17:58     ` Junio C Hamano
2012-12-11 22:33 ` [PATCH 0/5] Allow git log to use mailmap file Junio C Hamano
2012-12-11 22:41   ` Rich Midwinter

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=1355264493-8298-5-git-send-email-apelisse@gmail.com \
    --to=apelisse@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=rich.midwinter@gmail.com \
    /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).