Skip to content

Commit c48f4b3

Browse files
pcloudsgitster
authored andcommitted
config: prepare to pass more info in git_config_with_options()
So far we can only pass one flag, respect_includes, to thie function. We need to pass some more (non-flag even), so let's make it accept a struct instead of an integer. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 584f897 commit c48f4b3

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

builtin/config.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ static int use_global_config, use_system_config, use_local_config;
2626
static struct git_config_source given_config_source;
2727
static int actions, types;
2828
static int end_null;
29-
static int respect_includes = -1;
29+
static int respect_includes_opt = -1;
30+
static struct config_options config_options;
3031
static int show_origin;
3132

3233
#define ACTION_GET (1<<0)
@@ -81,7 +82,7 @@ static struct option builtin_config_options[] = {
8182
OPT_GROUP(N_("Other")),
8283
OPT_BOOL('z', "null", &end_null, N_("terminate values with NUL byte")),
8384
OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")),
84-
OPT_BOOL(0, "includes", &respect_includes, N_("respect include directives on lookup")),
85+
OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
8586
OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")),
8687
OPT_END(),
8788
};
@@ -242,7 +243,7 @@ static int get_value(const char *key_, const char *regex_)
242243
}
243244

244245
git_config_with_options(collect_config, &values,
245-
&given_config_source, respect_includes);
246+
&given_config_source, &config_options);
246247

247248
ret = !values.nr;
248249

@@ -320,7 +321,7 @@ static void get_color(const char *var, const char *def_color)
320321
get_color_found = 0;
321322
parsed_color[0] = '\0';
322323
git_config_with_options(git_get_color_config, NULL,
323-
&given_config_source, respect_includes);
324+
&given_config_source, &config_options);
324325

325326
if (!get_color_found && def_color) {
326327
if (color_parse(def_color, parsed_color) < 0)
@@ -352,7 +353,7 @@ static int get_colorbool(const char *var, int print)
352353
get_diff_color_found = -1;
353354
get_color_ui_found = -1;
354355
git_config_with_options(git_get_colorbool_config, NULL,
355-
&given_config_source, respect_includes);
356+
&given_config_source, &config_options);
356357

357358
if (get_colorbool_found < 0) {
358359
if (!strcmp(get_colorbool_slot, "color.diff"))
@@ -441,7 +442,7 @@ static int get_urlmatch(const char *var, const char *url)
441442
}
442443

443444
git_config_with_options(urlmatch_config_entry, &config,
444-
&given_config_source, respect_includes);
445+
&given_config_source, &config_options);
445446

446447
ret = !values.nr;
447448

@@ -530,8 +531,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
530531
prefix_filename(prefix, given_config_source.file);
531532
}
532533

533-
if (respect_includes == -1)
534-
respect_includes = !given_config_source.file;
534+
if (respect_includes_opt == -1)
535+
config_options.respect_includes = !given_config_source.file;
536+
else
537+
config_options.respect_includes = respect_includes_opt;
535538

536539
if (end_null) {
537540
term = '\0';
@@ -578,7 +581,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
578581
check_argc(argc, 0, 0);
579582
if (git_config_with_options(show_all_config, NULL,
580583
&given_config_source,
581-
respect_includes) < 0) {
584+
&config_options) < 0) {
582585
if (given_config_source.file)
583586
die_errno("unable to read config file '%s'",
584587
given_config_source.file);

cache.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,10 @@ enum config_origin_type {
18851885
CONFIG_ORIGIN_CMDLINE
18861886
};
18871887

1888+
struct config_options {
1889+
unsigned int respect_includes : 1;
1890+
};
1891+
18881892
typedef int (*config_fn_t)(const char *, const char *, void *);
18891893
extern int git_default_config(const char *, const char *, void *);
18901894
extern int git_config_from_file(config_fn_t fn, const char *, void *);
@@ -1898,7 +1902,7 @@ extern void read_early_config(config_fn_t cb, void *data);
18981902
extern void git_config(config_fn_t fn, void *);
18991903
extern int git_config_with_options(config_fn_t fn, void *,
19001904
struct git_config_source *config_source,
1901-
int respect_includes);
1905+
const struct config_options *opts);
19021906
extern int git_parse_ulong(const char *, unsigned long *);
19031907
extern int git_parse_maybe_bool(const char *);
19041908
extern int git_config_int(const char *, const char *);
@@ -1950,6 +1954,7 @@ struct config_include_data {
19501954
int depth;
19511955
config_fn_t fn;
19521956
void *data;
1957+
const struct config_options *opts;
19531958
};
19541959
#define CONFIG_INCLUDE_INIT { 0 }
19551960
extern int git_config_include(const char *name, const char *value, void *data);

config.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,13 +1530,14 @@ static int do_git_config_sequence(config_fn_t fn, void *data)
15301530

15311531
int git_config_with_options(config_fn_t fn, void *data,
15321532
struct git_config_source *config_source,
1533-
int respect_includes)
1533+
const struct config_options *opts)
15341534
{
15351535
struct config_include_data inc = CONFIG_INCLUDE_INIT;
15361536

1537-
if (respect_includes) {
1537+
if (opts->respect_includes) {
15381538
inc.fn = fn;
15391539
inc.data = data;
1540+
inc.opts = opts;
15401541
fn = git_config_include;
15411542
data = &inc;
15421543
}
@@ -1557,7 +1558,10 @@ int git_config_with_options(config_fn_t fn, void *data,
15571558

15581559
static void git_config_raw(config_fn_t fn, void *data)
15591560
{
1560-
if (git_config_with_options(fn, data, NULL, 1) < 0)
1561+
struct config_options opts = {0};
1562+
1563+
opts.respect_includes = 1;
1564+
if (git_config_with_options(fn, data, NULL, &opts) < 0)
15611565
/*
15621566
* git_config_with_options() normally returns only
15631567
* zero, as most errors are fatal, and
@@ -1597,9 +1601,11 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data)
15971601

15981602
void read_early_config(config_fn_t cb, void *data)
15991603
{
1604+
struct config_options opts = {0};
16001605
struct strbuf buf = STRBUF_INIT;
16011606

1602-
git_config_with_options(cb, data, NULL, 1);
1607+
opts.respect_includes = 1;
1608+
git_config_with_options(cb, data, NULL, &opts);
16031609

16041610
/*
16051611
* When setup_git_directory() was not yet asked to discover the
@@ -1615,7 +1621,7 @@ void read_early_config(config_fn_t cb, void *data)
16151621
memset(&repo_config, 0, sizeof(repo_config));
16161622
strbuf_addstr(&buf, "/config");
16171623
repo_config.file = buf.buf;
1618-
git_config_with_options(cb, data, &repo_config, 1);
1624+
git_config_with_options(cb, data, &repo_config, &opts);
16191625
}
16201626
strbuf_release(&buf);
16211627
}

0 commit comments

Comments
 (0)