Re: [PATCH 1/2] diff --stat: use asymptotic scaling in graph

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/12/06, Martin Waitz <tali@xxxxxxxxxxxxxx> wrote:
On Thu, Oct 12, 2006 at 03:37:17PM -0400, apodtele wrote:
> Instead of conditionally scaling the stat graph for large changes,
> always scale it asymptotically: small changes shall appear without any
> distortions.

very nice idea!

> +     return it * width / (it + width) + 1;

but wouldn't this formula result in at least 1, even for a 0 change?
Perhaps we'd have to special case an input of 0?

Corrected patch follows.

--- diff.c	2006-10-12 14:45:13.000000000 -0400
+++ diff.c	2006-10-12 17:32:15.000000000 -0400
@@ -637,15 +637,12 @@

const char mime_boundary_leader[] = "------------";

-static int scale_linear(int it, int width, int max_change)
+static int scale_nonlinear(int it, int width)
{
-	/*
-	 * make sure that at least one '-' is printed if there were deletions,
-	 * and likewise for '+'.
-	 */
-	if (max_change < 2)
-		return it;
-	return ((it - 1) * (width - 1) + max_change - 1) / (max_change - 1);
+	if (it)
+		return it * width / (it + width) + 1;
+	else
+		return 0;
}

static void show_name(const char *prefix, const char *name, int len,
@@ -776,11 +773,9 @@
		adds += add;
		dels += del;

-		if (width <= max_change) {
-			add = scale_linear(add, width, max_change);
-			del = scale_linear(del, width, max_change);
-			total = add + del;
-		}
+		add = scale_nonlinear(add, width / 2);
+		del = scale_nonlinear(del, width / 2);
+		total = add + del;
		show_name(prefix, name, len, reset, set);
		printf("%5d ", added + deleted);
		show_graph('+', add, add_c, reset);
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]