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

[PATCH] pretty: use strchr(3) in userformat_find_requirements()

From
René Scharfe <l.s.r@web.de>
Date
Jul 7, 2023, 19:08 UTC
Message-ID
<108ab1a2-28f4-dd62-1f90-64f37708aa8c@web.de>

The strbuf_expand_step() loop in userformat_find_requirements() iterates through the percent signs in the string "fmt", but we're not interested in its effect on the strbuf "dummy". Use strchr(3) instead and get rid of the strbuf that we no longer need.

Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 pretty.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/pretty.c b/pretty.c
index 7862be105d..d9419aa062 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1876,14 +1876,13 @@ static size_t format_commit_item(struct strbuf *sb, /* in UTF-8 */

 void userformat_find_requirements(const char *fmt, struct userformat_want *w)
 {
-	struct strbuf dummy = STRBUF_INIT;
-
 	if (!fmt) {
 		if (!user_format)
 			return;
 		fmt = user_format;
 	}
-	while (strbuf_expand_step(&dummy, &fmt)) {
+	while ((fmt = strchr(fmt, '%'))) {
+		fmt++;
 		if (skip_prefix(fmt, "%", &fmt))
 			continue;

@@ -1903,7 +1902,6 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)
 			break;
 		}
 	}
-	strbuf_release(&dummy);
 }

 void repo_format_commit_message(struct repository *r,
--
2.41.0
Message 1 of 1 in “pretty: use strchr(3) in userformat_find_requirements()”
  1. pretty: use strchr(3) in userformat_find_requirements()René Scharfe, Jul 7, 2023

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.