diff options
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | 2006-09-28 17:37:39 +0200 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-09-28 22:32:53 -0700 |
commit | 3ed74e608a69ce0f10bfad2e4ef6cf99eec04613 (patch) | |
tree | 97f0745f0717db4202a638f124fb8e756641d80d /diff.c | |
parent | 5c5b2ea9ab95f71ac155f12d75d1432b5c93c2bb (diff) | |
download | git-3ed74e608a69ce0f10bfad2e4ef6cf99eec04613.tar.gz |
diff --stat: ensure at least one '-' for deletions, and one '+' for additions
The number of '-' and '+' is still linear. The idea is that
scaled-length := floor(a * length + b) with the following constraints: if
length == 1, scaled-length == 1, and the combined length of plusses
and minusses should not be larger than the width by a small margin. Thus,
a + b == 1
and
a * max_plusses + b + a * max_minusses + b = width + 1
The solution is
a * x + b = ((width - 1) * (x - 1) + max_change - 1)
/ (max_change - 1)
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -550,9 +550,12 @@ const char mime_boundary_leader[] = "------------"; static int scale_linear(int it, int width, int max_change) { /* - * round(width * it / max_change); + * make sure that at least one '-' is printed if there were deletions, + * and likewise for '+'. */ - return (it * width * 2 + max_change) / (max_change * 2); + if (max_change < 2) + return it; + return ((it - 1) * (width - 1) + max_change - 1) / (max_change - 1); } static void show_name(const char *prefix, const char *name, int len, @@ -684,9 +687,9 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options) dels += del; if (width <= max_change) { - total = scale_linear(total, width, max_change); add = scale_linear(add, width, max_change); - del = total - add; + del = scale_linear(del, width, max_change); + total = add + del; } show_name(prefix, name, len, reset, set); printf("%5d ", added + deleted); |