Skip to content

Commit ca2fdbc

Browse files
KarthikNayakttaylorr
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. We do this by introducing a new local `packfile_config` struct in `packfile.c` and also adding the required function to parse the said config. We then use this within `packfile.c` to obtain the variables. 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. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent fc3e177 commit ca2fdbc

File tree

5 files changed

+55
-30
lines changed

5 files changed

+55
-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: 52 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"
@@ -27,6 +26,17 @@
2726
#include "config.h"
2827
#include "pack-objects.h"
2928

29+
struct packfile_config {
30+
unsigned long packed_git_window_size;
31+
unsigned long packed_git_limit;
32+
};
33+
34+
#define PACKFILE_CONFIG_INIT \
35+
{ \
36+
.packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE, \
37+
.packed_git_limit = DEFAULT_PACKED_GIT_LIMIT, \
38+
}
39+
3040
char *odb_pack_name(struct repository *repo, struct strbuf *buf,
3141
const unsigned char *hash, const char *ext)
3242
{
@@ -48,15 +58,44 @@ static size_t pack_mapped;
4858
#define SZ_FMT PRIuMAX
4959
static inline uintmax_t sz_fmt(size_t s) { return s; }
5060

51-
void pack_report(void)
61+
static int packfile_config(const char *var, const char *value,
62+
const struct config_context *ctx, void *cb)
5263
{
64+
struct packfile_config *config = cb;
65+
66+
if (!strcmp(var, "core.packedgitwindowsize")) {
67+
int pgsz_x2 = getpagesize() * 2;
68+
config->packed_git_window_size = git_config_ulong(var, value, ctx->kvi);
69+
70+
/* This value must be multiple of (pagesize * 2) */
71+
config->packed_git_window_size /= pgsz_x2;
72+
if (config->packed_git_window_size < 1)
73+
config->packed_git_window_size = 1;
74+
config->packed_git_window_size *= pgsz_x2;
75+
return 0;
76+
}
77+
78+
if (!strcmp(var, "core.packedgitlimit")) {
79+
config->packed_git_limit = git_config_ulong(var, value, ctx->kvi);
80+
return 0;
81+
}
82+
83+
return git_default_config(var, value, ctx, cb);
84+
}
85+
86+
87+
void pack_report(struct repository *repo)
88+
{
89+
struct packfile_config config = PACKFILE_CONFIG_INIT;
90+
repo_config(repo, packfile_config, &config);
91+
5392
fprintf(stderr,
5493
"pack_report: getpagesize() = %10" SZ_FMT "\n"
5594
"pack_report: core.packedGitWindowSize = %10" SZ_FMT "\n"
5695
"pack_report: core.packedGitLimit = %10" SZ_FMT "\n",
5796
sz_fmt(getpagesize()),
58-
sz_fmt(packed_git_window_size),
59-
sz_fmt(packed_git_limit));
97+
sz_fmt(config.packed_git_window_size),
98+
sz_fmt(config.packed_git_limit));
6099
fprintf(stderr,
61100
"pack_report: pack_used_ctr = %10u\n"
62101
"pack_report: pack_mmap_calls = %10u\n"
@@ -652,20 +691,25 @@ unsigned char *use_pack(struct packed_git *p,
652691
break;
653692
}
654693
if (!win) {
655-
size_t window_align = packed_git_window_size / 2;
694+
struct packfile_config config = PACKFILE_CONFIG_INIT;
695+
size_t window_align;
656696
off_t len;
657697

698+
repo_config(p->repo, packfile_config, &config);
699+
window_align = config.packed_git_window_size / 2;
700+
658701
if (p->pack_fd == -1 && open_packed_git(p))
659702
die("packfile %s cannot be accessed", p->pack_name);
660703

661704
CALLOC_ARRAY(win, 1);
662705
win->offset = (offset / window_align) * window_align;
663706
len = p->pack_size - win->offset;
664-
if (len > packed_git_window_size)
665-
len = packed_git_window_size;
707+
if (len > config.packed_git_window_size)
708+
len = config.packed_git_window_size;
666709
win->len = (size_t)len;
667710
pack_mapped += win->len;
668-
while (packed_git_limit < pack_mapped
711+
712+
while (config.packed_git_limit < pack_mapped
669713
&& unuse_one_window(p))
670714
; /* nothing */
671715
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

0 commit comments

Comments
 (0)