]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: move access to core.maxTreeDepth into repo settings
authorRené Scharfe <l.s.r@web.de>
Fri, 9 Jan 2026 21:30:12 +0000 (22:30 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 10 Jan 2026 02:36:16 +0000 (18:36 -0800)
The config setting core.maxTreeDepth is stored in a global variable and
populated by the function git_default_core_config.  This won't work if
we need to access multiple repositories with different values of that
setting in the same process.  Store the setting in struct repo_settings
instead and track it separately for each repository.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
environment.c
environment.h
git-compat-util.h
list-objects.c
repo-settings.c
repo-settings.h
tree-diff.c
tree-walk.c
tree.c

index a770b5921d9546818b350157f7b4501db1261f4c..c6e5b65abac19bb2b1b1ffe050a1a1a7570fd6e6 100644 (file)
@@ -80,30 +80,6 @@ int core_sparse_checkout_cone;
 int sparse_expect_files_outside_of_patterns;
 int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
 unsigned long pack_size_limit_cfg;
-int max_allowed_tree_depth =
-#ifdef _MSC_VER
-       /*
-        * When traversing into too-deep trees, Visual C-compiled Git seems to
-        * run into some internal stack overflow detection in the
-        * `RtlpAllocateHeap()` function that is called from within
-        * `git_inflate_init()`'s call tree. The following value seems to be
-        * low enough to avoid that by letting Git exit with an error before
-        * the stack overflow can occur.
-        */
-       512;
-#elif defined(GIT_WINDOWS_NATIVE) && defined(__clang__) && defined(__aarch64__)
-       /*
-        * Similar to Visual C, it seems that on Windows/ARM64 the clang-based
-        * builds have a smaller stack space available. When running out of
-        * that stack space, a `STATUS_STACK_OVERFLOW` is produced. When the
-        * Git command was run from an MSYS2 Bash, this unfortunately results
-        * in an exit code 127. Let's prevent that by lowering the maximal
-        * tree depth; This value seems to be low enough.
-        */
-       1280;
-#else
-       2048;
-#endif
 
 #ifndef PROTECT_HFS_DEFAULT
 #define PROTECT_HFS_DEFAULT 0
@@ -569,11 +545,6 @@ static int git_default_core_config(const char *var, const char *value,
                return 0;
        }
 
-       if (!strcmp(var, "core.maxtreedepth")) {
-               max_allowed_tree_depth = git_config_int(var, value, ctx->kvi);
-               return 0;
-       }
-
        /* Add other config variables here and to Documentation/config.adoc. */
        return platform_core_config(var, value, ctx, cb);
 }
index 51898c99cd1e451a47c1a4aae32869cfbddbce45..9efe0b30fb3d8b1f7f54634d3c64465c959792a3 100644 (file)
@@ -156,7 +156,6 @@ extern char *git_attributes_file;
 extern int zlib_compression_level;
 extern int pack_compression_level;
 extern unsigned long pack_size_limit_cfg;
-extern int max_allowed_tree_depth;
 
 extern int precomposed_unicode;
 extern int protect_hfs;
index b0673d1a450db5a44f51d44bfd7e0a0d41593f1c..bebcf9f698cd39263e3ad38ebf916ae4da9dbd22 100644 (file)
@@ -578,6 +578,30 @@ static inline bool strip_suffix(const char *str, const char *suffix,
 #define DEFAULT_PACKED_GIT_LIMIT \
        ((1024L * 1024L) * (size_t)(sizeof(void*) >= 8 ? (32 * 1024L * 1024L) : 256))
 
+#ifdef _MSC_VER
+  /*
+   * When traversing into too-deep trees, Visual C-compiled Git seems to
+   * run into some internal stack overflow detection in the
+   * `RtlpAllocateHeap()` function that is called from within
+   * `git_inflate_init()`'s call tree. The following value seems to be
+   * low enough to avoid that by letting Git exit with an error before
+   * the stack overflow can occur.
+   */
+#define DEFAULT_MAX_ALLOWED_TREE_DEPTH 512
+#elif defined(GIT_WINDOWS_NATIVE) && defined(__clang__) && defined(__aarch64__)
+  /*
+   * Similar to Visual C, it seems that on Windows/ARM64 the clang-based
+   * builds have a smaller stack space available. When running out of
+   * that stack space, a `STATUS_STACK_OVERFLOW` is produced. When the
+   * Git command was run from an MSYS2 Bash, this unfortunately results
+   * in an exit code 127. Let's prevent that by lowering the maximal
+   * tree depth; This value seems to be low enough.
+   */
+#define DEFAULT_MAX_ALLOWED_TREE_DEPTH 1280
+#else
+#define DEFAULT_MAX_ALLOWED_TREE_DEPTH 2048
+#endif
+
 int git_open_cloexec(const char *name, int flags);
 #define git_open(name) git_open_cloexec(name, O_RDONLY)
 
index 42c17d9573910b26569dee08f8cd3d5ba29b77cd..1279676ddca4df3d176b13180237e7b7356eff25 100644 (file)
@@ -167,7 +167,7 @@ static void process_tree(struct traversal_context *ctx,
            !revs->include_check_obj(&tree->object, revs->include_check_data))
                return;
 
-       if (ctx->depth > max_allowed_tree_depth)
+       if (ctx->depth > revs->repo->settings.max_allowed_tree_depth)
                die("exceeded maximum allowed tree depth");
 
        failed_parse = parse_tree_gently(tree, 1);
index 195c24e9c07606f00aa4d02eaf4ad25b6642a67f..208e09ff17fcee5232daab12f7d9ac6e34a412c1 100644 (file)
@@ -100,6 +100,9 @@ void prepare_repo_settings(struct repository *r)
         */
        if (!repo_config_get_int(r, "index.version", &value))
                r->settings.index_version = value;
+       repo_cfg_int(r, "core.maxtreedepth",
+                    &r->settings.max_allowed_tree_depth,
+                    DEFAULT_MAX_ALLOWED_TREE_DEPTH);
 
        if (!repo_config_get_string_tmp(r, "core.untrackedcache", &strval)) {
                int v = git_parse_maybe_bool(strval);
index d477885561449727db7fbc2ca8ece2280c4e7610..cad9c3f0cc15f32c9d6710efb3700f6734d3f63a 100644 (file)
@@ -67,6 +67,8 @@ struct repo_settings {
        size_t packed_git_limit;
        unsigned long big_file_threshold;
 
+       int max_allowed_tree_depth;
+
        char *hooks_path;
 };
 #define REPO_SETTINGS_INIT { \
@@ -78,6 +80,7 @@ struct repo_settings {
        .delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT, \
        .packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE, \
        .packed_git_limit = DEFAULT_PACKED_GIT_LIMIT, \
+       .max_allowed_tree_depth = DEFAULT_MAX_ALLOWED_TREE_DEPTH, \
 }
 
 void prepare_repo_settings(struct repository *r);
index 5988148b602536048c9d991ab07256c43ccf93bd..631ea868124256a09052abe697160ed4baf7d70c 100644 (file)
@@ -439,7 +439,7 @@ static void ll_diff_tree_paths(
        void *ttree, **tptree;
        int i;
 
-       if (depth > max_allowed_tree_depth)
+       if (depth > opt->repo->settings.max_allowed_tree_depth)
                die("exceeded maximum allowed tree depth");
 
        FAST_ARRAY_ALLOC(tp, nparent);
index e449a1320e55a6069b253f20e167db8c4922fd89..7e1b956f2781644474c67a083cc22cbebccd3fbe 100644 (file)
@@ -12,6 +12,7 @@
 #include "pathspec.h"
 #include "json-writer.h"
 #include "environment.h"
+#include "read-cache-ll.h"
 
 static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned long size, struct strbuf *err)
 {
@@ -441,8 +442,9 @@ int traverse_trees(struct index_state *istate,
        struct strbuf base = STRBUF_INIT;
        int interesting = 1;
        char *traverse_path;
+       struct repository *r = istate ? istate->repo : the_repository;
 
-       if (traverse_trees_cur_depth > max_allowed_tree_depth)
+       if (traverse_trees_cur_depth > r->settings.max_allowed_tree_depth)
                return error("exceeded maximum allowed tree depth");
 
        traverse_trees_count++;
diff --git a/tree.c b/tree.c
index 1ef743d90f4badf9e62fd6981bb920f35492e71f..2a677234d60aa10e4c993ee43602681d1a7f6b10 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -25,7 +25,7 @@ int read_tree_at(struct repository *r,
        int len, oldlen = base->len;
        enum interesting retval = entry_not_interesting;
 
-       if (depth > max_allowed_tree_depth)
+       if (depth > r->settings.max_allowed_tree_depth)
                return error("exceeded maximum allowed tree depth");
 
        if (parse_tree(tree))