Skip to content

Commit 183154b

Browse files
committed
Merge branch 'rr/precompose-utf8-cleanup'
* rr/precompose-utf8-cleanup: precompose-utf8: do not call checks for non-ascii "utf8" cleanup precompose_utf8
2 parents 9a245ac + 9a27f96 commit 183154b

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

compat/precompose_utf8.c

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/*
22
* Converts filenames from decomposed unicode into precomposed unicode.
33
* Used on MacOS X.
4-
*/
5-
4+
*/
65

76
#define PRECOMPOSE_UNICODE_C
87

@@ -11,25 +10,23 @@
1110
#include "precompose_utf8.h"
1211

1312
typedef char *iconv_ibp;
14-
const static char *repo_encoding = "UTF-8";
15-
const static char *path_encoding = "UTF-8-MAC";
16-
13+
static const char *repo_encoding = "UTF-8";
14+
static const char *path_encoding = "UTF-8-MAC";
1715

18-
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)
1917
{
20-
const uint8_t *utf8p = (const uint8_t*) s;
18+
const uint8_t *ptr = (const uint8_t *)s;
2119
size_t strlen_chars = 0;
2220
size_t ret = 0;
2321

24-
if ((!utf8p) || (!*utf8p)) {
22+
if (!ptr || !*ptr)
2523
return 0;
26-
}
2724

28-
while((*utf8p) && maxlen) {
29-
if (*utf8p & 0x80)
25+
while (*ptr && maxlen) {
26+
if (*ptr & 0x80)
3027
ret++;
3128
strlen_chars++;
32-
utf8p++;
29+
ptr++;
3330
maxlen--;
3431
}
3532
if (strlen_c)
@@ -41,26 +38,24 @@ static size_t has_utf8(const char *s, size_t maxlen, size_t *strlen_c)
4138

4239
void probe_utf8_pathname_composition(char *path, int len)
4340
{
44-
const static char *auml_nfc = "\xc3\xa4";
45-
const static char *auml_nfd = "\x61\xcc\x88";
41+
static const char *auml_nfc = "\xc3\xa4";
42+
static const char *auml_nfd = "\x61\xcc\x88";
4643
int output_fd;
4744
if (precomposed_unicode != -1)
4845
return; /* We found it defined in the global config, respect it */
49-
path[len] = 0;
5046
strcpy(path + len, auml_nfc);
5147
output_fd = open(path, O_CREAT|O_EXCL|O_RDWR, 0600);
52-
if (output_fd >=0) {
48+
if (output_fd >= 0) {
5349
close(output_fd);
54-
path[len] = 0;
5550
strcpy(path + len, auml_nfd);
5651
/* Indicate to the user, that we can configure it to true */
57-
if (0 == access(path, R_OK))
52+
if (!access(path, R_OK))
5853
git_config_set("core.precomposeunicode", "false");
59-
/* To be backward compatible, set precomposed_unicode to 0 */
54+
/* To be backward compatible, set precomposed_unicode to 0 */
6055
precomposed_unicode = 0;
61-
path[len] = 0;
6256
strcpy(path + len, auml_nfc);
63-
unlink(path);
57+
if (unlink(path))
58+
die_errno(_("failed to unlink '%s'"), path);
6459
}
6560
}
6661

@@ -82,7 +77,7 @@ void precompose_argv(int argc, const char **argv)
8277
while (i < argc) {
8378
size_t namelen;
8479
oldarg = argv[i];
85-
if (has_utf8(oldarg, (size_t)-1, &namelen)) {
80+
if (has_non_ascii(oldarg, (size_t)-1, &namelen)) {
8681
newarg = reencode_string_iconv(oldarg, namelen, ic_precompose);
8782
if (newarg)
8883
argv[i] = newarg;
@@ -135,7 +130,7 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
135130
prec_dir->dirent_nfc->d_ino = res->d_ino;
136131
prec_dir->dirent_nfc->d_type = res->d_type;
137132

138-
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)) {
139134
if (prec_dir->ic_precompose == (iconv_t)-1) {
140135
die("iconv_open(%s,%s) failed, but needed:\n"
141136
" precomposed unicode is not supported.\n"
@@ -160,8 +155,7 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
160155
namelenz = 0; /* trigger strlcpy */
161156
}
162157
}
163-
}
164-
else
158+
} else
165159
namelenz = 0;
166160

167161
if (!namelenz)

0 commit comments

Comments
 (0)