pretty: use strchr(3) in userformat_find_requirements()

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 7, 2023 at 21:08 UTC bd19ee9c459b2d7872a8e486fd9c2f1b17d662a5
1 file changed +2 -4
pretty.c
+2 -4
@@ -1873,14 +1873,13 @@ static size_t format_commit_item(struct strbuf *sb, /* in UTF-8 */
1873
1874 void userformat_find_requirements(const char *fmt, struct userformat_want *w)
1875 {
1876 - struct strbuf dummy = STRBUF_INIT;
1877 -
1876 if (!fmt) {
1877 if (!user_format)
1878 return;
1879 fmt = user_format;
1880 }
1883 - while (strbuf_expand_step(&dummy, &fmt)) {
1881 + while ((fmt = strchr(fmt, '%'))) {
1882 + fmt++;
1883 if (skip_prefix(fmt, "%", &fmt))
1884 continue;
1885
@@ -1900,7 +1899,6 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)
1899 break;
1900 }
1901 }
1903 - strbuf_release(&dummy);
1902 }
1903
1904 void repo_format_commit_message(struct repository *r,