summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5c5b2ea)
raw | patch | inline | side by side (parent: 5c5b2ea)
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | |
Thu, 28 Sep 2006 15:37:39 +0000 (17:37 +0200) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Fri, 29 Sep 2006 05:32:53 +0000 (22:32 -0700) |
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>
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>
diff.c | patch | blob | history |
index 90e0844108e7e8765cbe1b5f4d6620c1fe2db115..2df085f3c67afd96b5fcea5ade6f45c5e330198b 100644 (file)
--- a/diff.c
+++ b/diff.c
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,
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);