All of lore.kernel.org
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Subject: [PATCH v2 2/2] cat-file: use strbuf_expand_bad_format()
Date: Sun, 24 Mar 2024 12:21:15 +0100	[thread overview]
Message-ID: <c6f915a9-0788-4492-b71a-37171a8bb13b@web.de> (raw)
In-Reply-To: <27cdcde7-74bc-4ee8-bc84-9a6046292cae@web.de>

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>
---
Same as v1.

 builtin/cat-file.c | 16 ++++++++--------
 1 file 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");
 	}
 }

--
2.44.0

      parent reply	other threads:[~2024-03-24 11:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-24  7:55 [PATCH 1/2] factor out strbuf_expand_bad_format() René Scharfe
2024-03-24  8:04 ` [PATCH 2/2] cat-file: use strbuf_expand_bad_format() René Scharfe
2024-03-24  9:00 ` [PATCH 1/2] factor out strbuf_expand_bad_format() Chris Torek
2024-03-24 11:17   ` René Scharfe
2024-03-24 11:19 ` [PATCH v2 " René Scharfe
2024-03-24 16:06   ` Junio C Hamano
2024-03-24 11:21 ` René Scharfe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c6f915a9-0788-4492-b71a-37171a8bb13b@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.