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

[PATCH 1/2] diff: simplify quote_two()

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 15, 2021, 22:33 UTC
Message-ID
<20210915223316.1653443-2-gitster@pobox.com>
In-Reply-To
<20210915223316.1653443-1-gitster@pobox.com>

Reimplement the function as a mere thin wrapper around quote_two_c_style().

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/diff.c b/diff.c
index a8113f1707..8143b737b7 100644
--- a/diff.c
+++ b/diff.c
@@ -482,19 +482,9 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
 
 static char *quote_two(const char *one, const char *two)
 {
-	int need_one = quote_c_style(one, NULL, NULL, CQUOTE_NODQ);
-	int need_two = quote_c_style(two, NULL, NULL, CQUOTE_NODQ);
 	struct strbuf res = STRBUF_INIT;
 
-	if (need_one + need_two) {
-		strbuf_addch(&res, '"');
-		quote_c_style(one, &res, NULL, CQUOTE_NODQ);
-		quote_c_style(two, &res, NULL, CQUOTE_NODQ);
-		strbuf_addch(&res, '"');
-	} else {
-		strbuf_addstr(&res, one);
-		strbuf_addstr(&res, two);
-	}
+	quote_two_c_style(&res, one, two, 0);
 	return strbuf_detach(&res, NULL);
 }
 
-- 
2.33.0-649-gd4f4107c2b
Previous: Junio C HamanoNext: Gwyneth Morgan
Message 5 of 7 in “(experimental) diff --quote-path-with-sp”
  1. 0/2 (experimental) diff --quote-path-with-spJunio C Hamano, Sep 15, 2021
  2. 2/2 diff: --quote-path-with-spJunio C Hamano, Sep 15, 2021
  3. Ævar Arnfjörð BjarmasonSep 16, 2021
  4. Junio C HamanoSep 16, 2021
  5. 1/2 diff: simplify quote_two()Junio C Hamano, Sep 15, 2021
  6. Gwyneth MorganSep 16, 2021
  7. Junio C HamanoSep 16, 2021

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.