Skip to content

Commit 7c43bdf

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e36091a commit 7c43bdf

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

builtin/cat-file.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ static int is_atom(const char *atom, const char *s, int slen)
310310
return alen == slen && !memcmp(atom, s, alen);
311311
}
312312

313-
static void expand_atom(struct strbuf *sb, const char *atom, int len,
314-
struct expand_data *data)
313+
static int expand_atom(struct strbuf *sb, const char *atom, int len,
314+
struct expand_data *data)
315315
{
316316
if (is_atom("objectname", atom, len)) {
317317
if (!data->mark_query)
@@ -343,7 +343,8 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,
343343
strbuf_addstr(sb,
344344
oid_to_hex(&data->delta_base_oid));
345345
} else
346-
die("unknown format element: %.*s", len, atom);
346+
return 0;
347+
return 1;
347348
}
348349

349350
static void expand_format(struct strbuf *sb, const char *start,
@@ -354,12 +355,11 @@ static void expand_format(struct strbuf *sb, const char *start,
354355

355356
if (skip_prefix(start, "%", &start) || *start != '(')
356357
strbuf_addch(sb, '%');
357-
else if (!(end = strchr(start + 1, ')')))
358-
die("format element '%s' does not end in ')'", start);
359-
else {
360-
expand_atom(sb, start + 1, end - start - 1, data);
358+
else if ((end = strchr(start + 1, ')')) &&
359+
expand_atom(sb, start + 1, end - start - 1, data))
361360
start = end + 1;
362-
}
361+
else
362+
strbuf_expand_bad_format(start, "cat-file");
363363
}
364364
}
365365

0 commit comments

Comments
 (0)