commit-tree: cope with different ways "utf-8" can be spelled.
authorJunio C Hamano <junkio@cox.net>
Sat, 30 Dec 2006 20:20:43 +0000 (12:20 -0800)
committerJunio C Hamano <junkio@cox.net>
Sat, 30 Dec 2006 23:58:43 +0000 (15:58 -0800)
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 <junkio@cox.net>
builtin-commit-tree.c
utf8.c
utf8.h

index 146aaffd282987454c0910477cfe7a047f478e94..0651e5927e836d22246d84020576ccb3069b6c5d 100644 (file)
@@ -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 1eedd8b61aeed9867366df0b70ac849cdef985b9..7c80eeccb4537ab6d4387941c6262c89cab30d33 100644 (file)
--- 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 cae2a8e665c2cbe7bf31a49deed84250eaa37a33..a07c5a88af63d41ae963f230510a33d78b68a525 100644 (file)
--- 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