@@ -410,10 +410,7 @@ void pp_user_info(const struct pretty_print_context *pp,
410
410
const char * what , struct strbuf * sb ,
411
411
const char * line , const char * encoding )
412
412
{
413
- struct strbuf name ;
414
- struct strbuf mail ;
415
413
struct ident_split ident ;
416
- int linelen ;
417
414
char * line_end ;
418
415
const char * mailbuf , * namebuf ;
419
416
size_t namelen , maillen ;
@@ -422,18 +419,10 @@ void pp_user_info(const struct pretty_print_context *pp,
422
419
if (pp -> fmt == CMIT_FMT_ONELINE )
423
420
return ;
424
421
425
- line_end = strchr (line , '\n' );
426
- if (!line_end ) {
427
- line_end = strchr (line , '\0' );
428
- if (!line_end )
429
- return ;
430
- }
431
-
432
- linelen = ++ line_end - line ;
433
- if (split_ident_line (& ident , line , linelen ))
422
+ line_end = strchrnul (line , '\n' );
423
+ if (split_ident_line (& ident , line , line_end - line ))
434
424
return ;
435
425
436
-
437
426
mailbuf = ident .mail_begin ;
438
427
maillen = ident .mail_end - ident .mail_begin ;
439
428
namebuf = ident .name_begin ;
@@ -442,43 +431,33 @@ void pp_user_info(const struct pretty_print_context *pp,
442
431
if (pp -> mailmap )
443
432
map_user (pp -> mailmap , & mailbuf , & maillen , & namebuf , & namelen );
444
433
445
- strbuf_init (& mail , 0 );
446
- strbuf_init (& name , 0 );
447
-
448
- strbuf_add (& mail , mailbuf , maillen );
449
- strbuf_add (& name , namebuf , namelen );
450
-
451
- namelen = name .len + mail .len + 3 ; /* ' ' + '<' + '>' */
452
-
453
434
if (pp -> fmt == CMIT_FMT_EMAIL ) {
454
435
strbuf_addstr (sb , "From: " );
455
- if (needs_rfc2047_encoding (name . buf , name . len , RFC2047_ADDRESS )) {
456
- add_rfc2047 (sb , name . buf , name . len ,
436
+ if (needs_rfc2047_encoding (namebuf , namelen , RFC2047_ADDRESS )) {
437
+ add_rfc2047 (sb , namebuf , namelen ,
457
438
encoding , RFC2047_ADDRESS );
458
439
max_length = 76 ; /* per rfc2047 */
459
- } else if (needs_rfc822_quoting (name . buf , name . len )) {
440
+ } else if (needs_rfc822_quoting (namebuf , namelen )) {
460
441
struct strbuf quoted = STRBUF_INIT ;
461
- add_rfc822_quoted (& quoted , name . buf , name . len );
442
+ add_rfc822_quoted (& quoted , namebuf , namelen );
462
443
strbuf_add_wrapped_bytes (sb , quoted .buf , quoted .len ,
463
444
-6 , 1 , max_length );
464
445
strbuf_release (& quoted );
465
446
} else {
466
- strbuf_add_wrapped_bytes (sb , name . buf , name . len ,
447
+ strbuf_add_wrapped_bytes (sb , namebuf , namelen ,
467
448
-6 , 1 , max_length );
468
449
}
469
- if (namelen - name .len + last_line_length (sb ) > max_length )
470
- strbuf_addch (sb , '\n' );
471
450
472
- strbuf_addf (sb , " <%s>\n" , mail .buf );
451
+ if (max_length <
452
+ last_line_length (sb ) + strlen (" <" ) + maillen + strlen (">" ))
453
+ strbuf_addch (sb , '\n' );
454
+ strbuf_addf (sb , " <%.*s>\n" , (int )maillen , mailbuf );
473
455
} else {
474
- strbuf_addf (sb , "%s: %.*s%s <%s>\n" , what ,
475
- (pp -> fmt == CMIT_FMT_FULLER ) ? 4 : 0 ,
476
- " " , name . buf , mail . buf );
456
+ strbuf_addf (sb , "%s: %.*s%.* s <%.* s>\n" , what ,
457
+ (pp -> fmt == CMIT_FMT_FULLER ) ? 4 : 0 , " " ,
458
+ ( int ) namelen , namebuf , ( int ) maillen , mailbuf );
477
459
}
478
460
479
- strbuf_release (& mail );
480
- strbuf_release (& name );
481
-
482
461
switch (pp -> fmt ) {
483
462
case CMIT_FMT_MEDIUM :
484
463
strbuf_addf (sb , "Date: %s\n" ,
0 commit comments