summaryrefslogtreecommitdiff
path: root/builtin-commit-tree.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2006-12-22 22:06:08 +0100
committerJunio C Hamano <junkio@cox.net>2006-12-24 00:32:49 -0800
commit9e83266525aad5c6210b9a21be9b1c6996d5544f (patch)
tree8895723b2443360f01703d41eb9f813dbca0ac93 /builtin-commit-tree.c
parent8e554429e8a9dbb5dba6b8aeca66fc27c0bb5538 (diff)
downloadgit-9e83266525aad5c6210b9a21be9b1c6996d5544f.tar.gz
commit-tree: encourage UTF-8 commit messages.
Introduce is_utf() to check if a text looks like it is encoded in UTF-8, utf8_width() to count display width, and implements print_wrapped_text() using them. git-commit-tree warns if the commit message does not minimally conform to the UTF-8 encoding when i18n.commitencoding is either unset, or set to "utf-8". Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-commit-tree.c')
-rw-r--r--builtin-commit-tree.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c
index bc28770664..f641787988 100644
--- a/builtin-commit-tree.c
+++ b/builtin-commit-tree.c
@@ -7,6 +7,7 @@
#include "commit.h"
#include "tree.h"
#include "builtin.h"
+#include "utf8.h"
#define BLOCKING (1ul << 14)
@@ -32,7 +33,7 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)
len = vsnprintf(one_line, sizeof(one_line), fmt, args);
va_end(args);
size = *sizep;
- newsize = size + len;
+ newsize = size + len + 1;
alloc = (size + 32767) & ~32767;
buf = *bufp;
if (newsize > alloc) {
@@ -40,7 +41,7 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)
buf = xrealloc(buf, alloc);
*bufp = buf;
}
- *sizep = newsize;
+ *sizep = newsize - 1;
memcpy(buf + size, one_line, len);
}
@@ -77,6 +78,11 @@ static int new_parent(int idx)
return 1;
}
+static const char commit_utf8_warn[] =
+"Warning: commit message does not conform to UTF-8.\n"
+"You may want to amend it after fixing the message, or set the config\n"
+"variable i18n.commitencoding to the encoding your project uses.\n";
+
int cmd_commit_tree(int argc, const char **argv, const char *prefix)
{
int i;
@@ -130,6 +136,11 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
while (fgets(comment, sizeof(comment), stdin) != NULL)
add_buffer(&buffer, &size, "%s", comment);
+ /* And check the encoding */
+ buffer[size] = '\0';
+ if (!strcmp(git_commit_encoding, "utf-8") && !is_utf8(buffer))
+ fprintf(stderr, commit_utf8_warn);
+
if (!write_sha1_file(buffer, size, commit_type, commit_sha1)) {
printf("%s\n", sha1_to_hex(commit_sha1));
return 0;