Skip to content

Commit 4c6ac2d

Browse files
committed
Merge branch 'tb/precompose-prefix-simplify'
Streamline the codepath to fix the UTF-8 encoding issues in the argv[] and the prefix on macOS. * tb/precompose-prefix-simplify: macOS: precompose startup_info->prefix precompose_utf8: make precompose_string_if_needed() public
2 parents 1d5fbd4 + c7d0e61 commit 4c6ac2d

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

compat/precompose_utf8.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ void probe_utf8_pathname_composition(void)
6060
strbuf_release(&path);
6161
}
6262

63-
static inline const char *precompose_string_if_needed(const char *in)
63+
const char *precompose_string_if_needed(const char *in)
6464
{
6565
size_t inlen;
6666
size_t outlen;
67+
if (!in)
68+
return NULL;
6769
if (has_non_ascii(in, (size_t)-1, &inlen)) {
6870
iconv_t ic_prec;
6971
char *out;
@@ -96,10 +98,7 @@ const char *precompose_argv_prefix(int argc, const char **argv, const char *pref
9698
argv[i] = precompose_string_if_needed(argv[i]);
9799
i++;
98100
}
99-
if (prefix) {
100-
prefix = precompose_string_if_needed(prefix);
101-
}
102-
return prefix;
101+
return precompose_string_if_needed(prefix);
103102
}
104103

105104

compat/precompose_utf8.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef struct {
2929
} PREC_DIR;
3030

3131
const char *precompose_argv_prefix(int argc, const char **argv, const char *prefix);
32+
const char *precompose_string_if_needed(const char *in);
3233
void probe_utf8_pathname_composition(void);
3334

3435
PREC_DIR *precompose_utf8_opendir(const char *dirname);

git-compat-util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ static inline const char *precompose_argv_prefix(int argc, const char **argv, co
256256
{
257257
return prefix;
258258
}
259+
static inline const char *precompose_string_if_needed(const char *in)
260+
{
261+
return in;
262+
}
263+
259264
#define probe_utf8_pathname_composition()
260265
#endif
261266

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
423423
int nongit_ok;
424424
prefix = setup_git_directory_gently(&nongit_ok);
425425
}
426-
prefix = precompose_argv_prefix(argc, argv, prefix);
426+
precompose_argv_prefix(argc, argv, NULL);
427427
if (use_pager == -1 && p->option & (RUN_SETUP | RUN_SETUP_GENTLY) &&
428428
!(p->option & DELAY_PAGER_CONFIG))
429429
use_pager = check_pager_config(p->cmd);

setup.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,18 +1274,10 @@ const char *setup_git_directory_gently(int *nongit_ok)
12741274
* the GIT_PREFIX environment variable must always match. For details
12751275
* see Documentation/config/alias.txt.
12761276
*/
1277-
if (nongit_ok && *nongit_ok) {
1277+
if (nongit_ok && *nongit_ok)
12781278
startup_info->have_repository = 0;
1279-
startup_info->prefix = NULL;
1280-
setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
1281-
} else {
1279+
else
12821280
startup_info->have_repository = 1;
1283-
startup_info->prefix = prefix;
1284-
if (prefix)
1285-
setenv(GIT_PREFIX_ENVIRONMENT, prefix, 1);
1286-
else
1287-
setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
1288-
}
12891281

12901282
/*
12911283
* Not all paths through the setup code will call 'set_git_dir()' (which
@@ -1311,6 +1303,22 @@ const char *setup_git_directory_gently(int *nongit_ok)
13111303
if (startup_info->have_repository)
13121304
repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
13131305
}
1306+
/*
1307+
* Since precompose_string_if_needed() needs to look at
1308+
* the core.precomposeunicode configuration, this
1309+
* has to happen after the above block that finds
1310+
* out where the repository is, i.e. a preparation
1311+
* for calling git_config_get_bool().
1312+
*/
1313+
if (prefix) {
1314+
prefix = precompose_string_if_needed(prefix);
1315+
startup_info->prefix = prefix;
1316+
setenv(GIT_PREFIX_ENVIRONMENT, prefix, 1);
1317+
} else {
1318+
startup_info->prefix = NULL;
1319+
setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
1320+
}
1321+
13141322

13151323
strbuf_release(&dir);
13161324
strbuf_release(&gitdir);

0 commit comments

Comments
 (0)