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

Re: [PATCH 1/2] diff: introduce --stat-lines to limit the stat lines

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Apr 29, 2011, 15:12 UTC
Message-ID
<4DBAD56C.8020804@drmicha.warpmail.net>
In-Reply-To
<5f16db0f3730be70ff522e63fbd491dc910c34d0.1304089050.git.git@drmicha.warpmail.net>
Michael J Gruber venit, vidit, dixit 29.04.2011 16:57:
Show 77 quoted lines
> Often one is interested in the full --stat output only for commits which
> change a few files, but not others, because larger restructuring gives a
> --stat which fills a few screens.
> 
> Introduce a new option --stat-lines=<lines> which limits the --stat output
> to the first and last <lines> lines, separated by a "..." line. It can
> also be given as the third parameter in
> --stat=<width>,<name-width>,<lines>.
> 
> Also, the unstuck form is supported analogous to the other two stat
> parameters.
> 
> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
> ---
> I would even consider a default of 10 (i.e. show a 20 line stat in full,
> abbreviate larger ones) to be sensible but have refrained from such a
> behaviour change.
> 
> We have hardcoded defaults for width (80) and name-width (50), so having
> one for lines should be okay also. Can I has tis wiz default? ;)
> ---
>  Documentation/diff-options.txt |    5 ++++-
>  diff.c                         |   25 +++++++++++++++++++++++--
>  diff.h                         |    1 +
>  3 files changed, 28 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
> index 34f0145..e0429b3 100644
> --- a/Documentation/diff-options.txt
> +++ b/Documentation/diff-options.txt
> @@ -48,11 +48,14 @@ endif::git-format-patch[]
>  --patience::
>  	Generate a diff using the "patience diff" algorithm.
>  
> ---stat[=<width>[,<name-width>]]::
> +--stat[=<width>[,<name-width>[,<lines>]]]::
>  	Generate a diffstat.  You can override the default
>  	output width for 80-column terminal by `--stat=<width>`.
>  	The width of the filename part can be controlled by
>  	giving another width to it separated by a comma.
> +	By giving a third parameter `<lines>`, you can limit the
> +	output to the first and last `<lines>` lines, separated by
> +	`...`.
>  
>  --numstat::
>  	Similar to `\--stat`, but shows number of added and
> diff --git a/diff.c b/diff.c
> index feced34..9ccba1e 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -1244,7 +1244,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
>  	int i, len, add, del, adds = 0, dels = 0;
>  	uintmax_t max_change = 0, max_len = 0;
>  	int total_files = data->nr;
> -	int width, name_width;
> +	int width, name_width, lines;
>  	const char *reset, *add_c, *del_c;
>  	const char *line_prefix = "";
>  	struct strbuf *msg = NULL;
> @@ -1259,6 +1259,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
>  
>  	width = options->stat_width ? options->stat_width : 80;
>  	name_width = options->stat_name_width ? options->stat_name_width : 50;
> +	lines = options->stat_lines;
>  
>  	/* Sanity: give at least 5 columns to the graph,
>  	 * but leave at least 10 columns for the name.
> @@ -1303,6 +1304,12 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
>  		width = max_change;
>  
>  	for (i = 0; i < data->nr; i++) {
> +		if (lines && i >= lines && i < data->nr-lines) {
> +			fprintf(options->file, "%s ...\n", line_prefix);
> +			i = data->nr-lines-1;
> +			lines = 0; /* no need to recheck */
> +			continue;
> +		}

One could/should do the same limitting for the earlier loop which computes the maximal line width (since the largest file names may be skipped now). I'll leave this for a v2 which I'm sure will be necessary :)

Michael
Previous: Michael J GruberNext: Junio C Hamano
Message 3 of 21 in “diff: introduce --stat-lines to limit the stat lines”
  1. 1/2 diff: introduce --stat-lines to limit the stat linesMichael J Gruber, Apr 29, 2011
  2. 2/2 diff-options.txt: describe --stat-{width,name-width,lines}Michael J Gruber, Apr 29, 2011
  3. Michael J GruberApr 29, 2011
  4. Junio C HamanoApr 29, 2011
  5. Michael J GruberMay 1, 2011
  6. Junio C HamanoMay 1, 2011
  7. 1/2 diff: introduce --stat-lines to limit the stat linesMichael J Gruber, May 3, 2011
  8. Junio C HamanoMay 3, 2011
  9. Michael J GruberMay 4, 2011
  10. 0/3 diff.c: --stat-count=<n>Michael J Gruber, May 27, 2011
  11. 1/3 diff.c: omit hidden entries from namelen calculation with --statMichael J Gruber, May 27, 2011
  12. Junio C HamanoMay 27, 2011
  13. Michael J GruberMay 27, 2011
  14. Junio C HamanoMay 27, 2011
  15. 2/3 diff: introduce --stat-lines to limit the stat linesMichael J Gruber, May 27, 2011
  16. Junio C HamanoMay 28, 2011
  17. Michael J GruberMay 30, 2011
  18. Junio C HamanoMay 30, 2011
  19. 3/3 diff-options.txt: describe --stat-{width,name-width,count}Michael J Gruber, May 27, 2011
  20. Junio C HamanoMay 4, 2011
  21. 2/2 diff-options.txt: describe --stat-{width,name-width,count}Michael J Gruber, May 3, 2011

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.