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

Re: [PATCHv5 4/8] pretty.c: teach format_commit_message() to reencode the output

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 13, 2010, 21:59 UTC
Message-ID
<7vd3rdiwjh.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1286478657-61581-5-git-send-email-patnotz@gmail.com>
"Pat Notz" <patnotz@gmail.com> writes:
Show 27 quoted lines
> diff --git a/pretty.c b/pretty.c
> index a607fd6..e5ce7fb 100644
> --- a/pretty.c
> +++ b/pretty.c
> @@ -1009,16 +1009,47 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)
>  
>  void format_commit_message(const struct commit *commit,
>  			   const char *format, struct strbuf *sb,
> -			   const struct pretty_print_context *pretty_ctx)
> +			   const struct pretty_print_context *pretty_ctx,
> +			   const char *output_encoding)
>  {
>  	struct format_commit_context context;
> +	static char utf8[] = "UTF-8";
> +	char *enc;
> +	char *buffer;
> +	char *enc_buffer;
> +	struct strbuf scratch_sb = STRBUF_INIT;
> +	struct strbuf *sb_ptr;
> +
> +	enc = get_header(commit, "encoding");
> +	enc = enc ? enc : utf8;
> +	if(output_encoding && strcmp(enc,output_encoding)) {
> +		sb_ptr = &scratch_sb;
> +	} else {
> +		sb_ptr = sb;
> +	}
Style...
Show 25 quoted lines
>  	memset(&context, 0, sizeof(context));
>  	context.commit = commit;
>  	context.pretty_ctx = pretty_ctx;
>  	context.wrap_start = sb->len;
> -	strbuf_expand(sb, format, format_commit_item, &context);
> -	rewrap_message_tail(sb, &context, 0, 0, 0);
> +	strbuf_expand(sb_ptr, format, format_commit_item, &context);
> +	rewrap_message_tail(sb_ptr, &context, 0, 0, 0);
> +
> +	if(sb_ptr != sb) {
> +		/* if re-encoding fails, take the content byte-for-byte */
> +		buffer = strbuf_detach(sb_ptr, 0);
> +		enc_buffer = reencode_string(buffer, output_encoding, enc);
> +		enc_buffer = enc_buffer ? enc_buffer : buffer;
> +
> +		strbuf_addstr(sb,enc_buffer);
> +
> +		if(enc_buffer != buffer)
> +			free(enc_buffer);
> +		free(buffer);
> +	}
> +
> +	if(enc != utf8)
> +		free(enc);
>  }

You are expanding and wrapping commit->buf before re-encoding, but I am not sure it is the right thing to do. Wouldn't it become much simpler and more consistent if you re-encode first and then give the result to later expansion and wrapping process? format_commit_one() would need to take "msg" not from c->commit->buffer but from a new field to hold reencoded result you will add in your patch to the structure, if you do so, of course.

Besides, I am a bit lost as to what this patch has to do with the stated goal of the series, "Add commit message options for rebase --autosquash".

Previous: Pat NotzNext: Pat Notz
Message 10 of 17 in “[PATCHv5 0/8] Add commit message options for rebase --autosquash”
  1. Pat NotzOct 7, 2010
  2. 1/8 commit.c: prefer get_header() to manual searchingPat Notz, Oct 7, 2010
  3. Sverre RabbelierOct 7, 2010
  4. Sverre RabbelierOct 7, 2010
  5. Junio C HamanoOct 13, 2010
  6. 2/8 commit.c: new function for looking up a comit by namePat Notz, Oct 7, 2010
  7. Junio C HamanoOct 13, 2010
  8. 3/8 pretty.c: helper methods for getting output encodingsPat Notz, Oct 7, 2010
  9. 4/8 pretty.c: teach format_commit_message() to reencode the outputPat Notz, Oct 7, 2010
  10. Junio C HamanoOct 13, 2010
  11. Pat NotzOct 13, 2010
  12. 5/8 commit: --fixup option for use with rebase --autosquashPat Notz, Oct 7, 2010
  13. 6/8 add tests of commit --fixupPat Notz, Oct 7, 2010
  14. 7/8 commit: --squash option for use with rebase --autosquashPat Notz, Oct 7, 2010
  15. 8/8 add tests of commit --squashPat Notz, Oct 7, 2010
  16. Pat NotzOct 11, 2010
  17. Sverre RabbelierOct 12, 2010

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.