Skip to content

Commit 7211b9e

Browse files
derrickstoleegitster
authored andcommitted
repo-settings: consolidate some config settings
There are a few important config settings that are not loaded during git_default_config. These are instead loaded on-demand. Centralize these config options to a single scan, and store all of the values in a repo_settings struct. The values for each setting are initialized as negative to indicate "unset". This centralization will be particularly important in a later change to introduce "meta" config settings that change the defaults for these config settings. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9c9b961 commit 7211b9e

File tree

7 files changed

+58
-19
lines changed

7 files changed

+58
-19
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ LIB_OBJS += refspec.o
964964
LIB_OBJS += ref-filter.o
965965
LIB_OBJS += remote.o
966966
LIB_OBJS += replace-object.o
967+
LIB_OBJS += repo-settings.o
967968
LIB_OBJS += repository.o
968969
LIB_OBJS += rerere.o
969970
LIB_OBJS += resolve-undo.o

builtin/gc.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ static int aggressive_depth = 50;
4141
static int aggressive_window = 250;
4242
static int gc_auto_threshold = 6700;
4343
static int gc_auto_pack_limit = 50;
44-
static int gc_write_commit_graph;
4544
static int detach_auto = 1;
4645
static timestamp_t gc_log_expire_time;
4746
static const char *gc_log_expire = "1.day.ago";
@@ -148,7 +147,6 @@ static void gc_config(void)
148147
git_config_get_int("gc.aggressivedepth", &aggressive_depth);
149148
git_config_get_int("gc.auto", &gc_auto_threshold);
150149
git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
151-
git_config_get_bool("gc.writecommitgraph", &gc_write_commit_graph);
152150
git_config_get_bool("gc.autodetach", &detach_auto);
153151
git_config_get_expiry("gc.pruneexpire", &prune_expire);
154152
git_config_get_expiry("gc.worktreepruneexpire", &prune_worktrees_expire);
@@ -685,11 +683,11 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
685683
clean_pack_garbage();
686684
}
687685

688-
if (gc_write_commit_graph &&
689-
write_commit_graph_reachable(get_object_directory(),
690-
!quiet && !daemonized ? COMMIT_GRAPH_PROGRESS : 0,
691-
NULL))
692-
return 1;
686+
prepare_repo_settings(the_repository);
687+
if (the_repository->settings.gc_write_commit_graph == 1)
688+
write_commit_graph_reachable(get_object_directory(),
689+
!quiet && !daemonized ? COMMIT_GRAPH_PROGRESS : 0,
690+
NULL);
693691

694692
if (auto_gc && too_many_loose_objects())
695693
warning(_("There are too many unreachable loose objects; "

builtin/pack-objects.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,10 +2709,6 @@ static int git_pack_config(const char *k, const char *v, void *cb)
27092709
use_bitmap_index_default = git_config_bool(k, v);
27102710
return 0;
27112711
}
2712-
if (!strcmp(k, "pack.usesparse")) {
2713-
sparse = git_config_bool(k, v);
2714-
return 0;
2715-
}
27162712
if (!strcmp(k, "pack.threads")) {
27172713
delta_search_threads = git_config_int(k, v);
27182714
if (delta_search_threads < 0)
@@ -3332,6 +3328,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
33323328
read_replace_refs = 0;
33333329

33343330
sparse = git_env_bool("GIT_TEST_PACK_SPARSE", 0);
3331+
prepare_repo_settings(the_repository);
3332+
if (!sparse && the_repository->settings.pack_use_sparse != -1)
3333+
sparse = the_repository->settings.pack_use_sparse;
3334+
33353335
reset_pack_idx_option(&pack_idx_opts);
33363336
git_config(git_pack_config, NULL);
33373337

commit-graph.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ static void prepare_commit_graph_one(struct repository *r, const char *obj_dir)
466466
static int prepare_commit_graph(struct repository *r)
467467
{
468468
struct object_directory *odb;
469-
int config_value;
470469

471470
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD, 0))
472471
die("dying as requested by the '%s' variable on commit-graph load!",
@@ -476,9 +475,10 @@ static int prepare_commit_graph(struct repository *r)
476475
return !!r->objects->commit_graph;
477476
r->objects->commit_graph_attempted = 1;
478477

478+
prepare_repo_settings(r);
479+
479480
if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) &&
480-
(repo_config_get_bool(r, "core.commitgraph", &config_value) ||
481-
!config_value))
481+
r->settings.core_commit_graph != 1)
482482
/*
483483
* This repository is not configured to use commit graphs, so
484484
* do not load one. (But report commit_graph_attempted anyway

read-cache.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,16 +1599,17 @@ struct cache_entry *refresh_cache_entry(struct index_state *istate,
15991599

16001600
#define INDEX_FORMAT_DEFAULT 3
16011601

1602-
static unsigned int get_index_format_default(void)
1602+
static unsigned int get_index_format_default(struct repository *r)
16031603
{
16041604
char *envversion = getenv("GIT_INDEX_VERSION");
16051605
char *endp;
1606-
int value;
16071606
unsigned int version = INDEX_FORMAT_DEFAULT;
16081607

16091608
if (!envversion) {
1610-
if (!git_config_get_int("index.version", &value))
1611-
version = value;
1609+
prepare_repo_settings(r);
1610+
1611+
if (r->settings.index_version >= 0)
1612+
version = r->settings.index_version;
16121613
if (version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < version) {
16131614
warning(_("index.version set, but the value is invalid.\n"
16141615
"Using version %i"), INDEX_FORMAT_DEFAULT);
@@ -2765,7 +2766,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
27652766
}
27662767

27672768
if (!istate->version) {
2768-
istate->version = get_index_format_default();
2769+
istate->version = get_index_format_default(the_repository);
27692770
if (git_env_bool("GIT_TEST_SPLIT_INDEX", 0))
27702771
init_split_index(istate);
27712772
}

repo-settings.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "cache.h"
2+
#include "config.h"
3+
#include "repository.h"
4+
5+
void prepare_repo_settings(struct repository *r)
6+
{
7+
int value;
8+
9+
if (r->settings.initialized)
10+
return;
11+
12+
/* Defaults */
13+
memset(&r->settings, -1, sizeof(r->settings));
14+
15+
if (!repo_config_get_bool(r, "core.commitgraph", &value))
16+
r->settings.core_commit_graph = value;
17+
if (!repo_config_get_bool(r, "gc.writecommitgraph", &value))
18+
r->settings.gc_write_commit_graph = value;
19+
20+
if (!repo_config_get_bool(r, "index.version", &value))
21+
r->settings.index_version = value;
22+
23+
if (!repo_config_get_bool(r, "pack.usesparse", &value))
24+
r->settings.pack_use_sparse = value;
25+
}

repository.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ struct pathspec;
1111
struct raw_object_store;
1212
struct submodule_cache;
1313

14+
struct repo_settings {
15+
int initialized;
16+
17+
int core_commit_graph;
18+
int gc_write_commit_graph;
19+
20+
int index_version;
21+
22+
int pack_use_sparse;
23+
};
24+
1425
struct repository {
1526
/* Environment */
1627
/*
@@ -72,6 +83,8 @@ struct repository {
7283
*/
7384
char *submodule_prefix;
7485

86+
struct repo_settings settings;
87+
7588
/* Subsystems */
7689
/*
7790
* Repository's config which contains key-value pairs from the usual
@@ -157,5 +170,6 @@ int repo_read_index_unmerged(struct repository *);
157170
*/
158171
void repo_update_index_if_able(struct repository *, struct lock_file *);
159172

173+
void prepare_repo_settings(struct repository *r);
160174

161175
#endif /* REPOSITORY_H */

0 commit comments

Comments
 (0)