diff options
author | René Scharfe <l.s.r@web.de> | 2024-03-24 12:21:15 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-03-25 11:59:26 -0700 |
commit | 7c43bdf07b63ce86572bec1db9d19a160c8de8cd (patch) | |
tree | 4b415eb640e1be9fe8a5cdcc2c0e1b2a97ecef05 | |
parent | e36091aa1d67cedba02ea9de9245f0ff14a52f15 (diff) | |
download | git-7c43bdf07b63ce86572bec1db9d19a160c8de8cd.tar.gz |
cat-file: use strbuf_expand_bad_format()
Report unknown format elements and missing closing parentheses with
consistent and translated messages by calling strbuf_expand_bad_format()
at the very end of the combined if/else chain of expand_format() and
expand_atom().
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/cat-file.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/builtin/cat-file.c b/builtin/cat-file.c index bbf851138e..fadf2da2f0 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -310,8 +310,8 @@ static int is_atom(const char *atom, const char *s, int slen) return alen == slen && !memcmp(atom, s, alen); } -static void expand_atom(struct strbuf *sb, const char *atom, int len, - struct expand_data *data) +static int expand_atom(struct strbuf *sb, const char *atom, int len, + struct expand_data *data) { if (is_atom("objectname", atom, len)) { if (!data->mark_query) @@ -343,7 +343,8 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len, strbuf_addstr(sb, oid_to_hex(&data->delta_base_oid)); } else - die("unknown format element: %.*s", len, atom); + return 0; + return 1; } static void expand_format(struct strbuf *sb, const char *start, @@ -354,12 +355,11 @@ static void expand_format(struct strbuf *sb, const char *start, if (skip_prefix(start, "%", &start) || *start != '(') strbuf_addch(sb, '%'); - else if (!(end = strchr(start + 1, ')'))) - die("format element '%s' does not end in ')'", start); - else { - expand_atom(sb, start + 1, end - start - 1, data); + else if ((end = strchr(start + 1, ')')) && + expand_atom(sb, start + 1, end - start - 1, data)) start = end + 1; - } + else + strbuf_expand_bad_format(start, "cat-file"); } } |