Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15
  • (off-list ancestor, not in this archive)
  • Re: diff --stat · Junio C Hamano <hidden> · 2016-06-15
  • Re: diff --stat · Jeff King <hidden> · 2016-06-15

Re: diff --stat

From: Jeff King <hidden>
Date: 2016-06-15 22:53:04

Possibly related (same subject, not in this thread)

On Tue, Feb 14, 2012 at 01:49:11PM -0800, Junio C Hamano wrote:
 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 all the quantities were one smaller
+	 * than they actually are, and then add one to the result.
 	 */
 	if (max_change < 2)
-		return it;
-	return ((it - 1) * (width - 1) + max_change - 1) / (max_change - 1);
+		return 1;
+	return 1 + ((it - 1) * (width - 1) / (max_change - 1));
I'm not sure I understand why the "it - 1" and "max_change - 1" bits are
still there, or what they are doing in the first place. I.e., why is it
not simply "scale linearly to width-1, then add 1" as I posted earlier?

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help