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

[PATCH v6 6/7] convert: add tracing for 'working-tree-encoding' attribute

From
lars.schneider@autodesk.com <lars.schneider@autodesk.com>
Date
Feb 9, 2018, 13:28 UTC
Message-ID
<20180209132830.55385-7-lars.schneider@autodesk.com>
In-Reply-To
<20180209132830.55385-1-lars.schneider@autodesk.com>
From: Lars Schneider <larsxschneider@gmail.com>

Add the GIT_TRACE_WORKING_TREE_ENCODING environment variable to enable tracing for content that is reencoded with the 'working-tree-encoding' attribute. This is useful to debug encoding issues.

Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
---
 convert.c                        | 25 +++++++++++++++++++++++++
 t/t0028-working-tree-encoding.sh |  2 ++
 2 files changed, 27 insertions(+)
diff --git a/convert.c b/convert.c
index dc9e2db6b5..5b49416ee1 100644
--- a/convert.c
+++ b/convert.c
@@ -266,6 +266,29 @@ static int will_convert_lf_to_crlf(size_t len, struct text_stat *stats,
 
 }
 
+static void trace_encoding(const char *context, const char *path,
+			   const char *encoding, const char *buf, size_t len)
+{
+	static struct trace_key coe = TRACE_KEY_INIT(WORKING_TREE_ENCODING);
+	struct strbuf trace = STRBUF_INIT;
+	int i;
+
+	strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding);
+	for (i = 0; i < len && buf; ++i) {
+		strbuf_addf(
+			&trace,"| \e[2m%2i:\e[0m %2x \e[2m%c\e[0m%c",
+			i,
+			(unsigned char) buf[i],
+			(buf[i] > 32 && buf[i] < 127 ? buf[i] : ' '),
+			((i+1) % 8 && (i+1) < len ? ' ' : '\n')
+		);
+	}
+	strbuf_addchars(&trace, '\n', 1);
+
+	trace_strbuf(&coe, &trace);
+	strbuf_release(&trace);
+}
+
 static struct encoding {
 	const char *name;
 	struct encoding *next;
@@ -325,6 +348,7 @@ static int encode_to_git(const char *path, const char *src, size_t src_len,
 			error(error_msg, path, enc->name);
 	}
 
+	trace_encoding("source", path, enc->name, src, src_len);
 	dst = reencode_string_len(src, src_len, default_encoding, enc->name,
 				  &dst_len);
 	if (!dst) {
@@ -340,6 +364,7 @@ static int encode_to_git(const char *path, const char *src, size_t src_len,
 		else
 			error(msg, path, enc->name, default_encoding);
 	}
+	trace_encoding("destination", path, default_encoding, dst, dst_len);
 
 	strbuf_attach(buf, dst, dst_len, dst_len + 1);
 	return 1;
diff --git a/t/t0028-working-tree-encoding.sh b/t/t0028-working-tree-encoding.sh
index f9ce3e5ef5..01789ae1b8 100755
--- a/t/t0028-working-tree-encoding.sh
+++ b/t/t0028-working-tree-encoding.sh
@@ -4,6 +4,8 @@ test_description='working-tree-encoding conversion via gitattributes'
 
 . ./test-lib.sh
 
+GIT_TRACE_WORKING_TREE_ENCODING=1 && export GIT_TRACE_WORKING_TREE_ENCODING
+
 test_expect_success 'setup test repo' '
 	git config core.eol lf &&
 
-- 
2.16.1
Previous: lars.schneider@autodesk.comNext: Junio C Hamano
Message 12 of 14 in “convert: add support for different encodings”
  1. 0/7 convert: add support for different encodingslars.schneider@autodesk.com, Feb 9, 2018
  2. 1/7 strbuf: remove unnecessary NUL assignment in xstrdup_tolower()lars.schneider@autodesk.com, Feb 9, 2018
  3. 2/7 strbuf: add xstrdup_toupper()lars.schneider@autodesk.com, Feb 9, 2018
  4. 3/7 utf8: add function to detect prohibited UTF-16/32 BOMlars.schneider@autodesk.com, Feb 9, 2018
  5. 4/7 utf8: add function to detect a missing UTF-16/32 BOMlars.schneider@autodesk.com, Feb 9, 2018
  6. Junio C HamanoFeb 9, 2018
  7. Lars SchneiderFeb 9, 2018
  8. 5/7 convert: add 'working-tree-encoding' attributelars.schneider@autodesk.com, Feb 9, 2018
  9. Torsten BögershausenFeb 10, 2018
  10. Lars SchneiderFeb 14, 2018
  11. 7/7 convert: add round trip check based on 'core.checkRoundtripEncoding'lars.schneider@autodesk.com, Feb 9, 2018
  12. 6/7 convert: add tracing for 'working-tree-encoding' attributelars.schneider@autodesk.com, Feb 9, 2018
  13. Junio C HamanoFeb 9, 2018
  14. Lars SchneiderFeb 10, 2018

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.