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)