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

[RFC 2/8] Messages in locale.

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
May 12, 2009, 22:50 UTC
Message-ID
<1242168631-30753-3-git-send-email-robin.rosenberg@dewire.com>
In-Reply-To
<1242168631-30753-2-git-send-email-robin.rosenberg@dewire.com>
---
 builtin-cat-file.c    |    6 +++++-
 builtin-commit-tree.c |    9 ++++++---
 git-rebase.sh         |    1 +
 log-tree.c            |    4 +++-
 refs.c                |   11 ++++++++---
 t/t-utf-msg.sh        |   43 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 66 insertions(+), 8 deletions(-)
 create mode 100755 t/t-utf-msg.sh
diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index 6c16bfa..ff275bf 100644
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
@@ -145,6 +145,10 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
 	if (!buf)
 		die("git-cat-file %s: bad file", argv[2]);
 
-	write_or_die(1, buf, size);
+	size_t localsize = locallen(buf,size);
+	char *localbuf = xcalloc(localsize+1,1);
+	localcpy(localbuf, buf, size+1);
+	write_or_die(1, localbuf, localsize);
+	free(localbuf);
 	return 0;
 }
diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c
index e2e690a..8d87ec7 100644
--- a/builtin-commit-tree.c
+++ b/builtin-commit-tree.c
@@ -23,16 +23,19 @@ static void init_buffer(char **bufp, unsigned int *sizep)
 static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)
 {
 	char one_line[2048];
+	char one_line_utf[2048];
 	va_list args;
-	int len;
+	int len,len_utf;
 	unsigned long alloc, size, newsize;
 	char *buf;
 
 	va_start(args, fmt);
 	len = vsnprintf(one_line, sizeof(one_line), fmt, args);
 	va_end(args);
+	utfcpy(one_line_utf, one_line, len + 1);
+	len_utf = strlen(one_line_utf);
 	size = *sizep;
-	newsize = size + len;
+	newsize = size + len_utf;
 	alloc = (size + 32767) & ~32767;
 	buf = *bufp;
 	if (newsize > alloc) {
@@ -41,7 +44,7 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)
 		*bufp = buf;
 	}
 	*sizep = newsize;
-	memcpy(buf + size, one_line, len);
+	memcpy(buf + size, one_line_utf, len_utf);
 }
 
 static void check_valid(unsigned char *sha1, const char *expect)
diff --git a/git-rebase.sh b/git-rebase.sh
index 546fa44..939ac40 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -296,6 +296,7 @@ fi
 
 if test -z "$do_merge"
 then
+	LC_CTYPE=sv_SE.UTF-8 \
 	git-format-patch -k --stdout --full-index --ignore-if-in-upstream "$upstream"..ORIG_HEAD |
 	git am --binary -3 -k --resolvemsg="$RESOLVEMSG" \
 		--reflog-action=rebase
diff --git a/log-tree.c b/log-tree.c
index fbe1399..7c2564d 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -104,6 +104,7 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff)
 void show_log(struct rev_info *opt, const char *sep)
 {
 	static char this_header[16384];
+	static char this_header_local[16384];
 	struct log_info *log = opt->loginfo;
 	struct commit *commit = log->commit, *parent = log->parent;
 	int abbrev = opt->diffopt.abbrev;
@@ -217,7 +218,8 @@ void show_log(struct rev_info *opt, const char *sep)
 	if (opt->add_signoff)
 		len = append_signoff(this_header, sizeof(this_header), len,
 				     opt->add_signoff);
-	printf("%s%s%s", this_header, extra, sep);
+	localcpy(this_header_local, this_header, len+1);
+	printf("%s%s%s", this_header_local, extra, sep);
 }
 
 int log_tree_diff_flush(struct rev_info *opt)
diff --git a/refs.c b/refs.c
index 98327d7..cfe2704 100644
--- a/refs.c
+++ b/refs.c
@@ -363,8 +363,9 @@ static int log_ref_write(struct ref_lock *lock,
 	const unsigned char *sha1, const char *msg)
 {
 	int logfd, written, oflags = O_APPEND | O_WRONLY;
-	unsigned maxlen, len;
+	unsigned maxlen, len, len_utf;
 	char *logrec;
+	char *logrec_utf;
 	const char *committer;
 
 	if (log_all_ref_updates) {
@@ -400,10 +401,14 @@ static int log_ref_write(struct ref_lock *lock,
 			sha1_to_hex(sha1),
 			committer);
 	}
-	written = len <= maxlen ? write(logfd, logrec, len) : -1;
+	logrec_utf = xmalloc(len*6);
+	utfcpy(logrec_utf, logrec, len + 1);
+	len_utf = strlen(logrec_utf);
+	written = len_utf <= maxlen ? write(logfd, logrec_utf, len_utf) : -1;
 	free(logrec);
+	free(logrec_utf);
 	close(logfd);
-	if (written != len)
+	if (written != len_utf)
 		return error("Unable to append to %s", lock->log_file);
 	return 0;
 }
diff --git a/t/t-utf-msg.sh b/t/t-utf-msg.sh
new file mode 100755
index 0000000..727d497
--- /dev/null
+++ b/t/t-utf-msg.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+test_description='Test charset management.
+
+This assumes normal tests works fine
+and concentrates commit messages and other
+descriptive data.'
+
+. ./test-lib.sh
+
+export GIT_AUTHOR_NAME='Pär Nördsson'
+export GIT_COMMITTER_NAME='Pär Nördsson'
+export GIT_AUTHOR_DATE='Thu Sep 14 22:54:30 2006 +0000'
+export GIT_COMMITTER_DATE='Thu Sep 14 22:54:30 2006 +0000'
+
+test_expect_success \
+    'add simple text file' \
+    'echo hej >aland.txt &&
+    git-add aland.txt &&
+    git-commit -a -m "Ändrad" &&
+    echo test $(git-ls-files) = "aland.txt\"" &&
+    LC_CTYPE=sv_SE.UTF-8 echo test $(git-ls-files) = "aland.txt\""
+    '
+
+cat >>expected <<EOF
+commit 6905219c78beda5d5efd2a5fe4fbe0a8757bb355
+Author: Pär Nördsson <author@example.com>
+Date:   Thu Sep 14 22:54:30 2006 +0000
+
+    Ändrad
+EOF
+
+test_expect_success \
+    'log' \
+    '
+    git log >actual &&
+    diff -u actual expected
+    '
+
+# todo: git-cat-file commit xxxxxxxxxxxxx
+
+test_done
+
-- 
1.6.3.dirty
Previous: Robin RosenbergNext: Robin Rosenberg
Message 3 of 20 in “[RFC 0/8] Antique UTF-8 filename support”
  1. Robin RosenbergMay 12, 2009
  2. 1/8 UTF helpersRobin Rosenberg, May 12, 2009
  3. 2/8 Messages in locale.Robin Rosenberg, May 12, 2009
  4. 3/8 Extend tests to cover locale wrt to commit messages.Robin Rosenberg, May 12, 2009
  5. 4/8 UTF file names.Robin Rosenberg, May 12, 2009
  6. Johannes SchindelinMay 13, 2009
  7. Robin RosenbergMay 13, 2009
  8. Esko LuontolaMay 13, 2009
  9. Andreas EricssonMay 13, 2009
  10. Esko LuontolaMay 13, 2009
  11. Alex RiesenMay 13, 2009
  12. Junio C HamanoMay 13, 2009
  13. Esko LuontolaMay 13, 2009
  14. Junio C HamanoMay 13, 2009
  15. Johannes SchindelinMay 13, 2009
  16. Junio C HamanoMay 14, 2009
  17. Jay SoffianMay 14, 2009
  18. 6/8 test of utf_locallinksRobin Rosenberg, May 12, 2009
  19. 7/8 Convert symlink dest in diffRobin Rosenberg, May 12, 2009
  20. 8/8 UTF-8 in non-SHA1-objectsRobin Rosenberg, May 12, 2009

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.