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