@@ -1497,8 +1497,8 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1497
1497
for (i = 0 ; (i < count ) && (i < data -> nr ); i ++ ) {
1498
1498
struct diffstat_file * file = data -> files [i ];
1499
1499
uintmax_t change = file -> added + file -> deleted ;
1500
- if (! data -> files [ i ] -> is_interesting &&
1501
- (change == 0 )) {
1500
+
1501
+ if (! file -> is_interesting && (change == 0 )) {
1502
1502
count ++ ; /* not shown == room for one more */
1503
1503
continue ;
1504
1504
}
@@ -1525,7 +1525,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1525
1525
if (max_change < change )
1526
1526
max_change = change ;
1527
1527
}
1528
- count = i ; /* min(count, data->nr) */
1528
+ count = i ; /* where we can stop scanning in data->files[] */
1529
1529
1530
1530
/*
1531
1531
* We have width = stat_width or term_columns() columns total.
@@ -1613,16 +1613,15 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1613
1613
*/
1614
1614
for (i = 0 ; i < count ; i ++ ) {
1615
1615
const char * prefix = "" ;
1616
- char * name = data -> files [i ]-> print_name ;
1617
- uintmax_t added = data -> files [i ]-> added ;
1618
- uintmax_t deleted = data -> files [i ]-> deleted ;
1616
+ struct diffstat_file * file = data -> files [i ];
1617
+ char * name = file -> print_name ;
1618
+ uintmax_t added = file -> added ;
1619
+ uintmax_t deleted = file -> deleted ;
1619
1620
int name_len ;
1620
1621
1621
- if (!data -> files [i ]-> is_interesting &&
1622
- (added + deleted == 0 )) {
1623
- total_files -- ;
1622
+ if (!file -> is_interesting && (added + deleted == 0 ))
1624
1623
continue ;
1625
- }
1624
+
1626
1625
/*
1627
1626
* "scale" the filename
1628
1627
*/
@@ -1638,7 +1637,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1638
1637
name = slash ;
1639
1638
}
1640
1639
1641
- if (data -> files [ i ] -> is_binary ) {
1640
+ if (file -> is_binary ) {
1642
1641
fprintf (options -> file , "%s" , line_prefix );
1643
1642
show_name (options -> file , prefix , name , len );
1644
1643
fprintf (options -> file , " %*s" , number_width , "Bin" );
@@ -1655,7 +1654,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1655
1654
fprintf (options -> file , "\n" );
1656
1655
continue ;
1657
1656
}
1658
- else if (data -> files [ i ] -> is_unmerged ) {
1657
+ else if (file -> is_unmerged ) {
1659
1658
fprintf (options -> file , "%s" , line_prefix );
1660
1659
show_name (options -> file , prefix , name , len );
1661
1660
fprintf (options -> file , " Unmerged\n" );
@@ -1667,8 +1666,6 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1667
1666
*/
1668
1667
add = added ;
1669
1668
del = deleted ;
1670
- adds += add ;
1671
- dels += del ;
1672
1669
1673
1670
if (graph_width <= max_change ) {
1674
1671
int total = add + del ;
@@ -1694,16 +1691,24 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1694
1691
show_graph (options -> file , '-' , del , del_c , reset );
1695
1692
fprintf (options -> file , "\n" );
1696
1693
}
1697
- for (i = count ; i < data -> nr ; i ++ ) {
1698
- uintmax_t added = data -> files [i ]-> added ;
1699
- uintmax_t deleted = data -> files [i ]-> deleted ;
1700
- if (!data -> files [i ]-> is_interesting &&
1701
- (added + deleted == 0 )) {
1694
+
1695
+ for (i = 0 ; i < data -> nr ; i ++ ) {
1696
+ struct diffstat_file * file = data -> files [i ];
1697
+ uintmax_t added = file -> added ;
1698
+ uintmax_t deleted = file -> deleted ;
1699
+
1700
+ if (file -> is_unmerged ||
1701
+ (!file -> is_interesting && (added + deleted == 0 ))) {
1702
1702
total_files -- ;
1703
1703
continue ;
1704
1704
}
1705
- adds += added ;
1706
- dels += deleted ;
1705
+
1706
+ if (!file -> is_binary ) {
1707
+ adds += added ;
1708
+ dels += deleted ;
1709
+ }
1710
+ if (i < count )
1711
+ continue ;
1707
1712
if (!extra_shown )
1708
1713
fprintf (options -> file , "%s ...\n" , line_prefix );
1709
1714
extra_shown = 1 ;
@@ -1723,9 +1728,8 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
1723
1728
int added = data -> files [i ]-> added ;
1724
1729
int deleted = data -> files [i ]-> deleted ;
1725
1730
1726
- if (data -> files [i ]-> is_unmerged )
1727
- continue ;
1728
- if (!data -> files [i ]-> is_interesting && (added + deleted == 0 )) {
1731
+ if (data -> files [i ]-> is_unmerged ||
1732
+ (!data -> files [i ]-> is_interesting && (added + deleted == 0 ))) {
1729
1733
total_files -- ;
1730
1734
} else if (!data -> files [i ]-> is_binary ) { /* don't count bytes */
1731
1735
adds += added ;
@@ -2438,7 +2442,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
2438
2442
}
2439
2443
2440
2444
data = diffstat_add (diffstat , name_a , name_b );
2441
- data -> is_interesting = p -> status != 0 ;
2445
+ data -> is_interesting = p -> status != DIFF_STATUS_UNKNOWN ;
2442
2446
2443
2447
if (!one || !two ) {
2444
2448
data -> is_unmerged = 1 ;
0 commit comments