@matheusbsbs / matheus-bagliano / commits / 677cfed56a
Fork 0

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 <junkio@cox.net>

Junio C Hamano committed Dec 30, 2006 at 12:20 UTC 677cfed56ac530878b746ee4cca3ada8af384a81
3 files changed +12 -2
builtin-commit-tree.c
+1 -2
@@ -119,8 +119,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
119 }
120
121 /* Not having i18n.commitencoding is the same as having utf-8 */
122 - encoding_is_utf8 = (!git_commit_encoding ||
123 - !strcmp(git_commit_encoding, "utf-8"));
122 + encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
123
124 init_buffer(&buffer, &size);
125 add_buffer(&buffer, &size, "tree %s\n", sha1_to_hex(tree_sha1));
utf8.c
+9
@@ -277,6 +277,15 @@ void print_wrapped_text(const char *text, int indent, int indent2, int width)
277 }
278 }
279
280 +int is_encoding_utf8(const char *name)
281 +{
282 + if (!name)
283 + return 1;
284 + if (!strcasecmp(name, "utf-8") || !strcasecmp(name, "utf8"))
285 + return 1;
286 + return 0;
287 +}
288 +
289 /*
290 * Given a buffer and its encoding, return it re-encoded
291 * with iconv. If the conversion fails, returns NULL.
utf8.h
+2
@@ -3,6 +3,8 @@
3
4 int utf8_width(const char **start);
5 int is_utf8(const char *text);
6 +int is_encoding_utf8(const char *name);
7 +
8 void print_wrapped_text(const char *text, int indent, int indent2, int len);
9
10 #ifndef NO_ICONV