Skip to content

Commit d6b2d21

Browse files
KarthikNayakgitster
authored andcommitted
config: make delta_base_cache_limit a non-global variable
The `delta_base_cache_limit` variable is a global config variable used by multiple subsystems. Let's make this non-global, by adding this variable independently to the subsystems where it is used. First, add the setting to the `repo_settings` struct, this provides access to the config in places where the repository is available. Use this in `packfile.c`. In `index-pack.c` we add it to the `pack_idx_option` struct and its constructor. While the repository struct is available here, it may not be set because `git index-pack` can be used without a repository. In `gc.c` add it to the `gc_config` struct and also the constructor function. The gc functions currently do not have direct access to a repository struct. These changes are made to remove the usage of `delta_base_cache_limit` as a global variable in `packfile.c`. This brings us one step closer to removing the `USE_THE_REPOSITORY_VARIABLE` definition in `packfile.c` which we complete in the next patch. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c87910b commit d6b2d21

File tree

11 files changed

+39
-14
lines changed

11 files changed

+39
-14
lines changed

builtin/gc.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ struct gc_config {
138138
char *repack_filter_to;
139139
unsigned long big_pack_threshold;
140140
unsigned long max_delta_cache_size;
141+
/*
142+
* Remove this member from gc_config once repo_settings is passed
143+
* through the callchain.
144+
*/
145+
size_t delta_base_cache_limit;
141146
};
142147

143148
#define GC_CONFIG_INIT { \
@@ -153,6 +158,7 @@ struct gc_config {
153158
.prune_expire = xstrdup("2.weeks.ago"), \
154159
.prune_worktrees_expire = xstrdup("3.months.ago"), \
155160
.max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE, \
161+
.delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT, \
156162
}
157163

158164
static void gc_config_release(struct gc_config *cfg)
@@ -168,6 +174,7 @@ static void gc_config(struct gc_config *cfg)
168174
{
169175
const char *value;
170176
char *owned = NULL;
177+
unsigned long ulongval;
171178

172179
if (!git_config_get_value("gc.packrefs", &value)) {
173180
if (value && !strcmp(value, "notbare"))
@@ -206,6 +213,9 @@ static void gc_config(struct gc_config *cfg)
206213
git_config_get_ulong("gc.bigpackthreshold", &cfg->big_pack_threshold);
207214
git_config_get_ulong("pack.deltacachesize", &cfg->max_delta_cache_size);
208215

216+
if (!git_config_get_ulong("core.deltabasecachelimit", &ulongval))
217+
cfg->delta_base_cache_limit = ulongval;
218+
209219
if (!git_config_get_string("gc.repackfilter", &owned)) {
210220
free(cfg->repack_filter);
211221
cfg->repack_filter = owned;
@@ -416,7 +426,7 @@ static uint64_t estimate_repack_memory(struct gc_config *cfg,
416426
* read_sha1_file() (either at delta calculation phase, or
417427
* writing phase) also fills up the delta base cache
418428
*/
419-
heap += delta_base_cache_limit;
429+
heap += cfg->delta_base_cache_limit;
420430
/* and of course pack-objects has its own delta cache */
421431
heap += cfg->max_delta_cache_size;
422432

builtin/index-pack.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ static void parse_pack_objects(unsigned char *hash)
12381238
* recursively checking if the resulting object is used as a base
12391239
* for some more deltas.
12401240
*/
1241-
static void resolve_deltas(void)
1241+
static void resolve_deltas(struct pack_idx_option *opts)
12421242
{
12431243
int i;
12441244

@@ -1254,7 +1254,7 @@ static void resolve_deltas(void)
12541254
nr_ref_deltas + nr_ofs_deltas);
12551255

12561256
nr_dispatched = 0;
1257-
base_cache_limit = delta_base_cache_limit * nr_threads;
1257+
base_cache_limit = opts->delta_base_cache_limit * nr_threads;
12581258
if (nr_threads > 1 || getenv("GIT_FORCE_THREADS")) {
12591259
init_thread();
12601260
work_lock();
@@ -1604,6 +1604,10 @@ static int git_index_pack_config(const char *k, const char *v,
16041604
else
16051605
opts->flags &= ~WRITE_REV;
16061606
}
1607+
if (!strcmp(k, "core.deltabasecachelimit")) {
1608+
opts->delta_base_cache_limit = git_config_ulong(k, v, ctx->kvi);
1609+
return 0;
1610+
}
16071611
return git_default_config(k, v, ctx, cb);
16081612
}
16091613

@@ -1930,7 +1934,7 @@ int cmd_index_pack(int argc,
19301934
parse_pack_objects(pack_hash);
19311935
if (report_end_of_input)
19321936
write_in_full(2, "\0", 1);
1933-
resolve_deltas();
1937+
resolve_deltas(&opts);
19341938
conclude_pack(fix_thin_pack, curr_pack, pack_hash);
19351939
free(ofs_deltas);
19361940
free(ref_deltas);

config.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,11 +1515,6 @@ static int git_default_core_config(const char *var, const char *value,
15151515
return 0;
15161516
}
15171517

1518-
if (!strcmp(var, "core.deltabasecachelimit")) {
1519-
delta_base_cache_limit = git_config_ulong(var, value, ctx->kvi);
1520-
return 0;
1521-
}
1522-
15231518
if (!strcmp(var, "core.autocrlf")) {
15241519
if (value && !strcasecmp(value, "input")) {
15251520
auto_crlf = AUTO_CRLF_INPUT;

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;
5151
enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;
5252
size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
5353
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
54-
size_t delta_base_cache_limit = 96 * 1024 * 1024;
5554
unsigned long big_file_threshold = 512 * 1024 * 1024;
5655
char *editor_program;
5756
char *askpass_program;

environment.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ extern int zlib_compression_level;
165165
extern int pack_compression_level;
166166
extern size_t packed_git_window_size;
167167
extern size_t packed_git_limit;
168-
extern size_t delta_base_cache_limit;
169168
extern unsigned long big_file_threshold;
170169
extern unsigned long pack_size_limit_cfg;
171170
extern int max_allowed_tree_depth;

pack-objects.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
struct repository;
99

10-
#define DEFAULT_DELTA_CACHE_SIZE (256 * 1024 * 1024)
10+
#define DEFAULT_DELTA_CACHE_SIZE (256 * 1024 * 1024)
11+
#define DEFAULT_DELTA_BASE_CACHE_LIMIT (96 * 1024 * 1024)
1112

1213
#define OE_DFS_STATE_BITS 2
1314
#define OE_DEPTH_BITS 12

pack-write.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void reset_pack_idx_option(struct pack_idx_option *opts)
2121
memset(opts, 0, sizeof(*opts));
2222
opts->version = 2;
2323
opts->off32_limit = 0x7fffffff;
24+
opts->delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT;
2425
}
2526

2627
static int sha1_compare(const void *_a, const void *_b)

pack.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ struct pack_idx_option {
5858
*/
5959
int anomaly_alloc, anomaly_nr;
6060
uint32_t *anomaly;
61+
62+
size_t delta_base_cache_limit;
6163
};
6264

6365
void reset_pack_idx_option(struct pack_idx_option *);

packfile.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,9 @@ void clear_delta_base_cache(void)
14961496
}
14971497

14981498
static void add_delta_base_cache(struct packed_git *p, off_t base_offset,
1499-
void *base, unsigned long base_size, enum object_type type)
1499+
void *base, unsigned long base_size,
1500+
unsigned long delta_base_cache_limit,
1501+
enum object_type type)
15001502
{
15011503
struct delta_base_cache_entry *ent;
15021504
struct list_head *lru, *tmp;
@@ -1698,6 +1700,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
16981700
int delta_stack_nr = 0, delta_stack_alloc = UNPACK_ENTRY_STACK_PREALLOC;
16991701
int base_from_cache = 0;
17001702

1703+
prepare_repo_settings(p->repo);
1704+
17011705
write_pack_access_log(p, obj_offset);
17021706

17031707
/* PHASE 1: drill down to the innermost base object */
@@ -1878,7 +1882,9 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
18781882
* before we are done using it.
18791883
*/
18801884
if (!external_base)
1881-
add_delta_base_cache(p, base_obj_offset, base, base_size, type);
1885+
add_delta_base_cache(p, base_obj_offset, base, base_size,
1886+
p->repo->settings.delta_base_cache_limit,
1887+
type);
18821888

18831889
free(delta_data);
18841890
free(external_base);

repo-settings.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "repo-settings.h"
44
#include "repository.h"
55
#include "midx.h"
6+
#include "pack-objects.h"
67

78
static void repo_cfg_bool(struct repository *r, const char *key, int *dest,
89
int def)
@@ -26,6 +27,7 @@ void prepare_repo_settings(struct repository *r)
2627
const char *strval;
2728
int manyfiles;
2829
int read_changed_paths;
30+
unsigned long ulongval;
2931

3032
if (!r->gitdir)
3133
BUG("Cannot add settings for uninitialized repository");
@@ -123,6 +125,9 @@ void prepare_repo_settings(struct repository *r)
123125
* removed.
124126
*/
125127
r->settings.command_requires_full_index = 1;
128+
129+
if (!repo_config_get_ulong(r, "core.deltabasecachelimit", &ulongval))
130+
r->settings.delta_base_cache_limit = ulongval;
126131
}
127132

128133
enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo)

0 commit comments

Comments
 (0)