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

Re: [PATCHv6 2/6] pretty.c: teach format_commit_message() to reencode the output

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 27, 2010, 22:35 UTC
Message-ID
<7vvd4nb6wt.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1287689637-95301-3-git-send-email-patnotz@gmail.com>
"Pat Notz" <patnotz@gmail.com> writes:
Show 29 quoted lines
> @@ -1008,16 +1009,29 @@ 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;
> +
> +	enc = get_header(commit, "encoding");
> +	enc = enc ? enc : utf8;
>  
>  	memset(&context, 0, sizeof(context));
>  	context.commit = commit;
>  	context.pretty_ctx = pretty_ctx;
>  	context.wrap_start = sb->len;
> +	if (output_encoding && strcmp(enc, output_encoding))
> +		context.message = logmsg_reencode(commit, output_encoding);
> +	context.message = context.message ? context.message : commit->buffer;
> +
>  	strbuf_expand(sb, format, format_commit_item, &context);
>  	rewrap_message_tail(sb, &context, 0, 0, 0);
> +
> +	if (context.message != commit->buffer)
> +		free(context.message);
>  }
Three points.
 - Most of the callers give NULL to the output_encoding. Does it make
   sense to limit get_header(commit, "encoding") call only when the
   argument is given?
 - The conditional assignment to context.message with ?: is hard to read;
   perhaps it would be easier to read if you structure it like this:
	memset(&context, 0, sizeof(context));
        context.commit = ...;
        ...
	context.message = commit->buffer;
	if (output_encoding) {
        	enc = ...
                if (strcmp(enc, output_encoding))
                	context.message = ...
	}
 - Should output_encoding be a separate argument to this function?  If
   anybody is going to call this function with the same pretty_ctx with
   different output_encoding, your patch may make sense, but I suspect
   adding it as a new member to pretty_print_context structure may be much
   cleaner.  I would imagine that it would cut this patch down by 70% ;-)
Previous: Pat NotzNext: Pat Notz
Message 4 of 11 in “[PATCHv6 0/6] Add commit message options for rebase --autosquash”
  1. Pat NotzOct 21, 2010
  2. 1/6 commit: helper methods to reduce redundant blocks of codePat Notz, Oct 21, 2010
  3. 2/6 pretty.c: teach format_commit_message() to reencode the outputPat Notz, Oct 21, 2010
  4. Junio C HamanoOct 27, 2010
  5. 3/6 commit: --fixup option for use with rebase --autosquashPat Notz, Oct 21, 2010
  6. Junio C HamanoOct 27, 2010
  7. 4/6 add tests of commit --fixupPat Notz, Oct 21, 2010
  8. Junio C HamanoOct 27, 2010
  9. 5/6 commit: --squash option for use with rebase --autosquashPat Notz, Oct 21, 2010
  10. Junio C HamanoOct 27, 2010
  11. 6/6 add tests of commit --squashPat Notz, Oct 21, 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.