Git fork

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

+29 -16
+4 -5
compat/precompose_utf8.c
··· 60 60 strbuf_release(&path); 61 61 } 62 62 63 - static inline const char *precompose_string_if_needed(const char *in) 63 + const char *precompose_string_if_needed(const char *in) 64 64 { 65 65 size_t inlen; 66 66 size_t outlen; 67 + if (!in) 68 + return NULL; 67 69 if (has_non_ascii(in, (size_t)-1, &inlen)) { 68 70 iconv_t ic_prec; 69 71 char *out; ··· 96 98 argv[i] = precompose_string_if_needed(argv[i]); 97 99 i++; 98 100 } 99 - if (prefix) { 100 - prefix = precompose_string_if_needed(prefix); 101 - } 102 - return prefix; 101 + return precompose_string_if_needed(prefix); 103 102 } 104 103 105 104
+1
compat/precompose_utf8.h
··· 29 29 } PREC_DIR; 30 30 31 31 const char *precompose_argv_prefix(int argc, const char **argv, const char *prefix); 32 + const char *precompose_string_if_needed(const char *in); 32 33 void probe_utf8_pathname_composition(void); 33 34 34 35 PREC_DIR *precompose_utf8_opendir(const char *dirname);
+5
git-compat-util.h
··· 256 256 { 257 257 return prefix; 258 258 } 259 + static inline const char *precompose_string_if_needed(const char *in) 260 + { 261 + return in; 262 + } 263 + 259 264 #define probe_utf8_pathname_composition() 260 265 #endif 261 266
+1 -1
git.c
··· 423 423 int nongit_ok; 424 424 prefix = setup_git_directory_gently(&nongit_ok); 425 425 } 426 - prefix = precompose_argv_prefix(argc, argv, prefix); 426 + precompose_argv_prefix(argc, argv, NULL); 427 427 if (use_pager == -1 && p->option & (RUN_SETUP | RUN_SETUP_GENTLY) && 428 428 !(p->option & DELAY_PAGER_CONFIG)) 429 429 use_pager = check_pager_config(p->cmd);
+18 -10
setup.c
··· 1274 1274 * the GIT_PREFIX environment variable must always match. For details 1275 1275 * see Documentation/config/alias.txt. 1276 1276 */ 1277 - if (nongit_ok && *nongit_ok) { 1277 + if (nongit_ok && *nongit_ok) 1278 1278 startup_info->have_repository = 0; 1279 - startup_info->prefix = NULL; 1280 - setenv(GIT_PREFIX_ENVIRONMENT, "", 1); 1281 - } else { 1279 + else 1282 1280 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 - } 1289 1281 1290 1282 /* 1291 1283 * Not all paths through the setup code will call 'set_git_dir()' (which ··· 1311 1303 if (startup_info->have_repository) 1312 1304 repo_set_hash_algo(the_repository, repo_fmt.hash_algo); 1313 1305 } 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 + 1314 1322 1315 1323 strbuf_release(&dir); 1316 1324 strbuf_release(&gitdir);