precompose-utf8: do not call checks for non-ascii "utf8"

As suggested by Linus, this function is not checking UTF-8-ness of the string; it only is seeing if it is pure US-ASCII. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 20, 2012 at 11:12 UTC 9a27f967055afe64dc5f7c4ed44e7ca06707e538
1 file changed +8 -8
compat/precompose_utf8.c
+8 -8
@@ -13,20 +13,20 @@ typedef char *iconv_ibp;
13 static const char *repo_encoding = "UTF-8";
14 static const char *path_encoding = "UTF-8-MAC";
15
16 -static size_t has_utf8(const char *s, size_t maxlen, size_t *strlen_c)
16 +static size_t has_non_ascii(const char *s, size_t maxlen, size_t *strlen_c)
17 {
18 - const uint8_t *utf8p = (const uint8_t *)s;
18 + const uint8_t *ptr = (const uint8_t *)s;
19 size_t strlen_chars = 0;
20 size_t ret = 0;
21
22 - if (!utf8p || !*utf8p)
22 + if (!ptr || !*ptr)
23 return 0;
24
25 - while (*utf8p && maxlen) {
26 - if (*utf8p & 0x80)
25 + while (*ptr && maxlen) {
26 + if (*ptr & 0x80)
27 ret++;
28 strlen_chars++;
29 - utf8p++;
29 + ptr++;
30 maxlen--;
31 }
32 if (strlen_c)
@@ -77,7 +77,7 @@ void precompose_argv(int argc, const char **argv)
77 while (i < argc) {
78 size_t namelen;
79 oldarg = argv[i];
80 - if (has_utf8(oldarg, (size_t)-1, &namelen)) {
80 + if (has_non_ascii(oldarg, (size_t)-1, &namelen)) {
81 newarg = reencode_string_iconv(oldarg, namelen, ic_precompose);
82 if (newarg)
83 argv[i] = newarg;
@@ -130,7 +130,7 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
130 prec_dir->dirent_nfc->d_ino = res->d_ino;
131 prec_dir->dirent_nfc->d_type = res->d_type;
132
133 - if ((precomposed_unicode == 1) && has_utf8(res->d_name, (size_t)-1, NULL)) {
133 + if ((precomposed_unicode == 1) && has_non_ascii(res->d_name, (size_t)-1, NULL)) {
134 if (prec_dir->ic_precompose == (iconv_t)-1) {
135 die("iconv_open(%s,%s) failed, but needed:\n"
136 " precomposed unicode is not supported.\n"