git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 1/4] quote: add c quote flag to ignore core.quotePath

From
Justin Tobler <jltobler@gmail.com>
Date
Feb 1, 2025, 20:16 UTC
Message-ID
<20250201201658.11562-2-jltobler@gmail.com>
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
Previous: Justin ToblerNext: Christian Couder
Message 10 of 37 in “rev-list: print missing object type with --missing=print-type”
  1. rev-list: print missing object type with --missing=print-typeJustin Tobler, Jan 8, 2025
  2. Christian CouderJan 8, 2025
  3. Justin ToblerJan 8, 2025
  4. Junio C HamanoJan 8, 2025
  5. Justin ToblerJan 8, 2025
  6. Junio C HamanoJan 8, 2025
  7. Justin ToblerJan 8, 2025
  8. 0/2 rev-list: print additional missing object informationJustin Tobler, Jan 10, 2025
  9. 0/4 rev-list: print additional missing object informationJustin Tobler, Feb 1, 2025
  10. 1/4 quote: add c quote flag to ignore core.quotePathJustin Tobler, Feb 1, 2025
  11. Christian CouderFeb 3, 2025
  12. Junio C HamanoFeb 3, 2025
  13. Junio C HamanoFeb 3, 2025
  14. Junio C HamanoFeb 4, 2025
  15. Justin ToblerFeb 4, 2025
  16. 2/4 quote: add quote_path() flag to ignore configJustin Tobler, Feb 1, 2025
  17. Phillip WoodFeb 2, 2025
  18. Justin ToblerFeb 4, 2025
  19. Phillip WoodFeb 11, 2025
  20. Christian CouderFeb 3, 2025
  21. Junio C HamanoFeb 3, 2025
  22. 3/4 rev-list: add print-info action to print missing object pathJustin Tobler, Feb 1, 2025
  23. 4/4 rev-list: extend print-info to print missing object typeJustin Tobler, Feb 1, 2025
  24. Christian CouderFeb 3, 2025
  25. Justin ToblerFeb 4, 2025
  26. 0/2 rev-list: print additional missing object informationJustin Tobler, Feb 5, 2025
  27. 1/2 rev-list: add print-info action to print missing object pathJustin Tobler, Feb 5, 2025
  28. 2/2 rev-list: extend print-info to print missing object typeJustin Tobler, Feb 5, 2025
  29. Christian CouderFeb 5, 2025
  30. Justin ToblerFeb 5, 2025
  31. Junio C HamanoFeb 5, 2025
  32. Justin ToblerFeb 5, 2025
  33. Junio C HamanoFeb 5, 2025
  34. 1/2 rev-list: add --missing-info to print missing object pathJustin Tobler, Jan 10, 2025
  35. Christian CouderJan 10, 2025
  36. Junio C HamanoJan 10, 2025
  37. 2/2 rev-list: extend --missing-info to print missing object typeJustin Tobler, Jan 10, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.