@@ -1276,13 +1276,15 @@ const char mime_boundary_leader[] = "------------";
12761276
12771277static int scale_linear (int it , int width , int max_change )
12781278{
1279+ if (!it )
1280+ return 0 ;
12791281 /*
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.
12821286 */
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 );
12861288}
12871289
12881290static void show_name (FILE * file ,
@@ -1498,8 +1500,19 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
14981500 dels += del ;
14991501
15001502 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+ }
15031516 }
15041517 fprintf (options -> file , "%s" , line_prefix );
15051518 show_name (options -> file , prefix , name , len );
0 commit comments