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

[PATCH 1/3] blame: fix email output with mailmap

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Feb 4, 2012, 19:50 UTC
Message-ID
<1328385024-6955-2-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1328385024-6955-1-git-send-email-felipe.contreras@gmail.com>

An extra '>' is added in some cases (<spearce@spearce.org>>), for example:

 % git blame -e -L 947,+7 contrib/completion/git-completion.bash v1.7.9

The current code assumes map_user() *always* returns plain emails, but that's not true; when there's no email substitution (only name), map_user() would return 1, but don't touch the mail.

Also, add some tests.
This got broken by d20d654[1].
[1] Change current mailmap usage to do matching on both name and email
    of author/committer.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/blame.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index 5a67c20..dd69e51 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1403,10 +1403,13 @@ static void get_ac_line(const char *inbuf, const char *what,
 	 * Now, convert both name and e-mail using mailmap
 	 */
 	if (map_user(&mailmap, mail+1, mail_len-1, person, tmp-person-1)) {
-		/* Add a trailing '>' to email, since map_user returns plain emails
-		   Note: It already has '<', since we replace from mail+1 */
+		/*
+		 * Add a trailing '>' to email, since map_user returns plain
+		 * emails when it finds a matching mail.
+		 * Note: It already has '<', since we replace from mail + 1
+		 */
 		mailpos = memchr(mail, '\0', mail_len);
-		if (mailpos && mailpos-mail < mail_len - 1) {
+		if (mailpos && mailpos-mail < mail_len - 1 && *(mailpos - 1) != '>') {
 			*mailpos = '>';
 			*(mailpos+1) = '\0';
 		}
-- 
1.7.9.1.g97f7d
Previous: Felipe ContrerasNext: Jeff King
Message 2 of 22 in “blame: fix output with mailmap”
  1. 0/3 blame: fix output with mailmapFelipe Contreras, Feb 4, 2012
  2. 1/3 blame: fix email output with mailmapFelipe Contreras, Feb 4, 2012
  3. Jeff KingFeb 4, 2012
  4. Thomas RastFeb 5, 2012
  5. Felipe ContrerasFeb 5, 2012
  6. Jeff KingFeb 6, 2012
  7. 2/3 t: mailmap: add 'git blame -e' testsFelipe Contreras, Feb 4, 2012
  8. Jonathan NiederFeb 4, 2012
  9. Felipe ContrerasFeb 4, 2012
  10. Jonathan NiederFeb 4, 2012
  11. Felipe ContrerasFeb 4, 2012
  12. Junio C HamanoFeb 5, 2012
  13. Felipe ContrerasFeb 5, 2012
  14. 3/3 t: mailmap: add simple name translation testFelipe Contreras, Feb 4, 2012
  15. Jonathan NiederFeb 4, 2012
  16. Felipe ContrerasFeb 4, 2012
  17. Jonathan NiederFeb 4, 2012
  18. Felipe ContrerasFeb 4, 2012
  19. Jeff KingFeb 4, 2012
  20. Felipe ContrerasFeb 6, 2012
  21. Jonathan NiederFeb 5, 2012
  22. Felipe ContrerasFeb 6, 2012

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.