All of lore.kernel.org
 help / color / mirror / Atom feed
From: Justin Tobler <jltobler@gmail.com>
To: git@vger.kernel.org
Cc: christian.couder@gmail.com, Justin Tobler <jltobler@gmail.com>
Subject: [PATCH v3 1/4] quote: add c quote flag to ignore core.quotePath
Date: Sat,  1 Feb 2025 14:16:55 -0600	[thread overview]
Message-ID: <20250201201658.11562-2-jltobler@gmail.com> (raw)
In-Reply-To: <20250201201658.11562-1-jltobler@gmail.com>

The output of `cq_must_quote()` is affected by `core.quotePath`. This is
undesirable for operations that want to ensure consistent output
independent of config settings.

Introduce the `CQUOTE_IGNORE_CONFIG` flag for the `quote_c_style*`
functions which when set makes `cq_must_quote()` always follow the
default behavior (core.quotePath=true) regardless of how its set in the
config.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
 quote.c | 14 ++++++++------
 quote.h |  3 ++-
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/quote.c b/quote.c
index b9f6bdc775..d129c1de70 100644
--- a/quote.c
+++ b/quote.c
@@ -232,21 +232,22 @@ static signed char const cq_lookup[256] = {
 	/* 0x80 */ /* set to 0 */
 };
 
-static inline int cq_must_quote(char c)
+static inline int cq_must_quote(char c, int ignore_config)
 {
-	return cq_lookup[(unsigned char)c] + quote_path_fully > 0;
+	return cq_lookup[(unsigned char)c] + (quote_path_fully || ignore_config) > 0;
 }
 
 /* returns the longest prefix not needing a quote up to maxlen if positive.
    This stops at the first \0 because it's marked as a character needing an
    escape */
-static size_t next_quote_pos(const char *s, ssize_t maxlen)
+static size_t next_quote_pos(const char *s, ssize_t maxlen, int ignore_config)
 {
 	size_t len;
 	if (maxlen < 0) {
-		for (len = 0; !cq_must_quote(s[len]); len++);
+		for (len = 0; !cq_must_quote(s[len], ignore_config); len++);
 	} else {
-		for (len = 0; len < maxlen && !cq_must_quote(s[len]); len++);
+		for (len = 0;
+		     len < maxlen && !cq_must_quote(s[len], ignore_config); len++);
 	}
 	return len;
 }
@@ -282,13 +283,14 @@ static size_t quote_c_style_counted(const char *name, ssize_t maxlen,
 	} while (0)
 
 	int no_dq = !!(flags & CQUOTE_NODQ);
+	int ignore_config = !!(flags & CQUOTE_IGNORE_CONFIG);
 	size_t len, count = 0;
 	const char *p = name;
 
 	for (;;) {
 		int ch;
 
-		len = next_quote_pos(p, maxlen);
+		len = next_quote_pos(p, maxlen, ignore_config);
 		if (len == maxlen || (maxlen < 0 && !p[len]))
 			break;
 
diff --git a/quote.h b/quote.h
index 0300c29104..2a793fbef6 100644
--- a/quote.h
+++ b/quote.h
@@ -83,7 +83,8 @@ int sq_dequote_to_strvec(char *arg, struct strvec *);
 int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);
 
 /* Bits in the flags parameter to quote_c_style() */
-#define CQUOTE_NODQ 01
+#define CQUOTE_NODQ	     (1u << 0)
+#define CQUOTE_IGNORE_CONFIG (1u << 1)
 size_t quote_c_style(const char *name, struct strbuf *, FILE *, unsigned);
 void quote_two_c_style(struct strbuf *, const char *, const char *, unsigned);
 
-- 
2.48.1.157.g3b0d05c4a7


  reply	other threads:[~2025-02-01 20:20 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-08  3:40 [PATCH] rev-list: print missing object type with --missing=print-type Justin Tobler
2025-01-08 10:08 ` Christian Couder
2025-01-08 22:28   ` Justin Tobler
2025-01-08 15:17 ` Junio C Hamano
2025-01-08 22:18   ` Justin Tobler
2025-01-08 22:43     ` Junio C Hamano
2025-01-08 23:13       ` Justin Tobler
2025-01-10  5:34 ` [PATCH v2 0/2] rev-list: print additional missing object information Justin Tobler
2025-02-01 20:16   ` [PATCH v3 0/4] " Justin Tobler
2025-02-01 20:16     ` Justin Tobler [this message]
2025-02-03  9:51       ` [PATCH v3 1/4] quote: add c quote flag to ignore core.quotePath Christian Couder
2025-02-03 22:14         ` Junio C Hamano
2025-02-03 22:33       ` Junio C Hamano
2025-02-04 16:40         ` Junio C Hamano
2025-02-04 22:50           ` Justin Tobler
2025-02-01 20:16     ` [PATCH v3 2/4] quote: add quote_path() flag to ignore config Justin Tobler
2025-02-02 10:52       ` Phillip Wood
2025-02-04 22:39         ` Justin Tobler
2025-02-11 16:51           ` Phillip Wood
2025-02-03 10:07       ` Christian Couder
2025-02-03 22:52       ` Junio C Hamano
2025-02-01 20:16     ` [PATCH v3 3/4] rev-list: add print-info action to print missing object path Justin Tobler
2025-02-01 20:16     ` [PATCH v3 4/4] rev-list: extend print-info to print missing object type Justin Tobler
2025-02-03 10:45     ` [PATCH v3 0/4] rev-list: print additional missing object information Christian Couder
2025-02-04 22:51       ` Justin Tobler
2025-02-05  0:41     ` [PATCH v4 0/2] " Justin Tobler
2025-02-05  0:41       ` [PATCH v4 1/2] rev-list: add print-info action to print missing object path Justin Tobler
2025-02-05  0:41       ` [PATCH v4 2/2] rev-list: extend print-info to print missing object type Justin Tobler
2025-02-05 10:35       ` [PATCH v4 0/2] rev-list: print additional missing object information Christian Couder
2025-02-05 17:18         ` Justin Tobler
2025-02-05 13:18       ` Junio C Hamano
2025-02-05 17:17         ` Justin Tobler
2025-02-05 18:29           ` Junio C Hamano
2025-01-10  5:34 ` [PATCH v2 1/2] rev-list: add --missing-info to print missing object path Justin Tobler
2025-01-10  8:47   ` Christian Couder
2025-01-10 15:22     ` Junio C Hamano
2025-01-10  5:34 ` [PATCH v2 2/2] rev-list: extend --missing-info to print missing object type Justin Tobler

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=20250201201658.11562-2-jltobler@gmail.com \
    --to=jltobler@gmail.com \
    --cc=christian.couder@gmail.com \
    --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.