config: make `packed_git_(limit|window_size)` non-global variables
The variables `packed_git_window_size` and `packed_git_limit` are global config variables used in the `packfile.c` file. Since it is only used in this file, let's change it from being a global config variable to a local variable for the subsystem. With this, we rid `packfile.c` from all global variable usage and this means we can also remove the `USE_THE_REPOSITORY_VARIABLE` guard from the file. Helped-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karthik Nayak committed
Dec 3, 2024 at 15:44 UTC
d284713bae71877577cf1a07501c8528f8c44bb2
7 files changed
+35
-30
builtin/fast-import.c
+2
-2
@@ -3539,7 +3539,7 @@ static void parse_argv(void)
3539
int cmd_fast_import(int argc,
3540
const char **argv,
3541
const char *prefix,
3542
- struct repository *repo UNUSED)
3542
+ struct repository *repo)
3543
{
3544
unsigned int i;
3545
@@ -3660,7 +3660,7 @@ int cmd_fast_import(int argc,
3660
fprintf(stderr, " pools: %10lu KiB\n", (unsigned long)((tree_entry_allocd + fi_mem_pool.pool_alloc) /1024));
3661
fprintf(stderr, " objects: %10" PRIuMAX " KiB\n", (alloc_count*sizeof(struct object_entry))/1024);
3662
fprintf(stderr, "---------------------------------------------------------------------\n");
3663
- pack_report();
3663
+ pack_report(repo);
3664
fprintf(stderr, "---------------------------------------------------------------------\n");
3665
fprintf(stderr, "\n");
3666
}
config.c
-17
@@ -1493,28 +1493,11 @@ static int git_default_core_config(const char *var, const char *value,
1493
return 0;
1494
}
1495
1496
- if (!strcmp(var, "core.packedgitwindowsize")) {
1497
- int pgsz_x2 = getpagesize() * 2;
1498
- packed_git_window_size = git_config_ulong(var, value, ctx->kvi);
1499
-
1500
- /* This value must be multiple of (pagesize * 2) */
1501
- packed_git_window_size /= pgsz_x2;
1502
- if (packed_git_window_size < 1)
1503
- packed_git_window_size = 1;
1504
- packed_git_window_size *= pgsz_x2;
1505
- return 0;
1506
- }
1507
-
1496
if (!strcmp(var, "core.bigfilethreshold")) {
1497
big_file_threshold = git_config_ulong(var, value, ctx->kvi);
1498
return 0;
1499
}
1500
1513
- if (!strcmp(var, "core.packedgitlimit")) {
1514
- packed_git_limit = git_config_ulong(var, value, ctx->kvi);
1515
- return 0;
1516
- }
1517
-
1501
if (!strcmp(var, "core.autocrlf")) {
1502
if (value && !strcasecmp(value, "input")) {
1503
auto_crlf = AUTO_CRLF_INPUT;
environment.c
-2
@@ -49,8 +49,6 @@ int fsync_object_files = -1;
49
int use_fsync = -1;
50
enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;
51
enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;
52
-size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
53
-size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
52
unsigned long big_file_threshold = 512 * 1024 * 1024;
53
char *editor_program;
54
char *askpass_program;
packfile.c
+15
-8
@@ -1,4 +1,3 @@
1
-#define USE_THE_REPOSITORY_VARIABLE
1
2
#include "git-compat-util.h"
3
#include "environment.h"
@@ -46,15 +45,15 @@ static size_t pack_mapped;
45
#define SZ_FMT PRIuMAX
46
static inline uintmax_t sz_fmt(size_t s) { return s; }
47
49
-void pack_report(void)
48
+void pack_report(struct repository *repo)
49
{
50
fprintf(stderr,
51
"pack_report: getpagesize() = %10" SZ_FMT "\n"
52
"pack_report: core.packedGitWindowSize = %10" SZ_FMT "\n"
53
"pack_report: core.packedGitLimit = %10" SZ_FMT "\n",
54
sz_fmt(getpagesize()),
56
- sz_fmt(packed_git_window_size),
57
- sz_fmt(packed_git_limit));
55
+ sz_fmt(repo->settings.packed_git_window_size),
56
+ sz_fmt(repo->settings.packed_git_limit));
57
fprintf(stderr,
58
"pack_report: pack_used_ctr = %10u\n"
59
"pack_report: pack_mmap_calls = %10u\n"
@@ -650,8 +649,15 @@ unsigned char *use_pack(struct packed_git *p,
649
break;
650
}
651
if (!win) {
653
- size_t window_align = packed_git_window_size / 2;
652
+ size_t window_align;
653
off_t len;
654
+ struct repo_settings *settings;
655
+
656
+ /* lazy load the settings in case it hasn't been setup */
657
+ prepare_repo_settings(p->repo);
658
+ settings = &p->repo->settings;
659
+
660
+ window_align = settings->packed_git_window_size / 2;
661
662
if (p->pack_fd == -1 && open_packed_git(p))
663
die("packfile %s cannot be accessed", p->pack_name);
@@ -659,11 +665,12 @@ unsigned char *use_pack(struct packed_git *p,
665
CALLOC_ARRAY(win, 1);
666
win->offset = (offset / window_align) * window_align;
667
len = p->pack_size - win->offset;
662
- if (len > packed_git_window_size)
663
- len = packed_git_window_size;
668
+ if (len > settings->packed_git_window_size)
669
+ len = settings->packed_git_window_size;
670
win->len = (size_t)len;
671
pack_mapped += win->len;
666
- while (packed_git_limit < pack_mapped
672
+
673
+ while (settings->packed_git_limit < pack_mapped
674
&& unuse_one_window(p))
675
; /* nothing */
676
win->base = xmmap_gently(NULL, win->len,
packfile.h
+1
-1
@@ -89,7 +89,7 @@ unsigned long repo_approximate_object_count(struct repository *r);
89
struct packed_git *find_oid_pack(const struct object_id *oid,
90
struct packed_git *packs);
91
92
-void pack_report(void);
92
+void pack_report(struct repository *repo);
93
94
/*
95
* mmap the index file for the specified packfile (if it is not
repo-settings.c
+13
@@ -128,6 +128,19 @@ void prepare_repo_settings(struct repository *r)
128
129
if (!repo_config_get_ulong(r, "core.deltabasecachelimit", &ulongval))
130
r->settings.delta_base_cache_limit = ulongval;
131
+
132
+ if (!repo_config_get_ulong(r, "core.packedgitwindowsize", &ulongval)) {
133
+ int pgsz_x2 = getpagesize() * 2;
134
+
135
+ /* This value must be multiple of (pagesize * 2) */
136
+ ulongval /= pgsz_x2;
137
+ if (ulongval < 1)
138
+ ulongval = 1;
139
+ r->settings.packed_git_window_size = ulongval * pgsz_x2;
140
+ }
141
+
142
+ if (!repo_config_get_ulong(r, "core.packedgitlimit", &ulongval))
143
+ r->settings.packed_git_limit = ulongval;
144
}
145
146
enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo)
repo-settings.h
+4
@@ -59,6 +59,8 @@ struct repo_settings {
59
int warn_ambiguous_refs; /* lazily loaded via accessor */
60
61
size_t delta_base_cache_limit;
62
+ size_t packed_git_window_size;
63
+ size_t packed_git_limit;
64
};
65
#define REPO_SETTINGS_INIT { \
66
.index_version = -1, \
@@ -66,6 +68,8 @@ struct repo_settings {
68
.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \
69
.warn_ambiguous_refs = -1, \
70
.delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT, \
71
+ .packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE, \
72
+ .packed_git_limit = DEFAULT_PACKED_GIT_LIMIT, \
73
}
74
75
void prepare_repo_settings(struct repository *r);