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>
This commit is contained in:
Junio C Hamano 2006-12-30 12:20:43 -08:00
Родитель 7cbcf4d557
Коммит 677cfed56a
3 изменённых файлов: 12 добавлений и 2 удалений

Просмотреть файл

@ -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 */ /* Not having i18n.commitencoding is the same as having utf-8 */
encoding_is_utf8 = (!git_commit_encoding || encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
!strcmp(git_commit_encoding, "utf-8"));
init_buffer(&buffer, &size); init_buffer(&buffer, &size);
add_buffer(&buffer, &size, "tree %s\n", sha1_to_hex(tree_sha1)); add_buffer(&buffer, &size, "tree %s\n", sha1_to_hex(tree_sha1));

9
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 * Given a buffer and its encoding, return it re-encoded
* with iconv. If the conversion fails, returns NULL. * with iconv. If the conversion fails, returns NULL.

2
utf8.h
Просмотреть файл

@ -3,6 +3,8 @@
int utf8_width(const char **start); int utf8_width(const char **start);
int is_utf8(const char *text); 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); void print_wrapped_text(const char *text, int indent, int indent2, int len);
#ifndef NO_ICONV #ifndef NO_ICONV