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 <apelisse@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Antoine Pelisse committed
Jan 5, 2013 at 22:26 UTC
dffd325f379b825ca449e1592fa9fb31eddf1780
1 file changed
+37
-21
pretty.c
+37
-21
@@ -387,9 +387,13 @@ void pp_user_info(const struct pretty_print_context *pp,
387
const char *what, struct strbuf *sb,
388
const char *line, const char *encoding)
389
{
390
+ struct strbuf name;
391
+ struct strbuf mail;
392
struct ident_split ident;
391
- int linelen, namelen;
393
+ int linelen;
394
char *line_end, *date;
395
+ const char *mailbuf, *namebuf;
396
+ size_t namelen, maillen;
397
int max_length = 78; /* per rfc2822 */
398
unsigned long time;
399
int tz;
@@ -408,42 +412,54 @@ void pp_user_info(const struct pretty_print_context *pp,
412
if (split_ident_line(&ident, line, linelen))
413
return;
414
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; /* ' ' + '<' + '>' */
431
time = strtoul(ident.date_begin, &date, 10);
432
tz = strtol(date, NULL, 10);
433
434
if (pp->fmt == CMIT_FMT_EMAIL) {
416
- int display_name_length;
417
-
418
- display_name_length = ident.name_end - ident.name_begin;
419
-
435
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);
439
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)) {
441
struct strbuf quoted = STRBUF_INIT;
427
- add_rfc822_quoted("ed, line, display_name_length);
442
+ add_rfc822_quoted("ed, name.buf, name.len);
443
strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len,
444
-6, 1, max_length);
445
strbuf_release("ed);
446
} 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);
449
}
435
- if (namelen - display_name_length + last_line_length(sb) > max_length) {
450
+ if (namelen - name.len + last_line_length(sb) > max_length)
451
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);
454
} else {
443
- strbuf_addf(sb, "%s: %.*s%.*s\n", what,
455
+ strbuf_addf(sb, "%s: %.*s%s <%s>\n", what,
456
(pp->fmt == CMIT_FMT_FULLER) ? 4 : 0,
445
- " ", namelen, line);
457
+ " ", name.buf, mail.buf);
458
}
459
+
460
+ strbuf_release(&mail);
461
+ strbuf_release(&name);
462
+
463
switch (pp->fmt) {
464
case CMIT_FMT_MEDIUM:
465
strbuf_addf(sb, "Date: %s\n", show_date(time, tz, pp->date_mode));