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

Re: [PATCH] pretty: Add "%aU"|"%au" option to output author's username

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 24, 2019, 02:29 UTC
Message-ID
<xmqqa79qho4v.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20191022234822.f4ixqcpfytimiscn@camp.crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 9 quoted lines
>> +	if (part == 'u' || part == 'U') {	/* username */
>> +		maillen = strstr(s.mail_begin, "@") - s.mail_begin;
>> +		strbuf_add(sb, mail, maillen);
>> +		return placeholder_len;
>> +	}
>
> This branch doesn't appear to do anything different for the mailmap and
> non-mailmap cases.  Perhaps adding an additional test that demonstrates
> the difference would be a good idea.

Yes, and the bug that would be exposed is the lack of call to mailmap.

Perhaps along this line (I may have off-by-one or two tho)?
 pretty.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/pretty.c b/pretty.c
index e4ed14effe..4b76d022c6 100644
--- a/pretty.c
+++ b/pretty.c
@@ -696,15 +696,27 @@ static size_t format_person_part(struct strbuf *sb, char part,
 	mail = s.mail_begin;
 	maillen = s.mail_end - s.mail_begin;
 
-	if (part == 'N' || part == 'E') /* mailmap lookup */
+	if (part == 'N' || part == 'E' || part == 'L') /* mailmap lookup */
 		mailmap_name(&mail, &maillen, &name, &namelen);
-	if (part == 'n' || part == 'N') {	/* name */
+
+	switch (part) {
+	case 'n': case 'N':
 		strbuf_add(sb, name, namelen);
 		return placeholder_len;
-	}
-	if (part == 'e' || part == 'E') {	/* email */
+	case 'l': case 'L':
+		{
+			const char *at = memchr(mail, '@', maillen);
+			if (at) {
+				maillen -= at - mail + 1;
+				mail = at + 1;
+			}
+		}
+		/* fall through */
+	case 'e': case 'E': 
 		strbuf_add(sb, mail, maillen);
 		return placeholder_len;
+	default:
+		break;
 	}
 
 	if (!s.date_begin)
Previous: Prarit BhargavaNext: Prarit Bhargava
Message 6 of 9 in “pretty: Add "%aU"|"%au" option to output author's username”
  1. pretty: Add "%aU"|"%au" option to output author's usernamePrarit Bhargava, Oct 22, 2019
  2. Junio C HamanoOct 22, 2019
  3. Prarit BhargavaOct 23, 2019
  4. brian m. carlsonOct 22, 2019
  5. Prarit BhargavaOct 23, 2019
  6. Junio C HamanoOct 24, 2019
  7. Prarit BhargavaOct 24, 2019
  8. Jeff KingOct 23, 2019
  9. Prarit BhargavaOct 23, 2019

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.