From e36091aa1d67cedba02ea9de9245f0ff14a52f15 Mon Sep 17 00:00:00 2001 From: René Scharfe Date: Sun, 24 Mar 2024 12:19:40 +0100 Subject: factor out strbuf_expand_bad_format() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract a function for reporting placeholders that are not enclosed in a parenthesis or are unknown. This reduces the number of strings to translate and improves consistency across commands. Call it at the end of the if/else chain, after exhausting all accepted possibilities. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- strbuf.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'strbuf.c') diff --git a/strbuf.c b/strbuf.c index 7827178d8e..449eb610f1 100644 --- a/strbuf.c +++ b/strbuf.c @@ -442,6 +442,26 @@ size_t strbuf_expand_literal(struct strbuf *sb, const char *placeholder) return 0; } +void strbuf_expand_bad_format(const char *format, const char *command) +{ + const char *end; + + if (*format != '(') + /* TRANSLATORS: The first %s is a command like "ls-tree". */ + die(_("bad %s format: element '%s' does not start with '('"), + command, format); + + end = strchr(format + 1, ')'); + if (!end) + /* TRANSLATORS: The first %s is a command like "ls-tree". */ + die(_("bad %s format: element '%s' does not end in ')'"), + command, format); + + /* TRANSLATORS: %s is a command like "ls-tree". */ + die(_("bad %s format: %%%.*s"), + command, (int)(end - format + 1), format); +} + void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src) { size_t i, len = src->len; -- cgit v1.3