Skip to content

Commit 297fff3

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 53f7115 commit 297fff3

File tree

7 files changed

+37
-30
lines changed

7 files changed

+37
-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"
@@ -48,15 +47,15 @@ static size_t pack_mapped;
4847
#define SZ_FMT PRIuMAX
4948
static inline uintmax_t sz_fmt(size_t s) { return s; }
5049

51-
void pack_report(void)
50+
void pack_report(struct repository *repo)
5251
{
5352
fprintf(stderr,
5453
"pack_report: getpagesize() = %10" SZ_FMT "\n"
5554
"pack_report: core.packedGitWindowSize = %10" SZ_FMT "\n"
5655
"pack_report: core.packedGitLimit = %10" SZ_FMT "\n",
5756
sz_fmt(getpagesize()),
58-
sz_fmt(packed_git_window_size),
59-
sz_fmt(packed_git_limit));
57+
sz_fmt(repo->settings.packed_git_window_size),
58+
sz_fmt(repo->settings.packed_git_limit));
6059
fprintf(stderr,
6160
"pack_report: pack_used_ctr = %10u\n"
6261
"pack_report: pack_mmap_calls = %10u\n"
@@ -652,20 +651,28 @@ unsigned char *use_pack(struct packed_git *p,
652651
break;
653652
}
654653
if (!win) {
655-
size_t window_align = packed_git_window_size / 2;
654+
size_t window_align;
656655
off_t len;
656+
struct repo_settings *settings;
657+
658+
/* lazy load the settings in case it hasn't been setup */
659+
prepare_repo_settings(p->repo);
660+
settings = &p->repo->settings;
661+
662+
window_align = settings->packed_git_window_size / 2;
657663

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

661667
CALLOC_ARRAY(win, 1);
662668
win->offset = (offset / window_align) * window_align;
663669
len = p->pack_size - win->offset;
664-
if (len > packed_git_window_size)
665-
len = packed_git_window_size;
670+
if (len > settings->packed_git_window_size)
671+
len = settings->packed_git_window_size;
666672
win->len = (size_t)len;
667673
pack_mapped += win->len;
668-
while (packed_git_limit < pack_mapped
674+
675+
while (settings->packed_git_limit < pack_mapped
669676
&& unuse_one_window(p))
670677
; /* nothing */
671678
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void prepare_repo_settings(struct repository *r)
2626
const char *strval;
2727
int manyfiles;
2828
int read_changed_paths;
29+
unsigned long longval;
2930

3031
if (!r->gitdir)
3132
BUG("Cannot add settings for uninitialized repository");
@@ -123,6 +124,19 @@ void prepare_repo_settings(struct repository *r)
123124
* removed.
124125
*/
125126
r->settings.command_requires_full_index = 1;
127+
128+
if (!repo_config_get_ulong(r, "core.packedgitwindowsize", &longval)) {
129+
int pgsz_x2 = getpagesize() * 2;
130+
131+
/* This value must be multiple of (pagesize * 2) */
132+
longval /= pgsz_x2;
133+
if (longval < 1)
134+
longval = 1;
135+
r->settings.packed_git_window_size = longval * pgsz_x2;
136+
}
137+
138+
if (!repo_config_get_ulong(r, "core.packedgitlimit", &longval))
139+
r->settings.packed_git_limit = longval;
126140
}
127141

128142
enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo)

repo-settings.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,17 @@ struct repo_settings {
5757

5858
int core_multi_pack_index;
5959
int warn_ambiguous_refs; /* lazily loaded via accessor */
60+
61+
size_t packed_git_window_size;
62+
size_t packed_git_limit;
6063
};
6164
#define REPO_SETTINGS_INIT { \
6265
.index_version = -1, \
6366
.core_untracked_cache = UNTRACKED_CACHE_KEEP, \
6467
.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \
6568
.warn_ambiguous_refs = -1, \
69+
.packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE, \
70+
.packed_git_limit = DEFAULT_PACKED_GIT_LIMIT, \
6671
}
6772

6873
void prepare_repo_settings(struct repository *r);

0 commit comments

Comments
 (0)