Skip to content

Commit d284713

Browse files
KarthikNayakgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6b2d21 commit d284713

File tree

7 files changed

+35
-30
lines changed

7 files changed

+35
-30
lines changed

builtin/fast-import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,7 +3539,7 @@ static void parse_argv(void)
35393539
int cmd_fast_import(int argc,
35403540
const char **argv,
35413541
const char *prefix,
3542-
struct repository *repo UNUSED)
3542+
struct repository *repo)
35433543
{
35443544
unsigned int i;
35453545

@@ -3660,7 +3660,7 @@ int cmd_fast_import(int argc,
36603660
fprintf(stderr, " pools: %10lu KiB\n", (unsigned long)((tree_entry_allocd + fi_mem_pool.pool_alloc) /1024));
36613661
fprintf(stderr, " objects: %10" PRIuMAX " KiB\n", (alloc_count*sizeof(struct object_entry))/1024);
36623662
fprintf(stderr, "---------------------------------------------------------------------\n");
3663-
pack_report();
3663+
pack_report(repo);
36643664
fprintf(stderr, "---------------------------------------------------------------------\n");
36653665
fprintf(stderr, "\n");
36663666
}

config.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,28 +1493,11 @@ static int git_default_core_config(const char *var, const char *value,
14931493
return 0;
14941494
}
14951495

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-
15081496
if (!strcmp(var, "core.bigfilethreshold")) {
15091497
big_file_threshold = git_config_ulong(var, value, ctx->kvi);
15101498
return 0;
15111499
}
15121500

1513-
if (!strcmp(var, "core.packedgitlimit")) {
1514-
packed_git_limit = git_config_ulong(var, value, ctx->kvi);
1515-
return 0;
1516-
}
1517-
15181501
if (!strcmp(var, "core.autocrlf")) {
15191502
if (value && !strcasecmp(value, "input")) {
15201503
auto_crlf = AUTO_CRLF_INPUT;

environment.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +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-
size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
53-
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
5452
unsigned long big_file_threshold = 512 * 1024 * 1024;
5553
char *editor_program;
5654
char *askpass_program;

packfile.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21

32
#include "git-compat-util.h"
43
#include "environment.h"
@@ -46,15 +45,15 @@ static size_t pack_mapped;
4645
#define SZ_FMT PRIuMAX
4746
static inline uintmax_t sz_fmt(size_t s) { return s; }
4847

49-
void pack_report(void)
48+
void pack_report(struct repository *repo)
5049
{
5150
fprintf(stderr,
5251
"pack_report: getpagesize() = %10" SZ_FMT "\n"
5352
"pack_report: core.packedGitWindowSize = %10" SZ_FMT "\n"
5453
"pack_report: core.packedGitLimit = %10" SZ_FMT "\n",
5554
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));
5857
fprintf(stderr,
5958
"pack_report: pack_used_ctr = %10u\n"
6059
"pack_report: pack_mmap_calls = %10u\n"
@@ -650,20 +649,28 @@ unsigned char *use_pack(struct packed_git *p,
650649
break;
651650
}
652651
if (!win) {
653-
size_t window_align = packed_git_window_size / 2;
652+
size_t window_align;
654653
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;
655661

656662
if (p->pack_fd == -1 && open_packed_git(p))
657663
die("packfile %s cannot be accessed", p->pack_name);
658664

659665
CALLOC_ARRAY(win, 1);
660666
win->offset = (offset / window_align) * window_align;
661667
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;
664670
win->len = (size_t)len;
665671
pack_mapped += win->len;
666-
while (packed_git_limit < pack_mapped
672+
673+
while (settings->packed_git_limit < pack_mapped
667674
&& unuse_one_window(p))
668675
; /* nothing */
669676
win->base = xmmap_gently(NULL, win->len,

packfile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ unsigned long repo_approximate_object_count(struct repository *r);
8989
struct packed_git *find_oid_pack(const struct object_id *oid,
9090
struct packed_git *packs);
9191

92-
void pack_report(void);
92+
void pack_report(struct repository *repo);
9393

9494
/*
9595
* mmap the index file for the specified packfile (if it is not

repo-settings.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ void prepare_repo_settings(struct repository *r)
128128

129129
if (!repo_config_get_ulong(r, "core.deltabasecachelimit", &ulongval))
130130
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;
131144
}
132145

133146
enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo)

repo-settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,17 @@ struct repo_settings {
5959
int warn_ambiguous_refs; /* lazily loaded via accessor */
6060

6161
size_t delta_base_cache_limit;
62+
size_t packed_git_window_size;
63+
size_t packed_git_limit;
6264
};
6365
#define REPO_SETTINGS_INIT { \
6466
.index_version = -1, \
6567
.core_untracked_cache = UNTRACKED_CACHE_KEEP, \
6668
.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \
6769
.warn_ambiguous_refs = -1, \
6870
.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, \
6973
}
7074

7175
void prepare_repo_settings(struct repository *r);

0 commit comments

Comments
 (0)