summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-02-20 08:15:15 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-02-20 08:15:15 (GMT)
commit8c60fcbcfd39390c0fbf3d49974bf0029ef4d9c6 (patch)
tree055438fdee58366b592799598f34b2883ab3015c /diff.c
parent4d9e079e826c9b51b610260564111fa8385f7581 (diff)
parent2eeeef24ff5a6538f41f5fe44f3a4e7f6e36e7e5 (diff)
downloadgit-8c60fcbcfd39390c0fbf3d49974bf0029ef4d9c6.zip
git-8c60fcbcfd39390c0fbf3d49974bf0029ef4d9c6.tar.gz
git-8c60fcbcfd39390c0fbf3d49974bf0029ef4d9c6.tar.bz2
Merge branch 'jc/diff-stat-scaler'
* jc/diff-stat-scaler: diff --stat: show bars of same length for paths with same amount of changes
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/diff.c b/diff.c
index 3550c18..a1c06b5 100644
--- a/diff.c
+++ b/diff.c
@@ -1273,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,
@@ -1495,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);