From: Junio C Hamano Date: Sat, 30 Dec 2006 20:20:43 +0000 (-0800) Subject: commit-tree: cope with different ways "utf-8" can be spelled. X-Git-Tag: v1.5.0-rc1~147 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=677cfed56ac530878b746ee4cca3ada8af384a81;p=git.git commit-tree: cope with different ways "utf-8" can be spelled. People can spell config.commitencoding differently from what we internally have ("utf-8") to mean UTF-8. Try to accept them and treat them equally. Signed-off-by: Junio C Hamano --- diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c index 146aaffd2..0651e5927 100644 --- a/builtin-commit-tree.c +++ b/builtin-commit-tree.c @@ -119,8 +119,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) } /* Not having i18n.commitencoding is the same as having utf-8 */ - encoding_is_utf8 = (!git_commit_encoding || - !strcmp(git_commit_encoding, "utf-8")); + encoding_is_utf8 = is_encoding_utf8(git_commit_encoding); init_buffer(&buffer, &size); add_buffer(&buffer, &size, "tree %s\n", sha1_to_hex(tree_sha1)); diff --git a/utf8.c b/utf8.c index 1eedd8b61..7c80eeccb 100644 --- a/utf8.c +++ b/utf8.c @@ -277,6 +277,15 @@ void print_wrapped_text(const char *text, int indent, int indent2, int width) } } +int is_encoding_utf8(const char *name) +{ + if (!name) + return 1; + if (!strcasecmp(name, "utf-8") || !strcasecmp(name, "utf8")) + return 1; + return 0; +} + /* * Given a buffer and its encoding, return it re-encoded * with iconv. If the conversion fails, returns NULL. diff --git a/utf8.h b/utf8.h index cae2a8e66..a07c5a88a 100644 --- a/utf8.h +++ b/utf8.h @@ -3,6 +3,8 @@ int utf8_width(const char **start); int is_utf8(const char *text); +int is_encoding_utf8(const char *name); + void print_wrapped_text(const char *text, int indent, int indent2, int len); #ifndef NO_ICONV