@@ -1322,30 +1322,31 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
1322
1322
* Information on commits, used for output.
1323
1323
*/
1324
1324
struct commit_info {
1325
- const char * author ;
1326
- const char * author_mail ;
1325
+ struct strbuf author ;
1326
+ struct strbuf author_mail ;
1327
1327
unsigned long author_time ;
1328
- const char * author_tz ;
1328
+ struct strbuf author_tz ;
1329
1329
1330
1330
/* filled only when asked for details */
1331
- const char * committer ;
1332
- const char * committer_mail ;
1331
+ struct strbuf committer ;
1332
+ struct strbuf committer_mail ;
1333
1333
unsigned long committer_time ;
1334
- const char * committer_tz ;
1334
+ struct strbuf committer_tz ;
1335
1335
1336
- const char * summary ;
1336
+ struct strbuf summary ;
1337
1337
};
1338
1338
1339
1339
/*
1340
1340
* Parse author/committer line in the commit object buffer
1341
1341
*/
1342
1342
static void get_ac_line (const char * inbuf , const char * what ,
1343
- int person_len , char * person ,
1344
- int mail_len , char * mail ,
1345
- unsigned long * time , const char * * tz )
1343
+ struct strbuf * name , struct strbuf * mail ,
1344
+ unsigned long * time , struct strbuf * tz )
1346
1345
{
1347
- int len , tzlen , maillen ;
1348
- char * tmp , * endp , * timepos , * mailpos ;
1346
+ struct ident_split ident ;
1347
+ size_t len , maillen , namelen ;
1348
+ char * tmp , * endp ;
1349
+ const char * namebuf , * mailbuf ;
1349
1350
1350
1351
tmp = strstr (inbuf , what );
1351
1352
if (!tmp )
@@ -1356,69 +1357,61 @@ static void get_ac_line(const char *inbuf, const char *what,
1356
1357
len = strlen (tmp );
1357
1358
else
1358
1359
len = endp - tmp ;
1359
- if (person_len <= len ) {
1360
+
1361
+ if (split_ident_line (& ident , tmp , len )) {
1360
1362
error_out :
1361
1363
/* Ugh */
1362
- * tz = "(unknown)" ;
1363
- strcpy (person , * tz );
1364
- strcpy (mail , * tz );
1364
+ tmp = "(unknown)" ;
1365
+ strbuf_addstr (name , tmp );
1366
+ strbuf_addstr (mail , tmp );
1367
+ strbuf_addstr (tz , tmp );
1365
1368
* time = 0 ;
1366
1369
return ;
1367
1370
}
1368
- memcpy (person , tmp , len );
1369
1371
1370
- tmp = person ;
1371
- tmp += len ;
1372
- * tmp = 0 ;
1373
- while (person < tmp && * tmp != ' ' )
1374
- tmp -- ;
1375
- if (tmp <= person )
1376
- goto error_out ;
1377
- * tz = tmp + 1 ;
1378
- tzlen = (person + len )- (tmp + 1 );
1372
+ namelen = ident .name_end - ident .name_begin ;
1373
+ namebuf = ident .name_begin ;
1379
1374
1380
- * tmp = 0 ;
1381
- while (person < tmp && * tmp != ' ' )
1382
- tmp -- ;
1383
- if (tmp <= person )
1384
- goto error_out ;
1385
- * time = strtoul (tmp , NULL , 10 );
1386
- timepos = tmp ;
1375
+ maillen = ident .mail_end - ident .mail_begin ;
1376
+ mailbuf = ident .mail_begin ;
1387
1377
1388
- * tmp = 0 ;
1389
- while (person < tmp && !(* tmp == ' ' && tmp [1 ] == '<' ))
1390
- tmp -- ;
1391
- if (tmp <= person )
1392
- return ;
1393
- mailpos = tmp + 1 ;
1394
- * tmp = 0 ;
1395
- maillen = timepos - tmp ;
1396
- memcpy (mail , mailpos , maillen );
1378
+ * time = strtoul (ident .date_begin , NULL , 10 );
1397
1379
1398
- if (!mailmap .nr )
1399
- return ;
1400
-
1401
- /*
1402
- * mailmap expansion may make the name longer.
1403
- * make room by pushing stuff down.
1404
- */
1405
- tmp = person + person_len - (tzlen + 1 );
1406
- memmove (tmp , * tz , tzlen );
1407
- tmp [tzlen ] = 0 ;
1408
- * tz = tmp ;
1380
+ len = ident .tz_end - ident .tz_begin ;
1381
+ strbuf_add (tz , ident .tz_begin , len );
1409
1382
1410
1383
/*
1411
1384
* Now, convert both name and e-mail using mailmap
1412
1385
*/
1413
- if (map_user (& mailmap , mail + 1 , mail_len - 1 , person , tmp - person - 1 )) {
1414
- /* Add a trailing '>' to email, since map_user returns plain emails
1415
- Note: It already has '<', since we replace from mail+1 */
1416
- mailpos = memchr (mail , '\0' , mail_len );
1417
- if (mailpos && mailpos - mail < mail_len - 1 ) {
1418
- * mailpos = '>' ;
1419
- * (mailpos + 1 ) = '\0' ;
1420
- }
1421
- }
1386
+ map_user (& mailmap , & mailbuf , & maillen ,
1387
+ & namebuf , & namelen );
1388
+
1389
+ strbuf_addf (mail , "<%.*s>" , (int )maillen , mailbuf );
1390
+ strbuf_add (name , namebuf , namelen );
1391
+ }
1392
+
1393
+ static void commit_info_init (struct commit_info * ci )
1394
+ {
1395
+
1396
+ strbuf_init (& ci -> author , 0 );
1397
+ strbuf_init (& ci -> author_mail , 0 );
1398
+ strbuf_init (& ci -> author_tz , 0 );
1399
+ strbuf_init (& ci -> committer , 0 );
1400
+ strbuf_init (& ci -> committer_mail , 0 );
1401
+ strbuf_init (& ci -> committer_tz , 0 );
1402
+ strbuf_init (& ci -> summary , 0 );
1403
+ }
1404
+
1405
+ static void commit_info_destroy (struct commit_info * ci )
1406
+ {
1407
+
1408
+ strbuf_release (& ci -> author );
1409
+ strbuf_release (& ci -> author_mail );
1410
+ strbuf_release (& ci -> author_tz );
1411
+ strbuf_release (& ci -> committer );
1412
+ strbuf_release (& ci -> committer_mail );
1413
+ strbuf_release (& ci -> committer_tz );
1414
+ strbuf_release (& ci -> summary );
1422
1415
}
1423
1416
1424
1417
static void get_commit_info (struct commit * commit ,
@@ -1428,11 +1421,8 @@ static void get_commit_info(struct commit *commit,
1428
1421
int len ;
1429
1422
const char * subject , * encoding ;
1430
1423
char * reencoded , * message ;
1431
- static char author_name [1024 ];
1432
- static char author_mail [1024 ];
1433
- static char committer_name [1024 ];
1434
- static char committer_mail [1024 ];
1435
- static char summary_buf [1024 ];
1424
+
1425
+ commit_info_init (ret );
1436
1426
1437
1427
/*
1438
1428
* We've operated without save_commit_buffer, so
@@ -1450,33 +1440,25 @@ static void get_commit_info(struct commit *commit,
1450
1440
encoding = get_log_output_encoding ();
1451
1441
reencoded = logmsg_reencode (commit , encoding );
1452
1442
message = reencoded ? reencoded : commit -> buffer ;
1453
- ret -> author = author_name ;
1454
- ret -> author_mail = author_mail ;
1455
1443
get_ac_line (message , "\nauthor " ,
1456
- sizeof (author_name ), author_name ,
1457
- sizeof (author_mail ), author_mail ,
1444
+ & ret -> author , & ret -> author_mail ,
1458
1445
& ret -> author_time , & ret -> author_tz );
1459
1446
1460
1447
if (!detailed ) {
1461
1448
free (reencoded );
1462
1449
return ;
1463
1450
}
1464
1451
1465
- ret -> committer = committer_name ;
1466
- ret -> committer_mail = committer_mail ;
1467
1452
get_ac_line (message , "\ncommitter " ,
1468
- sizeof (committer_name ), committer_name ,
1469
- sizeof (committer_mail ), committer_mail ,
1453
+ & ret -> committer , & ret -> committer_mail ,
1470
1454
& ret -> committer_time , & ret -> committer_tz );
1471
1455
1472
- ret -> summary = summary_buf ;
1473
1456
len = find_commit_subject (message , & subject );
1474
- if (len && len < sizeof (summary_buf )) {
1475
- memcpy (summary_buf , subject , len );
1476
- summary_buf [len ] = 0 ;
1477
- } else {
1478
- sprintf (summary_buf , "(%s)" , sha1_to_hex (commit -> object .sha1 ));
1479
- }
1457
+ if (len )
1458
+ strbuf_add (& ret -> summary , subject , len );
1459
+ else
1460
+ strbuf_addf (& ret -> summary , "(%s)" , sha1_to_hex (commit -> object .sha1 ));
1461
+
1480
1462
free (reencoded );
1481
1463
}
1482
1464
@@ -1505,22 +1487,25 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat)
1505
1487
1506
1488
suspect -> commit -> object .flags |= METAINFO_SHOWN ;
1507
1489
get_commit_info (suspect -> commit , & ci , 1 );
1508
- printf ("author %s\n" , ci .author );
1509
- printf ("author-mail %s\n" , ci .author_mail );
1490
+ printf ("author %s\n" , ci .author . buf );
1491
+ printf ("author-mail %s\n" , ci .author_mail . buf );
1510
1492
printf ("author-time %lu\n" , ci .author_time );
1511
- printf ("author-tz %s\n" , ci .author_tz );
1512
- printf ("committer %s\n" , ci .committer );
1513
- printf ("committer-mail %s\n" , ci .committer_mail );
1493
+ printf ("author-tz %s\n" , ci .author_tz . buf );
1494
+ printf ("committer %s\n" , ci .committer . buf );
1495
+ printf ("committer-mail %s\n" , ci .committer_mail . buf );
1514
1496
printf ("committer-time %lu\n" , ci .committer_time );
1515
- printf ("committer-tz %s\n" , ci .committer_tz );
1516
- printf ("summary %s\n" , ci .summary );
1497
+ printf ("committer-tz %s\n" , ci .committer_tz . buf );
1498
+ printf ("summary %s\n" , ci .summary . buf );
1517
1499
if (suspect -> commit -> object .flags & UNINTERESTING )
1518
1500
printf ("boundary\n" );
1519
1501
if (suspect -> previous ) {
1520
1502
struct origin * prev = suspect -> previous ;
1521
1503
printf ("previous %s " , sha1_to_hex (prev -> commit -> object .sha1 ));
1522
1504
write_name_quoted (prev -> path , stdout , '\n' );
1523
1505
}
1506
+
1507
+ commit_info_destroy (& ci );
1508
+
1524
1509
return 1 ;
1525
1510
}
1526
1511
@@ -1707,11 +1692,11 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
1707
1692
if (opt & OUTPUT_ANNOTATE_COMPAT ) {
1708
1693
const char * name ;
1709
1694
if (opt & OUTPUT_SHOW_EMAIL )
1710
- name = ci .author_mail ;
1695
+ name = ci .author_mail . buf ;
1711
1696
else
1712
- name = ci .author ;
1697
+ name = ci .author . buf ;
1713
1698
printf ("\t(%10s\t%10s\t%d)" , name ,
1714
- format_time (ci .author_time , ci .author_tz ,
1699
+ format_time (ci .author_time , ci .author_tz . buf ,
1715
1700
show_raw_time ),
1716
1701
ent -> lno + 1 + cnt );
1717
1702
} else {
@@ -1730,14 +1715,14 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
1730
1715
const char * name ;
1731
1716
int pad ;
1732
1717
if (opt & OUTPUT_SHOW_EMAIL )
1733
- name = ci .author_mail ;
1718
+ name = ci .author_mail . buf ;
1734
1719
else
1735
- name = ci .author ;
1720
+ name = ci .author . buf ;
1736
1721
pad = longest_author - utf8_strwidth (name );
1737
1722
printf (" (%s%*s %10s" ,
1738
1723
name , pad , "" ,
1739
1724
format_time (ci .author_time ,
1740
- ci .author_tz ,
1725
+ ci .author_tz . buf ,
1741
1726
show_raw_time ));
1742
1727
}
1743
1728
printf (" %*d) " ,
@@ -1752,6 +1737,8 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
1752
1737
1753
1738
if (sb -> final_buf_size && cp [-1 ] != '\n' )
1754
1739
putchar ('\n' );
1740
+
1741
+ commit_info_destroy (& ci );
1755
1742
}
1756
1743
1757
1744
static void output (struct scoreboard * sb , int option )
@@ -1876,9 +1863,9 @@ static void find_alignment(struct scoreboard *sb, int *option)
1876
1863
suspect -> commit -> object .flags |= METAINFO_SHOWN ;
1877
1864
get_commit_info (suspect -> commit , & ci , 1 );
1878
1865
if (* option & OUTPUT_SHOW_EMAIL )
1879
- num = utf8_strwidth (ci .author_mail );
1866
+ num = utf8_strwidth (ci .author_mail . buf );
1880
1867
else
1881
- num = utf8_strwidth (ci .author );
1868
+ num = utf8_strwidth (ci .author . buf );
1882
1869
if (longest_author < num )
1883
1870
longest_author = num ;
1884
1871
}
@@ -1890,6 +1877,8 @@ static void find_alignment(struct scoreboard *sb, int *option)
1890
1877
longest_dst_lines = num ;
1891
1878
if (largest_score < ent_score (sb , e ))
1892
1879
largest_score = ent_score (sb , e );
1880
+
1881
+ commit_info_destroy (& ci );
1893
1882
}
1894
1883
max_orig_digits = decimal_width (longest_src_lines );
1895
1884
max_digits = decimal_width (longest_dst_lines );
0 commit comments