Skip to content

Commit dffd325

Browse files
apelissegitster
authored andcommitted
pretty: use mailmap to display username and email
Use the mailmap information to display the rewritten username and email address in all log commands. Signed-off-by: Antoine Pelisse <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0e2913b commit dffd325

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

pretty.c

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,13 @@ void pp_user_info(const struct pretty_print_context *pp,
387387
const char *what, struct strbuf *sb,
388388
const char *line, const char *encoding)
389389
{
390+
struct strbuf name;
391+
struct strbuf mail;
390392
struct ident_split ident;
391-
int linelen, namelen;
393+
int linelen;
392394
char *line_end, *date;
395+
const char *mailbuf, *namebuf;
396+
size_t namelen, maillen;
393397
int max_length = 78; /* per rfc2822 */
394398
unsigned long time;
395399
int tz;
@@ -408,42 +412,54 @@ void pp_user_info(const struct pretty_print_context *pp,
408412
if (split_ident_line(&ident, line, linelen))
409413
return;
410414

411-
namelen = ident.mail_end - ident.name_begin + 1;
415+
416+
mailbuf = ident.mail_begin;
417+
maillen = ident.mail_end - ident.mail_begin;
418+
namebuf = ident.name_begin;
419+
namelen = ident.name_end - ident.name_begin;
420+
421+
if (pp->mailmap)
422+
map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen);
423+
424+
strbuf_init(&mail, 0);
425+
strbuf_init(&name, 0);
426+
427+
strbuf_add(&mail, mailbuf, maillen);
428+
strbuf_add(&name, namebuf, namelen);
429+
430+
namelen = name.len + mail.len + 3; /* ' ' + '<' + '>' */
412431
time = strtoul(ident.date_begin, &date, 10);
413432
tz = strtol(date, NULL, 10);
414433

415434
if (pp->fmt == CMIT_FMT_EMAIL) {
416-
int display_name_length;
417-
418-
display_name_length = ident.name_end - ident.name_begin;
419-
420435
strbuf_addstr(sb, "From: ");
421-
if (needs_rfc2047_encoding(line, display_name_length, RFC2047_ADDRESS)) {
422-
add_rfc2047(sb, line, display_name_length,
423-
encoding, RFC2047_ADDRESS);
436+
if (needs_rfc2047_encoding(name.buf, name.len, RFC2047_ADDRESS)) {
437+
add_rfc2047(sb, name.buf, name.len,
438+
encoding, RFC2047_ADDRESS);
424439
max_length = 76; /* per rfc2047 */
425-
} else if (needs_rfc822_quoting(line, display_name_length)) {
440+
} else if (needs_rfc822_quoting(name.buf, name.len)) {
426441
struct strbuf quoted = STRBUF_INIT;
427-
add_rfc822_quoted(&quoted, line, display_name_length);
442+
add_rfc822_quoted(&quoted, name.buf, name.len);
428443
strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len,
429444
-6, 1, max_length);
430445
strbuf_release(&quoted);
431446
} else {
432-
strbuf_add_wrapped_bytes(sb, line, display_name_length,
433-
-6, 1, max_length);
447+
strbuf_add_wrapped_bytes(sb, name.buf, name.len,
448+
-6, 1, max_length);
434449
}
435-
if (namelen - display_name_length + last_line_length(sb) > max_length) {
450+
if (namelen - name.len + last_line_length(sb) > max_length)
436451
strbuf_addch(sb, '\n');
437-
if (!isspace(ident.name_end[0]))
438-
strbuf_addch(sb, ' ');
439-
}
440-
strbuf_add(sb, ident.name_end, namelen - display_name_length);
441-
strbuf_addch(sb, '\n');
452+
453+
strbuf_addf(sb, " <%s>\n", mail.buf);
442454
} else {
443-
strbuf_addf(sb, "%s: %.*s%.*s\n", what,
455+
strbuf_addf(sb, "%s: %.*s%s <%s>\n", what,
444456
(pp->fmt == CMIT_FMT_FULLER) ? 4 : 0,
445-
" ", namelen, line);
457+
" ", name.buf, mail.buf);
446458
}
459+
460+
strbuf_release(&mail);
461+
strbuf_release(&name);
462+
447463
switch (pp->fmt) {
448464
case CMIT_FMT_MEDIUM:
449465
strbuf_addf(sb, "Date: %s\n", show_date(time, tz, pp->date_mode));

0 commit comments

Comments
 (0)