@@ -1276,13 +1276,15 @@ const char mime_boundary_leader[] = "------------";
1276
1276
1277
1277
static int scale_linear (int it , int width , int max_change )
1278
1278
{
1279
+ if (!it )
1280
+ return 0 ;
1279
1281
/*
1280
- * make sure that at least one '-' is printed if there were deletions,
1281
- * and likewise for '+'.
1282
+ * make sure that at least one '-' or '+' is printed if
1283
+ * there is any change to this path. The easiest way is to
1284
+ * scale linearly as if the alloted width is one column shorter
1285
+ * than it is, and then add 1 to the result.
1282
1286
*/
1283
- if (max_change < 2 )
1284
- return it ;
1285
- return ((it - 1 ) * (width - 1 ) + max_change - 1 ) / (max_change - 1 );
1287
+ return 1 + (it * (width - 1 ) / max_change );
1286
1288
}
1287
1289
1288
1290
static void show_name (FILE * file ,
@@ -1498,8 +1500,19 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1498
1500
dels += del ;
1499
1501
1500
1502
if (width <= max_change ) {
1501
- add = scale_linear (add , width , max_change );
1502
- del = scale_linear (del , width , max_change );
1503
+ int total = add + del ;
1504
+
1505
+ total = scale_linear (add + del , width , max_change );
1506
+ if (total < 2 && add && del )
1507
+ /* width >= 2 due to the sanity check */
1508
+ total = 2 ;
1509
+ if (add < del ) {
1510
+ add = scale_linear (add , width , max_change );
1511
+ del = total - add ;
1512
+ } else {
1513
+ del = scale_linear (del , width , max_change );
1514
+ add = total - del ;
1515
+ }
1503
1516
}
1504
1517
fprintf (options -> file , "%s" , line_prefix );
1505
1518
show_name (options -> file , prefix , name , len );
0 commit comments