git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: diff --stat

From
Jeff King <peff@peff.net>
Date
Feb 14, 2012, 21:53 UTC
Message-ID
<20120214215318.GA24802@sigill.intra.peff.net>
In-Reply-To
<7vty2t5bmw.fsf@alter.siamese.dyndns.org>
On Tue, Feb 14, 2012 at 01:49:11PM -0800, Junio C Hamano wrote:
Show 17 quoted lines
>  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
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 7 in “diff --stat”
  1. Junio C HamanoFeb 14, 2012
  2. Jeff KingFeb 14, 2012
  3. Junio C HamanoFeb 14, 2012
  4. Jeff KingFeb 14, 2012
  5. Junio C HamanoFeb 14, 2012
  6. Jeff KingFeb 14, 2012
  7. Junio C HamanoFeb 14, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.