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

Re: [RFC PATCH 1/5] format-patch: allow additional generated content in make_cover_letter()

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 17, 2018, 10:15 UTC
Message-ID
<nycvar.QRO.7.76.6.1807171214590.71@tvgsbejvaqbjf.bet>
In-Reply-To
<20180530080325.37520-2-sunshine@sunshineco.com>
Hi Eric,
On Wed, 30 May 2018, Eric Sunshine wrote:
Show 7 quoted lines
> make_cover_letter() returns early when it lacks sufficient state to emit
> a diffstat, which makes it difficult to extend the function to reliably
> emit additional generated content. Work around this shortcoming by
> factoring diffstat-printing logic out to its own function and calling it
> as needed without otherwise inhibiting normal control flow.
> 
> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Makes sense.

Ciao, Dscho

Show 76 quoted lines
> ---
>  builtin/log.c | 43 +++++++++++++++++++++++--------------------
>  1 file changed, 23 insertions(+), 20 deletions(-)
> 
> diff --git a/builtin/log.c b/builtin/log.c
> index 71f68a3e4f..e01a256c11 100644
> --- a/builtin/log.c
> +++ b/builtin/log.c
> @@ -992,6 +992,26 @@ static char *find_branch_name(struct rev_info *rev)
>  	return branch;
>  }
>  
> +static void emit_diffstat(struct rev_info *rev,
> +			  struct commit *origin, struct commit *head)
> +{
> +	struct diff_options opts;
> +
> +	memcpy(&opts, &rev->diffopt, sizeof(opts));
> +	opts.output_format = DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
> +	opts.stat_width = MAIL_DEFAULT_WRAP;
> +
> +	diff_setup_done(&opts);
> +
> +	diff_tree_oid(&origin->tree->object.oid,
> +		      &head->tree->object.oid,
> +		      "", &opts);
> +	diffcore_std(&opts);
> +	diff_flush(&opts);
> +
> +	fprintf(rev->diffopt.file, "\n");
> +}
> +
>  static void make_cover_letter(struct rev_info *rev, int use_stdout,
>  			      struct commit *origin,
>  			      int nr, struct commit **list,
> @@ -1005,7 +1025,6 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
>  	struct strbuf sb = STRBUF_INIT;
>  	int i;
>  	const char *encoding = "UTF-8";
> -	struct diff_options opts;
>  	int need_8bit_cte = 0;
>  	struct pretty_print_context pp = {0};
>  	struct commit *head = list[0];
> @@ -1055,25 +1074,9 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
>  
>  	shortlog_output(&log);
>  
> -	/*
> -	 * We can only do diffstat with a unique reference point
> -	 */
> -	if (!origin)
> -		return;
> -
> -	memcpy(&opts, &rev->diffopt, sizeof(opts));
> -	opts.output_format = DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
> -	opts.stat_width = MAIL_DEFAULT_WRAP;
> -
> -	diff_setup_done(&opts);
> -
> -	diff_tree_oid(&origin->tree->object.oid,
> -		      &head->tree->object.oid,
> -		      "", &opts);
> -	diffcore_std(&opts);
> -	diff_flush(&opts);
> -
> -	fprintf(rev->diffopt.file, "\n");
> +	/* We can only do diffstat with a unique reference point */
> +	if (origin)
> +		emit_diffstat(rev, origin, head);
>  }
>  
>  static const char *clean_message_id(const char *msg_id)
> -- 
> 2.17.1.1235.ge295dfb56e
> 
> 
Previous: Eric SunshineNext: Eric Sunshine
Message 9 of 29 in “format-patch: automate cover letter range-diff”
  1. 0/5 format-patch: automate cover letter range-diffEric Sunshine, May 30, 2018
  2. 2/5 format-patch: add --range-diff option to embed diff in cover letterEric Sunshine, May 30, 2018
  3. Johannes SchindelinJul 17, 2018
  4. Eric SunshineJul 17, 2018
  5. Johannes SchindelinJul 26, 2018
  6. Eric SunshineJul 26, 2018
  7. Johannes SchindelinJul 27, 2018
  8. 1/5 format-patch: allow additional generated content in make_cover_letter()Eric Sunshine, May 30, 2018
  9. Johannes SchindelinJul 17, 2018
  10. Eric SunshineJul 17, 2018
  11. 3/5 format-patch: extend --range-diff to accept revision rangeEric Sunshine, May 30, 2018
  12. Stefan BellerMay 30, 2018
  13. Eric SunshineMay 30, 2018
  14. Johannes SchindelinJul 17, 2018
  15. Eric SunshineJul 17, 2018
  16. 4/5 format-patch: teach --range-diff to respect -v/--reroll-countEric Sunshine, May 30, 2018
  17. Stefan BellerMay 30, 2018
  18. Eric SunshineMay 30, 2018
  19. Stefan BellerMay 30, 2018
  20. Eric SunshineMay 30, 2018
  21. 5/5 format-patch: add --creation-weight tweak for --range-diffEric Sunshine, May 30, 2018
  22. Johannes SchindelinJul 17, 2018
  23. Ævar Arnfjörð BjarmasonMay 30, 2018
  24. Duy NguyenJun 6, 2018
  25. Eric SunshineJun 7, 2018
  26. Duy NguyenJun 7, 2018
  27. Johannes SchindelinJul 17, 2018
  28. Andrei RybakJul 26, 2018
  29. Johannes SchindelinJul 26, 2018

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.