X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=diff.c;h=a1c06b554b80e433dcb735c8e0adf186b6252ae5;hb=200e96e4af5e604174dff2f1487b26d3c42426f1;hp=84780fd5e641d9f1042f82863d1290f7ad8d92b5;hpb=b95ffc143fee155e9ef7ef5e4def38c58febf2ee;p=git.git diff --git a/diff.c b/diff.c index 84780fd5e..a1c06b554 100644 --- a/diff.c +++ b/diff.c @@ -177,11 +177,8 @@ int git_diff_basic_config(const char *var, const char *value, void *cb) return 0; } - switch (userdiff_config(var, value)) { - case 0: break; - case -1: return -1; - default: return 0; - } + if (userdiff_config(var, value) < 0) + return -1; if (!prefixcmp(var, "diff.color.") || !prefixcmp(var, "color.diff.")) { int slot = parse_diff_color_slot(var, 11); @@ -1276,13 +1273,15 @@ const char mime_boundary_leader[] = "------------"; static int scale_linear(int it, int width, int max_change) { + if (!it) + return 0; /* - * make sure that at least one '-' is printed if there were deletions, - * and likewise for '+'. + * make sure that at least one '-' or '+' is printed if + * there is any change to this path. The easiest way is to + * scale linearly as if the alloted width is one column shorter + * than it is, and then add 1 to the result. */ - if (max_change < 2) - return it; - return ((it - 1) * (width - 1) + max_change - 1) / (max_change - 1); + return 1 + (it * (width - 1) / max_change); } static void show_name(FILE *file, @@ -1498,8 +1497,19 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) dels += del; if (width <= max_change) { - add = scale_linear(add, width, max_change); - del = scale_linear(del, width, max_change); + int total = add + del; + + total = scale_linear(add + del, width, max_change); + if (total < 2 && add && del) + /* width >= 2 due to the sanity check */ + total = 2; + if (add < del) { + add = scale_linear(add, width, max_change); + del = total - add; + } else { + del = scale_linear(del, width, max_change); + add = total - del; + } } fprintf(options->file, "%s", line_prefix); show_name(options->file, prefix, name, len);