environment: move access to core.maxTreeDepth into repo settings

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>
This commit is contained in:
René Scharfe 2026-01-09 22:30:12 +01:00 committed by Junio C Hamano
parent d529f3a197
commit e691395365
9 changed files with 36 additions and 34 deletions

View 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);
}

View 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;

View 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)

View 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);

View 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);

View 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);

View 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);

View 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++;

2
tree.c
View File

@ -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))