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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Apr 17, 2017 at 17:10 UTC
c48f4b379eb3a0d093f5a87cce1d2ed6c175104f
3 files changed
+29
-15
builtin/config.c
+12
-9
@@ -26,7 +26,8 @@ static int use_global_config, use_system_config, use_local_config;
26
static struct git_config_source given_config_source;
27
static int actions, types;
28
static int end_null;
29
-static int respect_includes = -1;
29
+static int respect_includes_opt = -1;
30
+static struct config_options config_options;
31
static int show_origin;
32
33
#define ACTION_GET (1<<0)
@@ -81,7 +82,7 @@ static struct option builtin_config_options[] = {
82
OPT_GROUP(N_("Other")),
83
OPT_BOOL('z', "null", &end_null, N_("terminate values with NUL byte")),
84
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")),
86
OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")),
87
OPT_END(),
88
};
@@ -242,7 +243,7 @@ static int get_value(const char *key_, const char *regex_)
243
}
244
245
git_config_with_options(collect_config, &values,
245
- &given_config_source, respect_includes);
246
+ &given_config_source, &config_options);
247
248
ret = !values.nr;
249
@@ -320,7 +321,7 @@ static void get_color(const char *var, const char *def_color)
321
get_color_found = 0;
322
parsed_color[0] = '\0';
323
git_config_with_options(git_get_color_config, NULL,
323
- &given_config_source, respect_includes);
324
+ &given_config_source, &config_options);
325
326
if (!get_color_found && def_color) {
327
if (color_parse(def_color, parsed_color) < 0)
@@ -352,7 +353,7 @@ static int get_colorbool(const char *var, int print)
353
get_diff_color_found = -1;
354
get_color_ui_found = -1;
355
git_config_with_options(git_get_colorbool_config, NULL,
355
- &given_config_source, respect_includes);
356
+ &given_config_source, &config_options);
357
358
if (get_colorbool_found < 0) {
359
if (!strcmp(get_colorbool_slot, "color.diff"))
@@ -441,7 +442,7 @@ static int get_urlmatch(const char *var, const char *url)
442
}
443
444
git_config_with_options(urlmatch_config_entry, &config,
444
- &given_config_source, respect_includes);
445
+ &given_config_source, &config_options);
446
447
ret = !values.nr;
448
@@ -530,8 +531,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
531
prefix_filename(prefix, given_config_source.file);
532
}
533
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;
538
539
if (end_null) {
540
term = '\0';
@@ -578,7 +581,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
581
check_argc(argc, 0, 0);
582
if (git_config_with_options(show_all_config, NULL,
583
&given_config_source,
581
- respect_includes) < 0) {
584
+ &config_options) < 0) {
585
if (given_config_source.file)
586
die_errno("unable to read config file '%s'",
587
given_config_source.file);
cache.h
+6
-1
@@ -1885,6 +1885,10 @@ enum config_origin_type {
1885
CONFIG_ORIGIN_CMDLINE
1886
};
1887
1888
+struct config_options {
1889
+ unsigned int respect_includes : 1;
1890
+};
1891
+
1892
typedef int (*config_fn_t)(const char *, const char *, void *);
1893
extern int git_default_config(const char *, const char *, void *);
1894
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);
1902
extern void git_config(config_fn_t fn, void *);
1903
extern int git_config_with_options(config_fn_t fn, void *,
1904
struct git_config_source *config_source,
1901
- int respect_includes);
1905
+ const struct config_options *opts);
1906
extern int git_parse_ulong(const char *, unsigned long *);
1907
extern int git_parse_maybe_bool(const char *);
1908
extern int git_config_int(const char *, const char *);
@@ -1950,6 +1954,7 @@ struct config_include_data {
1954
int depth;
1955
config_fn_t fn;
1956
void *data;
1957
+ const struct config_options *opts;
1958
};
1959
#define CONFIG_INCLUDE_INIT { 0 }
1960
extern int git_config_include(const char *name, const char *value, void *data);
config.c
+11
-5
@@ -1530,13 +1530,14 @@ static int do_git_config_sequence(config_fn_t fn, void *data)
1530
1531
int git_config_with_options(config_fn_t fn, void *data,
1532
struct git_config_source *config_source,
1533
- int respect_includes)
1533
+ const struct config_options *opts)
1534
{
1535
struct config_include_data inc = CONFIG_INCLUDE_INIT;
1536
1537
- if (respect_includes) {
1537
+ if (opts->respect_includes) {
1538
inc.fn = fn;
1539
inc.data = data;
1540
+ inc.opts = opts;
1541
fn = git_config_include;
1542
data = &inc;
1543
}
@@ -1557,7 +1558,10 @@ int git_config_with_options(config_fn_t fn, void *data,
1558
1559
static void git_config_raw(config_fn_t fn, void *data)
1560
{
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)
1565
/*
1566
* git_config_with_options() normally returns only
1567
* 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)
1601
1602
void read_early_config(config_fn_t cb, void *data)
1603
{
1604
+ struct config_options opts = {0};
1605
struct strbuf buf = STRBUF_INIT;
1606
1602
- git_config_with_options(cb, data, NULL, 1);
1607
+ opts.respect_includes = 1;
1608
+ git_config_with_options(cb, data, NULL, &opts);
1609
1610
/*
1611
* 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)
1621
memset(&repo_config, 0, sizeof(repo_config));
1622
strbuf_addstr(&buf, "/config");
1623
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);
1625
}
1626
strbuf_release(&buf);
1627
}