From 70b5348b5704771dd4260f52c6c92b115f971292 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 17 Sep 2022 14:56:36 +0200 Subject: [PATCH 1/2] fixup! mingw: support long paths Let's avoid requiring `git_config()` to have been called all the time. Signed-off-by: Johannes Schindelin --- compat/mingw.c | 29 ++++++++++++++++++++++------- compat/mingw.h | 6 ++++-- compat/win32/dirent.c | 3 ++- compat/win32/fscache.c | 2 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 346e83056d9f75..969534681a5c6e 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -264,7 +264,27 @@ static int core_restrict_inherited_handles = -1; static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY; static char *unset_environment_variables; int core_fscache; -int core_long_paths; + +int are_long_paths_enabled(void) +{ + /* default to `false` during initialization */ + static const int fallback = 0; + + static int enabled = -1; + + if (enabled < 0) { + /* avoid infinite recursion */ + if (!the_repository) + return fallback; + + if (the_repository->config && + the_repository->config->hash_initialized && + git_config_get_bool("core.longpaths", &enabled) < 0) + enabled = 0; + } + + return enabled < 0 ? fallback : enabled; +} int mingw_core_config(const char *var, const char *value, void *cb) { @@ -281,11 +301,6 @@ int mingw_core_config(const char *var, const char *value, void *cb) return 0; } - if (!strcmp(var, "core.longpaths")) { - core_long_paths = git_config_bool(var, value); - return 0; - } - if (!strcmp(var, "core.unsetenvvars")) { free(unset_environment_variables); unset_environment_variables = xstrdup(value); @@ -659,7 +674,7 @@ int mingw_mkdir(const char *path, int mode) /* CreateDirectoryW path limit is 248 (MAX_PATH - 8.3 file name) */ if (xutftowcs_path_ex(wpath, path, MAX_LONG_PATH, -1, 248, - core_long_paths) < 0) + are_long_paths_enabled()) < 0) return -1; ret = _wmkdir(wpath); diff --git a/compat/mingw.h b/compat/mingw.h index cab88e1340f5dc..c9624a932bbc0a 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -12,7 +12,9 @@ typedef _sigset_t sigset_t; #endif extern int core_fscache; -extern int core_long_paths; + +struct repository; +int are_long_paths_enabled(void); int mingw_core_config(const char *var, const char *value, void *cb); #define platform_core_config mingw_core_config @@ -647,7 +649,7 @@ static inline int xutftowcs_path(wchar_t *wcs, const char *utf) static inline int xutftowcs_long_path(wchar_t *wcs, const char *utf) { return xutftowcs_path_ex(wcs, utf, MAX_LONG_PATH, -1, MAX_PATH, - core_long_paths); + are_long_paths_enabled()); } /** diff --git a/compat/win32/dirent.c b/compat/win32/dirent.c index db3b08c84606a9..87063101f57202 100644 --- a/compat/win32/dirent.c +++ b/compat/win32/dirent.c @@ -76,7 +76,8 @@ DIR *dirent_opendir(const char *name) /* convert name to UTF-16 and check length */ if ((len = xutftowcs_path_ex(pattern, name, MAX_LONG_PATH, -1, - MAX_PATH - 2, core_long_paths)) < 0) + MAX_PATH - 2, + are_long_paths_enabled())) < 0) return NULL; /* diff --git a/compat/win32/fscache.c b/compat/win32/fscache.c index baba69b40e2c67..5edbb6150a8b0f 100644 --- a/compat/win32/fscache.c +++ b/compat/win32/fscache.c @@ -261,7 +261,7 @@ static struct fsentry *fsentry_create_list(struct fscache *cache, const struct f /* convert name to UTF-16 and check length */ if ((wlen = xutftowcs_path_ex(pattern, dir->dirent.d_name, MAX_LONG_PATH, dir->len, MAX_PATH - 2, - core_long_paths)) < 0) + are_long_paths_enabled())) < 0) return NULL; /* handle CWD */ From 04a77c905dc7a0f3c90521c25d3c8b7e3344bc38 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 17 Sep 2022 14:57:27 +0200 Subject: [PATCH 2/2] fixup! mingw: ensure that core.longPaths is handled *always* This is no longer necessary (and was fragile to begin with, as many code paths might have been missed). Signed-off-by: Johannes Schindelin --- builtin/archive.c | 2 -- builtin/bisect--helper.c | 2 -- builtin/bundle.c | 2 -- builtin/check-ref-format.c | 2 -- builtin/clone.c | 2 -- builtin/column.c | 2 -- builtin/credential-store.c | 3 --- builtin/fetch-pack.c | 2 -- builtin/get-tar-commit-id.c | 2 -- builtin/log.c | 1 - builtin/ls-remote.c | 2 -- builtin/mailinfo.c | 2 -- builtin/mailsplit.c | 2 -- builtin/merge-index.c | 3 --- builtin/merge-tree.c | 3 --- builtin/mktag.c | 1 - builtin/mktree.c | 2 -- builtin/pack-refs.c | 1 - builtin/prune-packed.c | 2 -- builtin/prune.c | 3 --- builtin/reflog.c | 1 - builtin/remote-ext.c | 2 -- builtin/remote.c | 1 - builtin/rev-parse.c | 1 - builtin/show-index.c | 2 -- builtin/show-ref.c | 1 - builtin/stripspace.c | 5 +++-- builtin/submodule--helper.c | 1 - builtin/upload-archive.c | 3 --- http-backend.c | 1 - refs.c | 2 +- 31 files changed, 4 insertions(+), 57 deletions(-) diff --git a/builtin/archive.c b/builtin/archive.c index 15fe853e0e5af9..f094390ee01f81 100644 --- a/builtin/archive.c +++ b/builtin/archive.c @@ -9,7 +9,6 @@ #include "parse-options.h" #include "pkt-line.h" #include "sideband.h" -#include "config.h" static void create_output_file(const char *output_file) { @@ -94,7 +93,6 @@ int cmd_archive(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, local_opts, NULL, PARSE_OPT_KEEP_ALL); diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 91f68252790607..501245fac95217 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -9,7 +9,6 @@ #include "prompt.h" #include "quote.h" #include "revision.h" -#include "config.h" static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS") static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV") @@ -1325,7 +1324,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) }; struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL }; - git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, options, git_bisect_helper_usage, PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN_OPT); diff --git a/builtin/bundle.c b/builtin/bundle.c index aca68bb39d8a22..e80efce3a420a0 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -3,7 +3,6 @@ #include "parse-options.h" #include "cache.h" #include "bundle.h" -#include "config.h" /* * Basic handler for bundle files to connect repositories via sneakernet. @@ -111,7 +110,6 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) { }; char *bundle_file; - git_config(git_default_config, NULL); argc = parse_options_cmd_bundle(argc, argv, prefix, builtin_bundle_verify_usage, options, &bundle_file); /* bundle internals use argv[1] as further parameters */ diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c index 2269d8df7d83c0..fd0e5f86832a0e 100644 --- a/builtin/check-ref-format.c +++ b/builtin/check-ref-format.c @@ -6,7 +6,6 @@ #include "refs.h" #include "builtin.h" #include "strbuf.h" -#include "config.h" static const char builtin_check_ref_format_usage[] = "git check-ref-format [--normalize] [] \n" @@ -61,7 +60,6 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix) char *to_free = NULL; int ret = 1; - git_config(git_default_config, NULL); if (argc == 2 && !strcmp(argv[1], "-h")) usage(builtin_check_ref_format_usage); diff --git a/builtin/clone.c b/builtin/clone.c index cde660b2a67c35..d269d6fec68ce4 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -905,8 +905,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix) struct transport_ls_refs_options transport_ls_refs_options = TRANSPORT_LS_REFS_OPTIONS_INIT; - git_config(git_default_core_config, NULL); - packet_trace_identity("clone"); git_config(git_clone_config, NULL); diff --git a/builtin/column.c b/builtin/column.c index 69718917526868..158fdf53d9fb9c 100644 --- a/builtin/column.c +++ b/builtin/column.c @@ -34,8 +34,6 @@ int cmd_column(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_default_core_config, NULL); - /* This one is special and must be the first one */ if (argc > 1 && starts_with(argv[1], "--command=")) { command = argv[1] + 10; diff --git a/builtin/credential-store.c b/builtin/credential-store.c index a693b235f34208..62a4f3c2653143 100644 --- a/builtin/credential-store.c +++ b/builtin/credential-store.c @@ -4,7 +4,6 @@ #include "credential.h" #include "string-list.h" #include "parse-options.h" -#include "config.h" static struct lock_file credential_lock; @@ -166,8 +165,6 @@ int cmd_credential_store(int argc, const char **argv, const char *prefix) umask(077); - git_config(git_default_config, NULL); - argc = parse_options(argc, (const char **)argv, prefix, options, usage, 0); if (argc != 1) usage_with_options(usage, options); diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index d958b41b47ae56..afe679368deec2 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -5,7 +5,6 @@ #include "connect.h" #include "oid-array.h" #include "protocol.h" -#include "config.h" static const char fetch_pack_usage[] = "git fetch-pack [--all] [--stdin] [--quiet | -q] [--keep | -k] [--thin] " @@ -58,7 +57,6 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix) struct packet_reader reader; enum protocol_version version; - git_config(git_default_config, NULL); fetch_if_missing = 0; packet_trace_identity("fetch-pack"); diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c index a623518ae7dc23..491af9202dc937 100644 --- a/builtin/get-tar-commit-id.c +++ b/builtin/get-tar-commit-id.c @@ -6,7 +6,6 @@ #include "tar.h" #include "builtin.h" #include "quote.h" -#include "config.h" static const char builtin_get_tar_commit_id_usage[] = "git get-tar-commit-id"; @@ -28,7 +27,6 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix) if (argc != 1) usage(builtin_get_tar_commit_id_usage); - git_config(git_default_config, NULL); n = read_in_full(0, buffer, HEADERSIZE); if (n < 0) die_errno("git get-tar-commit-id: read error"); diff --git a/builtin/log.c b/builtin/log.c index a68a6bfb9e7af3..ee19dc5d450c57 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -2437,7 +2437,6 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, options, cherry_usage, 0); switch (argc) { diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index 7398b7c4aa4cc0..df44e5cc0d1171 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -4,7 +4,6 @@ #include "ref-filter.h" #include "remote.h" #include "refs.h" -#include "config.h" static const char * const ls_remote_usage[] = { N_("git ls-remote [--heads] [--tags] [--refs] [--upload-pack=]\n" @@ -87,7 +86,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) packet_trace_identity("ls-remote"); - git_config(git_default_config, NULL); if (argc > 1) { int i; CALLOC_ARRAY(pattern, argc); diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index df6cc4172120f1..01d16ef9e5a2d6 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -8,7 +8,6 @@ #include "strbuf.h" #include "mailinfo.h" #include "parse-options.h" -#include "config.h" static const char * const mailinfo_usage[] = { /* TRANSLATORS: keep <> in "<" mail ">" info. */ @@ -79,7 +78,6 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_default_config, NULL); setup_mailinfo(&mi); meta_charset.policy = CHARSET_DEFAULT; diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c index 939c5b41975832..73509f651bda48 100644 --- a/builtin/mailsplit.c +++ b/builtin/mailsplit.c @@ -8,7 +8,6 @@ #include "builtin.h" #include "string-list.h" #include "strbuf.h" -#include "config.h" static const char git_mailsplit_usage[] = "git mailsplit [-d] [-f] [-b] [--keep-cr] -o [(|)...]"; @@ -278,7 +277,6 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix) const char **argp; static const char *stdin_only[] = { "-", NULL }; - git_config(git_default_config, NULL); for (argp = argv+1; *argp; argp++) { const char *arg = *argp; diff --git a/builtin/merge-index.c b/builtin/merge-index.c index 24e5c1f6ea9f7c..c0383fe9df9a3e 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -1,7 +1,6 @@ #define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "run-command.h" -#include "config.h" static const char *pgm; static int one_shot, quiet; @@ -78,8 +77,6 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) */ signal(SIGCHLD, SIG_DFL); - git_config(git_default_config, NULL); - if (argc < 3) usage("git merge-index [-o] [-q] (-a | [--] [...])"); diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 14126bf33c2d72..ae5782917b96c5 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -12,7 +12,6 @@ #include "exec-cmd.h" #include "merge-blobs.h" #include "quote.h" -#include "config.h" static int line_termination = '\n'; @@ -509,8 +508,6 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_default_config, NULL); - /* Parse arguments */ original_argc = argc - 1; /* ignoring argv[0] */ argc = parse_options(argc, argv, prefix, mt_options, diff --git a/builtin/mktag.c b/builtin/mktag.c index 275feb0667a4bf..5d22909122d195 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -84,7 +84,6 @@ int cmd_mktag(int argc, const char **argv, const char *prefix) builtin_mktag_options, builtin_mktag_usage, 0); - git_config(git_default_config, NULL); if (strbuf_read(&buf, 0, 0) < 0) die_errno(_("could not read from stdin")); diff --git a/builtin/mktree.c b/builtin/mktree.c index 12386110b452aa..06d81400f55815 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -8,7 +8,6 @@ #include "tree.h" #include "parse-options.h" #include "object-store.h" -#include "config.h" static struct treeent { unsigned mode; @@ -165,7 +164,6 @@ int cmd_mktree(int ac, const char **av, const char *prefix) OPT_END() }; - git_config(git_default_config, NULL); ac = parse_options(ac, av, prefix, option, mktree_usage, 0); getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf; diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c index 28f79b993862e7..cfbd5c36c7640b 100644 --- a/builtin/pack-refs.c +++ b/builtin/pack-refs.c @@ -3,7 +3,6 @@ #include "parse-options.h" #include "refs.h" #include "repository.h" -#include "config.h" static char const * const pack_refs_usage[] = { N_("git pack-refs []"), diff --git a/builtin/prune-packed.c b/builtin/prune-packed.c index 221fd881eb7b34..da3273a268b47d 100644 --- a/builtin/prune-packed.c +++ b/builtin/prune-packed.c @@ -1,7 +1,6 @@ #include "builtin.h" #include "parse-options.h" #include "prune-packed.h" -#include "config.h" static const char * const prune_packed_usage[] = { "git prune-packed [-n | --dry-run] [-q | --quiet]", @@ -19,7 +18,6 @@ int cmd_prune_packed(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, prune_packed_options, prune_packed_usage, 0); diff --git a/builtin/prune.c b/builtin/prune.c index 5dfd6a47d52fcb..df376b2ed1e092 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -9,7 +9,6 @@ #include "prune-packed.h" #include "object-store.h" #include "shallow.h" -#include "config.h" static const char * const prune_usage[] = { N_("git prune [-n] [-v] [--progress] [--expire