git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: git@vger.kernel.org
Cc: Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [RFC 2/8] Messages in locale.
Date: Wed, 13 May 2009 00:50:25 +0200	[thread overview]
Message-ID: <1242168631-30753-3-git-send-email-robin.rosenberg@dewire.com> (raw)
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

  reply	other threads:[~2009-05-12 22:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-12 22:50 [RFC 0/8] Antique UTF-8 filename support Robin Rosenberg
2009-05-12 22:50 ` [RFC 1/8] UTF helpers Robin Rosenberg
2009-05-12 22:50   ` Robin Rosenberg [this message]
2009-05-12 22:50     ` [RFC 3/8] Extend tests to cover locale wrt to commit messages Robin Rosenberg
2009-05-12 22:50       ` [RFC 4/8] UTF file names Robin Rosenberg
     [not found]         ` <1242168631-30753-6-git-send-email-robin.rosenberg@dewire.com>
2009-05-12 22:50           ` [RFC 6/8] test of utf_locallinks Robin Rosenberg
2009-05-12 22:50             ` [RFC 7/8] Convert symlink dest in diff Robin Rosenberg
2009-05-12 22:50               ` [RFC 8/8] UTF-8 in non-SHA1-objects Robin Rosenberg
2009-05-13  0:20   ` [RFC 1/8] UTF helpers Johannes Schindelin
2009-05-13  5:24     ` Robin Rosenberg
2009-05-13  9:24       ` Esko Luontola
2009-05-13 10:02         ` Andreas Ericsson
2009-05-13 10:21           ` Esko Luontola
2009-05-13 11:44             ` Alex Riesen
2009-05-13 18:48         ` Junio C Hamano
2009-05-13 19:31           ` Esko Luontola
2009-05-13 20:10             ` Junio C Hamano
2009-05-13 10:14       ` Johannes Schindelin
2009-05-14  4:38       ` Junio C Hamano
2009-05-14 13:57         ` Jay Soffian

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1242168631-30753-3-git-send-email-robin.rosenberg@dewire.com \
    --to=robin.rosenberg@dewire.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).