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

Re: [PATCH 3/3] add a "lua" pretty format

From
Jeff King <peff@peff.net>
Date
Oct 6, 2012, 17:33 UTC
Message-ID
<20121006173329.GA31012@sigill.intra.peff.net>
In-Reply-To
<20120925002539.GC19605@sigill.intra.peff.net>
On Mon, Sep 24, 2012 at 08:25:39PM -0400, Jeff King wrote:
Show 10 quoted lines
> @@ -1168,7 +1180,11 @@ void format_commit_message(const struct commit *commit,
>  		free(enc);
>  	}
>  
> -	strbuf_expand(sb, format, format_commit_item, &context);
> +	if (pretty_ctx->fmt == CMIT_FMT_USERFORMAT)
> +		strbuf_expand(sb, format, format_commit_item, &context);
> +	else if (pretty_ctx->fmt == CMIT_FMT_LUA)
> +		lua_commit_format(sb, &context);
> +

This hunk breaks lots of tests. I know we are not seriously considering the lua series as-is, but in case anybody wants to play with it, here is the fix (and we would need the same fix regardless of language, anyway).

You might want to queue this on jk/lua-hackery (probably it would be squashed in for a real series).

-- >8 --
Subject: [PATCH] pretty: fix up one-off format_commit_message calls

If the usual pretty-print code invokes format_commit_message, the "fmt" field of the pretty_print_context will always have either CMIT_FMT_USERFORMAT or CMIT_FMT_LUA in it, and we can just choose which to use.

However, many call sites invoke format_commit_message directly without bothering to set the "fmt" field of the context; they expect format_commit_message to just default to CMIT_FMT_USERFORMAT in that case, since previously that was the only format it handled.

The recent addition of the lua formatter broke that assumption. Rather than require each caller to be more strict, let's just default to USERFORMAT when the format is set to something nonsensical.

Signed-off-by: Jeff King <peff@peff.net>
---
 pretty.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pretty.c b/pretty.c
index fdd4258..7289590 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1180,10 +1180,10 @@ void format_commit_message(const struct commit *commit,
 		free(enc);
 	}
 
-	if (pretty_ctx->fmt == CMIT_FMT_USERFORMAT)
-		strbuf_expand(sb, format, format_commit_item, &context);
-	else if (pretty_ctx->fmt == CMIT_FMT_LUA)
+	if (pretty_ctx->fmt == CMIT_FMT_LUA)
 		lua_commit_format(sb, &context);
+	else
+		strbuf_expand(sb, format, format_commit_item, &context);
 
 	rewrap_message_tail(sb, &context, 0, 0, 0);
 
-- 
1.8.0.rc0.22.g285fd2d
Previous: Jeff KingNext: Nguyen Thai Ngoc Duy
Message 10 of 15 in “git log --pretty=lua”
  1. 0/3 git log --pretty=luaJeff King, Sep 25, 2012
  2. 1/3 pretty: make some commit-parsing helpers more publicJeff King, Sep 25, 2012
  3. 2/3 add basic lua infrastructureJeff King, Sep 25, 2012
  4. Nguyen Thai Ngoc DuySep 25, 2012
  5. Jeff KingSep 25, 2012
  6. Robin H. JohnsonSep 25, 2012
  7. Jeff KingSep 25, 2012
  8. Junio C HamanoSep 25, 2012
  9. 3/3 add a "lua" pretty formatJeff King, Sep 25, 2012
  10. Jeff KingOct 6, 2012
  11. Nguyen Thai Ngoc DuySep 25, 2012
  12. Stephen BashSep 25, 2012
  13. Matthieu MoySep 25, 2012
  14. Junio C HamanoSep 25, 2012
  15. Nguyen Thai Ngoc DuySep 30, 2012

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.