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