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

Re: [PATCH 1/3] diff --stat: allow custom diffstat output width.

From
DRDavid Rientjes <rientjes@cs.washington.edu>
Date
Sep 27, 2006, 03:11 UTC
Message-ID
<Pine.LNX.4.64N.0609262001460.520@attu4.cs.washington.edu>
In-Reply-To
<7vr6xyjal0.fsf@assigned-by-dhcp.cox.net>
On Tue, 26 Sep 2006, Junio C Hamano wrote:
Show 8 quoted lines
> +static void show_graph(char ch, int cnt)
> +{
> +	if (!cnt)
> +		return;
> +	while (cnt--)
> +		putchar(ch);
> +}
> +
'if (cnt <= 0)' or 'while (cnt-- > 0)' is a better API./
Show 24 quoted lines
> +static void show_stats(struct diffstat_t* data, struct diff_options *options)
>  {
>  	int i, len, add, del, total, adds = 0, dels = 0;
> -	int max, max_change = 0, max_len = 0;
> +	int max_change = 0, max_len = 0;
>  	int total_files = data->nr;
> +	int width, name_width;
>  
>  	if (data->nr == 0)
>  		return;
>  
> +	width = options->stat_width ? options->stat_width : 80;
> +	name_width = options->stat_name_width ? options->stat_name_width : 50;
> +
> +	/* Sanity: give at least 5 columns to the graph,
> +	 * but leave at least 10 columns for the name.
> +	 */
> +	if (width < name_width + 15) {
> +		if (25 < name_width)
> +			name_width = width - 15;
> +		else
> +			width = name_width + 15;
> +	}
> +
Constants go on the right side of comparison expressions.
Show 11 quoted lines
> +	/* Find the longest filename and max number of changes */
>  	for (i = 0; i < data->nr; i++) {
>  		struct diffstat_file *file = data->files[i];
> +		int change = file->added + file->deleted;
> +
> +		if (0 < (len = quote_c_style(file->name, NULL, NULL, 0))) {
> +			char *qname = xmalloc(len + 1);
> +			quote_c_style(file->name, qname, NULL, 0);
> +			free(file->name);
> +			file->name = qname;
> +		}
Same.
Show 23 quoted lines
> @@ -623,27 +664,34 @@ static void show_stats(struct diffstat_t
>  			goto free_diffstat_file;
>  		}
>  
> +		/*
> +		 * scale the add/delete
> +		 */
>  		add = added;
>  		del = deleted;
>  		total = add + del;
>  		adds += add;
>  		dels += del;
>  
> -		if (max_change > 0) {
> -			total = (total * max + max_change / 2) / max_change;
> -			add = (add * max + max_change / 2) / max_change;
> +		if (max_change < width)
> +			;
> +		else {
> +			total = scale_linear(total, width, max_change);
> +			add = scale_linear(add, width, max_change);
>  			del = total - add;
>  		}
if (max_change >= width)
Show 11 quoted lines
> diff --git a/diff.h b/diff.h
> index b60a02e..e06d0f4 100644
> --- a/diff.h
> +++ b/diff.h
> @@ -69,6 +69,9 @@ struct diff_options {
>  	const char *stat_sep;
>  	long xdl_opts;
>  
> +	int stat_width;
> +	int stat_name_width;
> +
Can you use unsigned char here instead?
		David
Previous: Junio C HamanoNext: Linus Torvalds
Message 2 of 12 in “diff --stat: allow custom diffstat output width.”
  1. 1/3 diff --stat: allow custom diffstat output width.Junio C Hamano, Sep 27, 2006
  2. David RientjesSep 27, 2006
  3. Linus TorvaldsSep 28, 2006
  4. Junio C HamanoSep 28, 2006
  5. Linus TorvaldsSep 28, 2006
  6. Junio C HamanoSep 29, 2006
  7. Junio C HamanoSep 29, 2006
  8. Linus TorvaldsSep 29, 2006
  9. Junio C HamanoSep 29, 2006
  10. Linus TorvaldsSep 29, 2006
  11. Adrian BunkSep 28, 2006
  12. Johannes SchindelinSep 28, 2006

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.