Skip to content

Commit 7835ee7

Browse files
pks-tgitster
authored andcommitted
environment: move access to "core.bigFileThreshold" into repo settings
The "core.bigFileThreshold" setting is stored in a global variable and populated via `git_default_core_config()`. This may cause issues in the case where one is handling multiple different repositories in a single process with different values for that config key, as we may or may not see the correct value in that case. Furthermore, global state blocks our path towards libification. Refactor the code so that we instead store the value in `struct repo_settings`, where the value is computed as-needed and cached. Note that this change requires us to adapt one test in t1050 that verifies that we die when parsing an invalid "core.bigFileThreshold" value. The exercised Git command doesn't use the value at all, and thus it won't hit the new code path that parses the value. This is addressed by using git-hash-object(1) instead, which does read the value. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2582846 commit 7835ee7

15 files changed

+52
-22
lines changed

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
216216
/* Stream it? */
217217
if (S_ISREG(mode) && !args->convert &&
218218
oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
219-
size > big_file_threshold)
219+
size > repo_settings_get_big_file_threshold(the_repository))
220220
return write_entry(args, oid, path.buf, path.len, mode, NULL, size);
221221

222222
buffer = object_file_to_archive(args, path.buf, oid, mode, &type, &size);

builtin/fast-import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,7 @@ static void parse_and_store_blob(
20212021
static struct strbuf buf = STRBUF_INIT;
20222022
uintmax_t len;
20232023

2024-
if (parse_data(&buf, big_file_threshold, &len))
2024+
if (parse_data(&buf, repo_settings_get_big_file_threshold(the_repository), &len))
20252025
store_object(OBJ_BLOB, &buf, last, oidout, mark);
20262026
else {
20272027
if (last) {
@@ -3402,7 +3402,7 @@ static int parse_one_option(const char *option)
34023402
unsigned long v;
34033403
if (!git_parse_ulong(option, &v))
34043404
return 0;
3405-
big_file_threshold = v;
3405+
repo_settings_set_big_file_threshold(the_repository, v);
34063406
} else if (skip_prefix(option, "depth=", &option)) {
34073407
option_depth(option);
34083408
} else if (skip_prefix(option, "active-branches=", &option)) {

builtin/index-pack.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
485485
git_hash_update(&c, hdr, hdrlen);
486486
} else
487487
oid = NULL;
488-
if (type == OBJ_BLOB && size > big_file_threshold)
488+
if (type == OBJ_BLOB &&
489+
size > repo_settings_get_big_file_threshold(the_repository))
489490
buf = fixed_buf;
490491
else
491492
buf = xmallocz(size);
@@ -799,7 +800,8 @@ static int check_collison(struct object_entry *entry)
799800
enum object_type type;
800801
unsigned long size;
801802

802-
if (entry->size <= big_file_threshold || entry->type != OBJ_BLOB)
803+
if (entry->size <= repo_settings_get_big_file_threshold(the_repository) ||
804+
entry->type != OBJ_BLOB)
803805
return -1;
804806

805807
memset(&data, 0, sizeof(data));

builtin/pack-objects.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
499499

500500
if (!usable_delta) {
501501
if (oe_type(entry) == OBJ_BLOB &&
502-
oe_size_greater_than(&to_pack, entry, big_file_threshold) &&
502+
oe_size_greater_than(&to_pack, entry,
503+
repo_settings_get_big_file_threshold(the_repository)) &&
503504
(st = open_istream(the_repository, &entry->idx.oid, &type,
504505
&size, NULL)) != NULL)
505506
buf = NULL;
@@ -2454,7 +2455,8 @@ static void get_object_details(void)
24542455
struct object_entry *entry = sorted_by_offset[i];
24552456
check_object(entry, i);
24562457
if (entry->type_valid &&
2457-
oe_size_greater_than(&to_pack, entry, big_file_threshold))
2458+
oe_size_greater_than(&to_pack, entry,
2459+
repo_settings_get_big_file_threshold(the_repository)))
24582460
entry->no_try_delta = 1;
24592461
display_progress(progress_state, i + 1);
24602462
}

builtin/unpack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,8 @@ static void unpack_one(unsigned nr)
553553

554554
switch (type) {
555555
case OBJ_BLOB:
556-
if (!dry_run && size > big_file_threshold) {
556+
if (!dry_run &&
557+
size > repo_settings_get_big_file_threshold(the_repository)) {
557558
stream_blob(size, nr);
558559
return;
559560
}

config.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,11 +1490,6 @@ static int git_default_core_config(const char *var, const char *value,
14901490
return 0;
14911491
}
14921492

1493-
if (!strcmp(var, "core.bigfilethreshold")) {
1494-
big_file_threshold = git_config_ulong(var, value, ctx->kvi);
1495-
return 0;
1496-
}
1497-
14981493
if (!strcmp(var, "core.autocrlf")) {
14991494
if (value && !strcasecmp(value, "input")) {
15001495
auto_crlf = AUTO_CRLF_INPUT;

diff.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4193,7 +4193,8 @@ int diff_populate_filespec(struct repository *r,
41934193
* is probably fine.
41944194
*/
41954195
if (check_binary &&
4196-
s->size > big_file_threshold && s->is_binary == -1) {
4196+
s->size > repo_settings_get_big_file_threshold(the_repository) &&
4197+
s->is_binary == -1) {
41974198
s->is_binary = 1;
41984199
return 0;
41994200
}
@@ -4243,7 +4244,8 @@ int diff_populate_filespec(struct repository *r,
42434244
if (size_only || check_binary) {
42444245
if (size_only)
42454246
return 0;
4246-
if (s->size > big_file_threshold && s->is_binary == -1) {
4247+
if (s->size > repo_settings_get_big_file_threshold(the_repository) &&
4248+
s->is_binary == -1) {
42474249
s->is_binary = 1;
42484250
return 0;
42494251
}

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ int fsync_object_files = -1;
4949
int use_fsync = -1;
5050
enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;
5151
enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;
52-
unsigned long big_file_threshold = 512 * 1024 * 1024;
5352
char *editor_program;
5453
char *askpass_program;
5554
char *excludes_file;

environment.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ extern int zlib_compression_level;
154154
extern int pack_compression_level;
155155
extern size_t packed_git_window_size;
156156
extern size_t packed_git_limit;
157-
extern unsigned long big_file_threshold;
158157
extern unsigned long pack_size_limit_cfg;
159158
extern int max_allowed_tree_depth;
160159

object-file.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,7 +2803,8 @@ int index_fd(struct index_state *istate, struct object_id *oid,
28032803
ret = index_stream_convert_blob(istate, oid, fd, path, flags);
28042804
else if (!S_ISREG(st->st_mode))
28052805
ret = index_pipe(istate, oid, fd, type, path, flags);
2806-
else if (st->st_size <= big_file_threshold || type != OBJ_BLOB ||
2806+
else if (st->st_size <= repo_settings_get_big_file_threshold(the_repository) ||
2807+
type != OBJ_BLOB ||
28072808
(path && would_convert_to_git(istate, path)))
28082809
ret = index_core(istate, oid, fd, xsize_t(st->st_size),
28092810
type, path, flags);
@@ -3137,7 +3138,8 @@ int read_loose_object(const char *path,
31373138
goto out;
31383139
}
31393140

3140-
if (*oi->typep == OBJ_BLOB && *size > big_file_threshold) {
3141+
if (*oi->typep == OBJ_BLOB &&
3142+
*size > repo_settings_get_big_file_threshold(the_repository)) {
31413143
if (check_stream_oid(&stream, hdr, *size, path, expected_oid) < 0)
31423144
goto out;
31433145
} else {

0 commit comments

Comments
 (0)