{"thread":{"id":"59961","subject":"[PATCH] pretty: use strchr(3) in userformat_find_requirements()","startedAt":"2023-07-07T19:08:46Z","lastAt":"2023-07-07T19:08:46Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"479292","messageId":"108ab1a2-28f4-dd62-1f90-64f37708aa8c@web.de","threadId":"59961","inReplyTo":null,"subject":"[PATCH] pretty: use strchr(3) in userformat_find_requirements()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2023-07-07T19:08:33Z","receivedAt":"2023-07-07T19:08:46Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"The strbuf_expand_step() loop in userformat_find_requirements() iterates\nthrough the percent signs in the string \"fmt\", but we're not interested\nin its effect on the strbuf \"dummy\".  Use strchr(3) instead and get rid\nof the strbuf that we no longer need.\n\nSuggested-by: Jeff King <peff@peff.net>\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n pretty.c | 6 ++----\n 1 file changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/pretty.c b/pretty.c\nindex 7862be105d..d9419aa062 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1876,14 +1876,13 @@ static size_t format_commit_item(struct strbuf *sb, /* in UTF-8 */\n\n void userformat_find_requirements(const char *fmt, struct userformat_want *w)\n {\n-\tstruct strbuf dummy = STRBUF_INIT;\n-\n \tif (!fmt) {\n \t\tif (!user_format)\n \t\t\treturn;\n \t\tfmt = user_format;\n \t}\n-\twhile (strbuf_expand_step(&dummy, &fmt)) {\n+\twhile ((fmt = strchr(fmt, '%'))) {\n+\t\tfmt++;\n \t\tif (skip_prefix(fmt, \"%\", &fmt))\n \t\t\tcontinue;\n\n@@ -1903,7 +1902,6 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)\n \t\t\tbreak;\n \t\t}\n \t}\n-\tstrbuf_release(&dummy);\n }\n\n void repo_format_commit_message(struct repository *r,\n--\n2.41.0\n"}]}