Skip to content

Commit 9b6b06c

Browse files
vdyegitster
authored andcommitted
config: pass 'repo' directly to 'config_with_options()'
Add a 'struct repository' argument to 'config_with_options()' and remove the 'repo' field from 'struct git_config_source'. A 'struct repository' instance was originally added to the config source in e3e8bf0 (submodule-config: pass repo upon blob config read, 2021-08-16) to improve how submodule blob config content was accessed. At the time, this was the only use for a 'repository' instance, so it was naturally added only where it was needed: to 'struct git_config_source'. However, in upcoming patches, 'config_with_options()' will need the repository instance to access extension information (regardless of whether a 'config_source' exists). To make the 'struct repository' instance more easily accessible, move it into the function's arguments. Update all callers of 'config_with_options()' to pass the appropriate 'repo' value: * in 'builtin/config.c', use 'the_repository' * in 'submodule--config.c', use the 'repo' arg in 'config_from_gitmodules()' * in 'read_[very_]early_config()' & 'read_protected_config()', set 'repo' to NULL (repository instances aren't available there) * in 'populate_remote_urls()', use the repo instance that has been added to the 'struct config_include_data' * in 'repo_read_config()', use the given 'repo' arg Finally, note that this patch eliminates the fallback to 'the_repository' that previously existed for the 'config_source' repo instance if it was NULL. The fallback is no longer necessary, as the 'repo' is set explicitly in all cases where it is needed. Signed-off-by: Victoria Dye <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 847d002 commit 9b6b06c

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

builtin/config.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ static int get_value(const char *key_, const char *regex_, unsigned flags)
375375
}
376376

377377
config_with_options(collect_config, &values,
378-
&given_config_source, &config_options);
378+
&given_config_source, the_repository,
379+
&config_options);
379380

380381
if (!values.nr && default_value) {
381382
struct strbuf *item;
@@ -486,7 +487,8 @@ static void get_color(const char *var, const char *def_color)
486487
get_color_found = 0;
487488
parsed_color[0] = '\0';
488489
config_with_options(git_get_color_config, NULL,
489-
&given_config_source, &config_options);
490+
&given_config_source, the_repository,
491+
&config_options);
490492

491493
if (!get_color_found && def_color) {
492494
if (color_parse(def_color, parsed_color) < 0)
@@ -518,7 +520,8 @@ static int get_colorbool(const char *var, int print)
518520
get_diff_color_found = -1;
519521
get_color_ui_found = -1;
520522
config_with_options(git_get_colorbool_config, NULL,
521-
&given_config_source, &config_options);
523+
&given_config_source, the_repository,
524+
&config_options);
522525

523526
if (get_colorbool_found < 0) {
524527
if (!strcmp(get_colorbool_slot, "color.diff"))
@@ -607,7 +610,8 @@ static int get_urlmatch(const char *var, const char *url)
607610
}
608611

609612
config_with_options(urlmatch_config_entry, &config,
610-
&given_config_source, &config_options);
613+
&given_config_source, the_repository,
614+
&config_options);
611615

612616
ret = !values.nr;
613617

@@ -827,7 +831,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
827831
if (actions == ACTION_LIST) {
828832
check_argc(argc, 0, 0);
829833
if (config_with_options(show_all_config, NULL,
830-
&given_config_source,
834+
&given_config_source, the_repository,
831835
&config_options) < 0) {
832836
if (given_config_source.file)
833837
die_errno(_("unable to read config file '%s'"),

config.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ struct config_include_data {
199199
void *data;
200200
const struct config_options *opts;
201201
struct git_config_source *config_source;
202+
struct repository *repo;
202203
struct config_reader *config_reader;
203204

204205
/*
@@ -415,7 +416,8 @@ static void populate_remote_urls(struct config_include_data *inc)
415416

416417
inc->remote_urls = xmalloc(sizeof(*inc->remote_urls));
417418
string_list_init_dup(inc->remote_urls);
418-
config_with_options(add_remote_url, inc->remote_urls, inc->config_source, &opts);
419+
config_with_options(add_remote_url, inc->remote_urls,
420+
inc->config_source, inc->repo, &opts);
419421

420422
config_reader_set_scope(inc->config_reader, store_scope);
421423
}
@@ -2261,6 +2263,7 @@ static int do_git_config_sequence(struct config_reader *reader,
22612263

22622264
int config_with_options(config_fn_t fn, void *data,
22632265
struct git_config_source *config_source,
2266+
struct repository *repo,
22642267
const struct config_options *opts)
22652268
{
22662269
struct config_include_data inc = CONFIG_INCLUDE_INIT;
@@ -2271,6 +2274,7 @@ int config_with_options(config_fn_t fn, void *data,
22712274
inc.fn = fn;
22722275
inc.data = data;
22732276
inc.opts = opts;
2277+
inc.repo = repo;
22742278
inc.config_source = config_source;
22752279
inc.config_reader = &the_reader;
22762280
fn = git_config_include;
@@ -2289,8 +2293,6 @@ int config_with_options(config_fn_t fn, void *data,
22892293
} else if (config_source && config_source->file) {
22902294
ret = git_config_from_file(fn, config_source->file, data);
22912295
} else if (config_source && config_source->blob) {
2292-
struct repository *repo = config_source->repo ?
2293-
config_source->repo : the_repository;
22942296
ret = git_config_from_blob_ref(fn, repo, config_source->blob,
22952297
data);
22962298
} else {
@@ -2353,7 +2355,7 @@ void read_early_config(config_fn_t cb, void *data)
23532355
opts.git_dir = gitdir.buf;
23542356
}
23552357

2356-
config_with_options(cb, data, NULL, &opts);
2358+
config_with_options(cb, data, NULL, NULL, &opts);
23572359

23582360
strbuf_release(&commondir);
23592361
strbuf_release(&gitdir);
@@ -2373,7 +2375,7 @@ void read_very_early_config(config_fn_t cb, void *data)
23732375
opts.ignore_cmdline = 1;
23742376
opts.system_gently = 1;
23752377

2376-
config_with_options(cb, data, NULL, &opts);
2378+
config_with_options(cb, data, NULL, NULL, &opts);
23772379
}
23782380

23792381
RESULT_MUST_BE_USED
@@ -2681,7 +2683,7 @@ static void repo_read_config(struct repository *repo)
26812683
data.config_set = repo->config;
26822684
data.config_reader = &the_reader;
26832685

2684-
if (config_with_options(config_set_callback, &data, NULL, &opts) < 0)
2686+
if (config_with_options(config_set_callback, &data, NULL, repo, &opts) < 0)
26852687
/*
26862688
* config_with_options() normally returns only
26872689
* zero, as most errors are fatal, and
@@ -2825,7 +2827,7 @@ static void read_protected_config(void)
28252827
git_configset_init(&protected_config);
28262828
data.config_set = &protected_config;
28272829
data.config_reader = &the_reader;
2828-
config_with_options(config_set_callback, &data, NULL, &opts);
2830+
config_with_options(config_set_callback, &data, NULL, NULL, &opts);
28292831
}
28302832

28312833
void git_protected_config(config_fn_t fn, void *data)

config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "hashmap.h"
55
#include "string-list.h"
6+
#include "repository.h"
67

78

89
/**
@@ -49,8 +50,6 @@ const char *config_scope_name(enum config_scope scope);
4950
struct git_config_source {
5051
unsigned int use_stdin:1;
5152
const char *file;
52-
/* The repository if blob is not NULL; leave blank for the_repository */
53-
struct repository *repo;
5453
const char *blob;
5554
enum config_scope scope;
5655
};
@@ -196,6 +195,7 @@ void git_config(config_fn_t fn, void *);
196195
*/
197196
int config_with_options(config_fn_t fn, void *,
198197
struct git_config_source *config_source,
198+
struct repository *repo,
199199
const struct config_options *opts);
200200

201201
/**

submodule-config.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,14 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
659659
config_source.file = file;
660660
} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||
661661
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
662-
config_source.repo = repo;
663662
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
664663
if (repo != the_repository)
665664
add_submodule_odb_by_path(repo->objects->odb->path);
666665
} else {
667666
goto out;
668667
}
669668

670-
config_with_options(fn, data, &config_source, &opts);
669+
config_with_options(fn, data, &config_source, repo, &opts);
671670

672671
out:
673672
free(oidstr);

0 commit comments

Comments
 (0)