Skip to content

Commit e691395

Browse files
rscharfegitster
authored andcommitted
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>
1 parent d529f3a commit e691395

9 files changed

Lines changed: 36 additions & 34 deletions

File tree

environment.c

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,30 +80,6 @@ int core_sparse_checkout_cone;
8080
int sparse_expect_files_outside_of_patterns;
8181
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
8282
unsigned long pack_size_limit_cfg;
83-
int max_allowed_tree_depth =
84-
#ifdef _MSC_VER
85-
/*
86-
* When traversing into too-deep trees, Visual C-compiled Git seems to
87-
* run into some internal stack overflow detection in the
88-
* `RtlpAllocateHeap()` function that is called from within
89-
* `git_inflate_init()`'s call tree. The following value seems to be
90-
* low enough to avoid that by letting Git exit with an error before
91-
* the stack overflow can occur.
92-
*/
93-
512;
94-
#elif defined(GIT_WINDOWS_NATIVE) && defined(__clang__) && defined(__aarch64__)
95-
/*
96-
* Similar to Visual C, it seems that on Windows/ARM64 the clang-based
97-
* builds have a smaller stack space available. When running out of
98-
* that stack space, a `STATUS_STACK_OVERFLOW` is produced. When the
99-
* Git command was run from an MSYS2 Bash, this unfortunately results
100-
* in an exit code 127. Let's prevent that by lowering the maximal
101-
* tree depth; This value seems to be low enough.
102-
*/
103-
1280;
104-
#else
105-
2048;
106-
#endif
10783

10884
#ifndef PROTECT_HFS_DEFAULT
10985
#define PROTECT_HFS_DEFAULT 0
@@ -569,11 +545,6 @@ static int git_default_core_config(const char *var, const char *value,
569545
return 0;
570546
}
571547

572-
if (!strcmp(var, "core.maxtreedepth")) {
573-
max_allowed_tree_depth = git_config_int(var, value, ctx->kvi);
574-
return 0;
575-
}
576-
577548
/* Add other config variables here and to Documentation/config.adoc. */
578549
return platform_core_config(var, value, ctx, cb);
579550
}

environment.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ extern char *git_attributes_file;
156156
extern int zlib_compression_level;
157157
extern int pack_compression_level;
158158
extern unsigned long pack_size_limit_cfg;
159-
extern int max_allowed_tree_depth;
160159

161160
extern int precomposed_unicode;
162161
extern int protect_hfs;

git-compat-util.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,30 @@ static inline bool strip_suffix(const char *str, const char *suffix,
578578
#define DEFAULT_PACKED_GIT_LIMIT \
579579
((1024L * 1024L) * (size_t)(sizeof(void*) >= 8 ? (32 * 1024L * 1024L) : 256))
580580

581+
#ifdef _MSC_VER
582+
/*
583+
* When traversing into too-deep trees, Visual C-compiled Git seems to
584+
* run into some internal stack overflow detection in the
585+
* `RtlpAllocateHeap()` function that is called from within
586+
* `git_inflate_init()`'s call tree. The following value seems to be
587+
* low enough to avoid that by letting Git exit with an error before
588+
* the stack overflow can occur.
589+
*/
590+
#define DEFAULT_MAX_ALLOWED_TREE_DEPTH 512
591+
#elif defined(GIT_WINDOWS_NATIVE) && defined(__clang__) && defined(__aarch64__)
592+
/*
593+
* Similar to Visual C, it seems that on Windows/ARM64 the clang-based
594+
* builds have a smaller stack space available. When running out of
595+
* that stack space, a `STATUS_STACK_OVERFLOW` is produced. When the
596+
* Git command was run from an MSYS2 Bash, this unfortunately results
597+
* in an exit code 127. Let's prevent that by lowering the maximal
598+
* tree depth; This value seems to be low enough.
599+
*/
600+
#define DEFAULT_MAX_ALLOWED_TREE_DEPTH 1280
601+
#else
602+
#define DEFAULT_MAX_ALLOWED_TREE_DEPTH 2048
603+
#endif
604+
581605
int git_open_cloexec(const char *name, int flags);
582606
#define git_open(name) git_open_cloexec(name, O_RDONLY)
583607

list-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static void process_tree(struct traversal_context *ctx,
167167
!revs->include_check_obj(&tree->object, revs->include_check_data))
168168
return;
169169

170-
if (ctx->depth > max_allowed_tree_depth)
170+
if (ctx->depth > revs->repo->settings.max_allowed_tree_depth)
171171
die("exceeded maximum allowed tree depth");
172172

173173
failed_parse = parse_tree_gently(tree, 1);

repo-settings.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ void prepare_repo_settings(struct repository *r)
100100
*/
101101
if (!repo_config_get_int(r, "index.version", &value))
102102
r->settings.index_version = value;
103+
repo_cfg_int(r, "core.maxtreedepth",
104+
&r->settings.max_allowed_tree_depth,
105+
DEFAULT_MAX_ALLOWED_TREE_DEPTH);
103106

104107
if (!repo_config_get_string_tmp(r, "core.untrackedcache", &strval)) {
105108
int v = git_parse_maybe_bool(strval);

repo-settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ struct repo_settings {
6767
size_t packed_git_limit;
6868
unsigned long big_file_threshold;
6969

70+
int max_allowed_tree_depth;
71+
7072
char *hooks_path;
7173
};
7274
#define REPO_SETTINGS_INIT { \
@@ -78,6 +80,7 @@ struct repo_settings {
7880
.delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT, \
7981
.packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE, \
8082
.packed_git_limit = DEFAULT_PACKED_GIT_LIMIT, \
83+
.max_allowed_tree_depth = DEFAULT_MAX_ALLOWED_TREE_DEPTH, \
8184
}
8285

8386
void prepare_repo_settings(struct repository *r);

tree-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ static void ll_diff_tree_paths(
439439
void *ttree, **tptree;
440440
int i;
441441

442-
if (depth > max_allowed_tree_depth)
442+
if (depth > opt->repo->settings.max_allowed_tree_depth)
443443
die("exceeded maximum allowed tree depth");
444444

445445
FAST_ARRAY_ALLOC(tp, nparent);

tree-walk.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "pathspec.h"
1313
#include "json-writer.h"
1414
#include "environment.h"
15+
#include "read-cache-ll.h"
1516

1617
static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned long size, struct strbuf *err)
1718
{
@@ -441,8 +442,9 @@ int traverse_trees(struct index_state *istate,
441442
struct strbuf base = STRBUF_INIT;
442443
int interesting = 1;
443444
char *traverse_path;
445+
struct repository *r = istate ? istate->repo : the_repository;
444446

445-
if (traverse_trees_cur_depth > max_allowed_tree_depth)
447+
if (traverse_trees_cur_depth > r->settings.max_allowed_tree_depth)
446448
return error("exceeded maximum allowed tree depth");
447449

448450
traverse_trees_count++;

tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int read_tree_at(struct repository *r,
2525
int len, oldlen = base->len;
2626
enum interesting retval = entry_not_interesting;
2727

28-
if (depth > max_allowed_tree_depth)
28+
if (depth > r->settings.max_allowed_tree_depth)
2929
return error("exceeded maximum allowed tree depth");
3030

3131
if (parse_tree(tree))

0 commit comments

Comments
 (0)