@@ -1300,6 +1300,7 @@ struct diffstat_t {
1300
1300
unsigned is_unmerged :1 ;
1301
1301
unsigned is_binary :1 ;
1302
1302
unsigned is_renamed :1 ;
1303
+ unsigned is_interesting :1 ;
1303
1304
uintmax_t added , deleted ;
1304
1305
} * * files ;
1305
1306
};
@@ -1469,8 +1470,8 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1469
1470
for (i = 0 ; (i < count ) && (i < data -> nr ); i ++ ) {
1470
1471
struct diffstat_file * file = data -> files [i ];
1471
1472
uintmax_t change = file -> added + file -> deleted ;
1472
- if (! data -> files [ i ] -> is_renamed &&
1473
- (change == 0 )) {
1473
+
1474
+ if (! file -> is_interesting && (change == 0 )) {
1474
1475
count ++ ; /* not shown == room for one more */
1475
1476
continue ;
1476
1477
}
@@ -1497,7 +1498,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1497
1498
if (max_change < change )
1498
1499
max_change = change ;
1499
1500
}
1500
- count = i ; /* min(count, data->nr) */
1501
+ count = i ; /* where we can stop scanning in data->files[] */
1501
1502
1502
1503
/*
1503
1504
* We have width = stat_width or term_columns() columns total.
@@ -1585,16 +1586,15 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1585
1586
*/
1586
1587
for (i = 0 ; i < count ; i ++ ) {
1587
1588
const char * prefix = "" ;
1588
- char * name = data -> files [i ]-> print_name ;
1589
- uintmax_t added = data -> files [i ]-> added ;
1590
- uintmax_t deleted = data -> files [i ]-> deleted ;
1589
+ struct diffstat_file * file = data -> files [i ];
1590
+ char * name = file -> print_name ;
1591
+ uintmax_t added = file -> added ;
1592
+ uintmax_t deleted = file -> deleted ;
1591
1593
int name_len ;
1592
1594
1593
- if (!data -> files [i ]-> is_renamed &&
1594
- (added + deleted == 0 )) {
1595
- total_files -- ;
1595
+ if (!file -> is_interesting && (added + deleted == 0 ))
1596
1596
continue ;
1597
- }
1597
+
1598
1598
/*
1599
1599
* "scale" the filename
1600
1600
*/
@@ -1610,7 +1610,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1610
1610
name = slash ;
1611
1611
}
1612
1612
1613
- if (data -> files [ i ] -> is_binary ) {
1613
+ if (file -> is_binary ) {
1614
1614
fprintf (options -> file , "%s" , line_prefix );
1615
1615
show_name (options -> file , prefix , name , len );
1616
1616
fprintf (options -> file , " %*s" , number_width , "Bin" );
@@ -1627,7 +1627,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1627
1627
fprintf (options -> file , "\n" );
1628
1628
continue ;
1629
1629
}
1630
- else if (data -> files [ i ] -> is_unmerged ) {
1630
+ else if (file -> is_unmerged ) {
1631
1631
fprintf (options -> file , "%s" , line_prefix );
1632
1632
show_name (options -> file , prefix , name , len );
1633
1633
fprintf (options -> file , " Unmerged\n" );
@@ -1639,8 +1639,6 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1639
1639
*/
1640
1640
add = added ;
1641
1641
del = deleted ;
1642
- adds += add ;
1643
- dels += del ;
1644
1642
1645
1643
if (graph_width <= max_change ) {
1646
1644
int total = add + del ;
@@ -1666,16 +1664,24 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1666
1664
show_graph (options -> file , '-' , del , del_c , reset );
1667
1665
fprintf (options -> file , "\n" );
1668
1666
}
1669
- for (i = count ; i < data -> nr ; i ++ ) {
1670
- uintmax_t added = data -> files [i ]-> added ;
1671
- uintmax_t deleted = data -> files [i ]-> deleted ;
1672
- if (!data -> files [i ]-> is_renamed &&
1673
- (added + deleted == 0 )) {
1667
+
1668
+ for (i = 0 ; i < data -> nr ; i ++ ) {
1669
+ struct diffstat_file * file = data -> files [i ];
1670
+ uintmax_t added = file -> added ;
1671
+ uintmax_t deleted = file -> deleted ;
1672
+
1673
+ if (file -> is_unmerged ||
1674
+ (!file -> is_interesting && (added + deleted == 0 ))) {
1674
1675
total_files -- ;
1675
1676
continue ;
1676
1677
}
1677
- adds += added ;
1678
- dels += deleted ;
1678
+
1679
+ if (!file -> is_binary ) {
1680
+ adds += added ;
1681
+ dels += deleted ;
1682
+ }
1683
+ if (i < count )
1684
+ continue ;
1679
1685
if (!extra_shown )
1680
1686
fprintf (options -> file , "%s ...\n" , line_prefix );
1681
1687
extra_shown = 1 ;
@@ -1695,9 +1701,8 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
1695
1701
int added = data -> files [i ]-> added ;
1696
1702
int deleted = data -> files [i ]-> deleted ;
1697
1703
1698
- if (data -> files [i ]-> is_unmerged )
1699
- continue ;
1700
- if (!data -> files [i ]-> is_renamed && (added + deleted == 0 )) {
1704
+ if (data -> files [i ]-> is_unmerged ||
1705
+ (!data -> files [i ]-> is_interesting && (added + deleted == 0 ))) {
1701
1706
total_files -- ;
1702
1707
} else if (!data -> files [i ]-> is_binary ) { /* don't count bytes */
1703
1708
adds += added ;
@@ -2397,13 +2402,20 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
2397
2402
struct diff_filespec * two ,
2398
2403
struct diffstat_t * diffstat ,
2399
2404
struct diff_options * o ,
2400
- int complete_rewrite )
2405
+ struct diff_filepair * p )
2401
2406
{
2402
2407
mmfile_t mf1 , mf2 ;
2403
2408
struct diffstat_file * data ;
2404
2409
int same_contents ;
2410
+ int complete_rewrite = 0 ;
2411
+
2412
+ if (!DIFF_PAIR_UNMERGED (p )) {
2413
+ if (p -> status == DIFF_STATUS_MODIFIED && p -> score )
2414
+ complete_rewrite = 1 ;
2415
+ }
2405
2416
2406
2417
data = diffstat_add (diffstat , name_a , name_b );
2418
+ data -> is_interesting = p -> status != DIFF_STATUS_UNKNOWN ;
2407
2419
2408
2420
if (!one || !two ) {
2409
2421
data -> is_unmerged = 1 ;
@@ -3114,11 +3126,10 @@ static void run_diffstat(struct diff_filepair *p, struct diff_options *o,
3114
3126
{
3115
3127
const char * name ;
3116
3128
const char * other ;
3117
- int complete_rewrite = 0 ;
3118
3129
3119
3130
if (DIFF_PAIR_UNMERGED (p )) {
3120
3131
/* unmerged */
3121
- builtin_diffstat (p -> one -> path , NULL , NULL , NULL , diffstat , o , 0 );
3132
+ builtin_diffstat (p -> one -> path , NULL , NULL , NULL , diffstat , o , p );
3122
3133
return ;
3123
3134
}
3124
3135
@@ -3131,9 +3142,7 @@ static void run_diffstat(struct diff_filepair *p, struct diff_options *o,
3131
3142
diff_fill_sha1_info (p -> one );
3132
3143
diff_fill_sha1_info (p -> two );
3133
3144
3134
- if (p -> status == DIFF_STATUS_MODIFIED && p -> score )
3135
- complete_rewrite = 1 ;
3136
- builtin_diffstat (name , other , p -> one , p -> two , diffstat , o , complete_rewrite );
3145
+ builtin_diffstat (name , other , p -> one , p -> two , diffstat , o , p );
3137
3146
}
3138
3147
3139
3148
static void run_checkdiff (struct diff_filepair * p , struct diff_options * o )
0 commit comments