Skip to content

Commit dc90208

Browse files
chooglengitster
authored andcommitted
trace2: plumb config kvi
There is a code path starting from trace2_def_param_fl() that eventually calls current_config_scope(), and thus it needs to have "kvi" plumbed through it. Additional plumbing is also needed to get "kvi" to trace2_def_param_fl(), which gets called by two code paths: - Through tr2_cfg_cb(), which is a config callback, so it trivially receives "kvi" via the "struct config_context ctx" parameter. - Through tr2_list_env_vars_fl(), which is a high level function that lists environment variables for tracing. This has been secretly behaving like git_config_from_parameters() (in that it parses config from environment variables/the CLI), but does not set config source information. Teach tr2_list_env_vars_fl() to be well-behaved by using kvi_from_param(), which is used elsewhere for CLI/environment variable-based config. As a result, current_config_scope() has no more callers, so remove it. Signed-off-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 26b6693 commit dc90208

9 files changed

+19
-60
lines changed

config.c

-46
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,6 @@ struct config_reader {
8585
*/
8686
struct config_source *source;
8787
struct key_value_info *config_kvi;
88-
/*
89-
* The "scope" of the current config source being parsed (repo, global,
90-
* etc). Like "source", this is only set when parsing a config source.
91-
* It's not part of "source" because it transcends a single file (i.e.,
92-
* a file included from .git/config is still in "repo" scope).
93-
*
94-
* When iterating through a configset, the equivalent value is
95-
* "config_kvi.scope" (see above).
96-
*/
97-
enum config_scope parsing_scope;
9888
};
9989
/*
10090
* Where possible, prefer to accept "struct config_reader" as an arg than to use
@@ -125,19 +115,9 @@ static inline struct config_source *config_reader_pop_source(struct config_reade
125115
static inline void config_reader_set_kvi(struct config_reader *reader,
126116
struct key_value_info *kvi)
127117
{
128-
if (kvi && (reader->source || reader->parsing_scope))
129-
BUG("kvi should not be set while parsing a config source");
130118
reader->config_kvi = kvi;
131119
}
132120

133-
static inline void config_reader_set_scope(struct config_reader *reader,
134-
enum config_scope scope)
135-
{
136-
if (scope && reader->config_kvi)
137-
BUG("scope should only be set when iterating through a config source");
138-
reader->parsing_scope = scope;
139-
}
140-
141121
static int pack_compression_seen;
142122
static int zlib_compression_seen;
143123

@@ -412,19 +392,13 @@ static void populate_remote_urls(struct config_include_data *inc)
412392
{
413393
struct config_options opts;
414394

415-
enum config_scope store_scope = inc->config_reader->parsing_scope;
416-
417395
opts = *inc->opts;
418396
opts.unconditional_remote_url = 1;
419397

420-
config_reader_set_scope(inc->config_reader, 0);
421-
422398
inc->remote_urls = xmalloc(sizeof(*inc->remote_urls));
423399
string_list_init_dup(inc->remote_urls);
424400
config_with_options(add_remote_url, inc->remote_urls,
425401
inc->config_source, inc->repo, &opts);
426-
427-
config_reader_set_scope(inc->config_reader, store_scope);
428402
}
429403

430404
static int forbid_remote_url(const char *var, const char *value UNUSED,
@@ -2255,7 +2229,6 @@ static int do_git_config_sequence(struct config_reader *reader,
22552229
char *user_config = NULL;
22562230
char *repo_config;
22572231
char *worktree_config;
2258-
enum config_scope prev_parsing_scope = reader->parsing_scope;
22592232

22602233
/*
22612234
* Ensure that either:
@@ -2273,15 +2246,13 @@ static int do_git_config_sequence(struct config_reader *reader,
22732246
worktree_config = NULL;
22742247
}
22752248

2276-
config_reader_set_scope(reader, CONFIG_SCOPE_SYSTEM);
22772249
if (git_config_system() && system_config &&
22782250
!access_or_die(system_config, R_OK,
22792251
opts->system_gently ? ACCESS_EACCES_OK : 0))
22802252
ret += git_config_from_file_with_options(fn, system_config,
22812253
data, CONFIG_SCOPE_SYSTEM,
22822254
NULL);
22832255

2284-
config_reader_set_scope(reader, CONFIG_SCOPE_GLOBAL);
22852256
git_global_config(&user_config, &xdg_config);
22862257

22872258
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))
@@ -2292,13 +2263,11 @@ static int do_git_config_sequence(struct config_reader *reader,
22922263
ret += git_config_from_file_with_options(fn, user_config, data,
22932264
CONFIG_SCOPE_GLOBAL, NULL);
22942265

2295-
config_reader_set_scope(reader, CONFIG_SCOPE_LOCAL);
22962266
if (!opts->ignore_repo && repo_config &&
22972267
!access_or_die(repo_config, R_OK, 0))
22982268
ret += git_config_from_file_with_options(fn, repo_config, data,
22992269
CONFIG_SCOPE_LOCAL, NULL);
23002270

2301-
config_reader_set_scope(reader, CONFIG_SCOPE_WORKTREE);
23022271
if (!opts->ignore_worktree && worktree_config &&
23032272
repo && repo->repository_format_worktree_config &&
23042273
!access_or_die(worktree_config, R_OK, 0)) {
@@ -2307,11 +2276,9 @@ static int do_git_config_sequence(struct config_reader *reader,
23072276
NULL);
23082277
}
23092278

2310-
config_reader_set_scope(reader, CONFIG_SCOPE_COMMAND);
23112279
if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0)
23122280
die(_("unable to parse command-line config"));
23132281

2314-
config_reader_set_scope(reader, prev_parsing_scope);
23152282
free(system_config);
23162283
free(xdg_config);
23172284
free(user_config);
@@ -2326,7 +2293,6 @@ int config_with_options(config_fn_t fn, void *data,
23262293
const struct config_options *opts)
23272294
{
23282295
struct config_include_data inc = CONFIG_INCLUDE_INIT;
2329-
enum config_scope prev_scope = the_reader.parsing_scope;
23302296
int ret;
23312297

23322298
if (opts->respect_includes) {
@@ -2340,9 +2306,6 @@ int config_with_options(config_fn_t fn, void *data,
23402306
data = &inc;
23412307
}
23422308

2343-
if (config_source)
2344-
config_reader_set_scope(&the_reader, config_source->scope);
2345-
23462309
/*
23472310
* If we have a specific filename, use it. Otherwise, follow the
23482311
* regular lookup sequence.
@@ -2364,7 +2327,6 @@ int config_with_options(config_fn_t fn, void *data,
23642327
string_list_clear(inc.remote_urls, 0);
23652328
FREE_AND_NULL(inc.remote_urls);
23662329
}
2367-
config_reader_set_scope(&the_reader, prev_scope);
23682330
return ret;
23692331
}
23702332

@@ -4088,14 +4050,6 @@ static int reader_config_name(struct config_reader *reader, const char **out)
40884050
return 0;
40894051
}
40904052

4091-
enum config_scope current_config_scope(void)
4092-
{
4093-
if (the_reader.config_kvi)
4094-
return the_reader.config_kvi->scope;
4095-
else
4096-
return the_reader.parsing_scope;
4097-
}
4098-
40994053
int lookup_config(const char **mapping, int nr_mapping, const char *var)
41004054
{
41014055
int i;

config.h

-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ void git_global_config(char **user, char **xdg);
386386

387387
int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
388388

389-
enum config_scope current_config_scope(void);
390389
const char *config_origin_type_name(enum config_origin_type type);
391390
void kvi_from_param(struct key_value_info *out);
392391

trace2.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ void trace2_thread_exit_fl(const char *file, int line)
634634
}
635635

636636
void trace2_def_param_fl(const char *file, int line, const char *param,
637-
const char *value)
637+
const char *value, const struct key_value_info *kvi)
638638
{
639639
struct tr2_tgt *tgt_j;
640640
int j;
@@ -644,7 +644,7 @@ void trace2_def_param_fl(const char *file, int line, const char *param,
644644

645645
for_each_wanted_builtin (j, tgt_j)
646646
if (tgt_j->pfn_param_fl)
647-
tgt_j->pfn_param_fl(file, line, param, value);
647+
tgt_j->pfn_param_fl(file, line, param, value, kvi);
648648
}
649649

650650
void trace2_def_repo_fl(const char *file, int line, struct repository *repo)

trace2.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ void trace2_thread_exit_fl(const char *file, int line);
325325

326326
#define trace2_thread_exit() trace2_thread_exit_fl(__FILE__, __LINE__)
327327

328+
struct key_value_info;
328329
/*
329330
* Emits a "def_param" message containing a key/value pair.
330331
*
@@ -334,7 +335,7 @@ void trace2_thread_exit_fl(const char *file, int line);
334335
* `core.abbrev`, `status.showUntrackedFiles`, or `--no-ahead-behind`.
335336
*/
336337
void trace2_def_param_fl(const char *file, int line, const char *param,
337-
const char *value);
338+
const char *value, const struct key_value_info *kvi);
338339

339340
#define trace2_def_param(param, value) \
340341
trace2_def_param_fl(__FILE__, __LINE__, (param), (value))

trace2/tr2_cfg.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct tr2_cfg_data {
100100
* See if the given config key matches any of our patterns of interest.
101101
*/
102102
static int tr2_cfg_cb(const char *key, const char *value,
103-
const struct config_context *ctx UNUSED, void *d)
103+
const struct config_context *ctx, void *d)
104104
{
105105
struct strbuf **s;
106106
struct tr2_cfg_data *data = (struct tr2_cfg_data *)d;
@@ -109,7 +109,8 @@ static int tr2_cfg_cb(const char *key, const char *value,
109109
struct strbuf *buf = *s;
110110
int wm = wildmatch(buf->buf, key, WM_CASEFOLD);
111111
if (wm == WM_MATCH) {
112-
trace2_def_param_fl(data->file, data->line, key, value);
112+
trace2_def_param_fl(data->file, data->line, key, value,
113+
ctx->kvi);
113114
return 0;
114115
}
115116
}
@@ -127,16 +128,18 @@ void tr2_cfg_list_config_fl(const char *file, int line)
127128

128129
void tr2_list_env_vars_fl(const char *file, int line)
129130
{
131+
struct key_value_info kvi = KVI_INIT;
130132
struct strbuf **s;
131133

134+
kvi_from_param(&kvi);
132135
if (tr2_load_env_vars() <= 0)
133136
return;
134137

135138
for (s = tr2_cfg_env_vars; *s; s++) {
136139
struct strbuf *buf = *s;
137140
const char *val = getenv(buf->buf);
138141
if (val && *val)
139-
trace2_def_param_fl(file, line, buf->buf, val);
142+
trace2_def_param_fl(file, line, buf->buf, val, &kvi);
140143
}
141144
}
142145

trace2/tr2_tgt.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ typedef void(tr2_tgt_evt_exec_result_fl_t)(const char *file, int line,
6969
uint64_t us_elapsed_absolute,
7070
int exec_id, int code);
7171

72+
struct key_value_info;
7273
typedef void(tr2_tgt_evt_param_fl_t)(const char *file, int line,
73-
const char *param, const char *value);
74+
const char *param, const char *value,
75+
const struct key_value_info *kvi);
7476

7577
typedef void(tr2_tgt_evt_repo_fl_t)(const char *file, int line,
7678
const struct repository *repo);

trace2/tr2_tgt_event.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,11 @@ static void fn_exec_result_fl(const char *file, int line,
477477
}
478478

479479
static void fn_param_fl(const char *file, int line, const char *param,
480-
const char *value)
480+
const char *value, const struct key_value_info *kvi)
481481
{
482482
const char *event_name = "def_param";
483483
struct json_writer jw = JSON_WRITER_INIT;
484-
enum config_scope scope = current_config_scope();
484+
enum config_scope scope = kvi->scope;
485485
const char *scope_name = config_scope_name(scope);
486486

487487
jw_object_begin(&jw, 0);

trace2/tr2_tgt_normal.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ static void fn_exec_result_fl(const char *file, int line,
297297
}
298298

299299
static void fn_param_fl(const char *file, int line, const char *param,
300-
const char *value)
300+
const char *value, const struct key_value_info *kvi)
301301
{
302302
struct strbuf buf_payload = STRBUF_INIT;
303-
enum config_scope scope = current_config_scope();
303+
enum config_scope scope = kvi->scope;
304304
const char *scope_name = config_scope_name(scope);
305305

306306
strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param,

trace2/tr2_tgt_perf.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,12 @@ static void fn_exec_result_fl(const char *file, int line,
439439
}
440440

441441
static void fn_param_fl(const char *file, int line, const char *param,
442-
const char *value)
442+
const char *value, const struct key_value_info *kvi)
443443
{
444444
const char *event_name = "def_param";
445445
struct strbuf buf_payload = STRBUF_INIT;
446446
struct strbuf scope_payload = STRBUF_INIT;
447-
enum config_scope scope = current_config_scope();
447+
enum config_scope scope = kvi->scope;
448448
const char *scope_name = config_scope_name(scope);
449449

450450
strbuf_addf(&buf_payload, "%s:%s", param, value);

0 commit comments

Comments
 (0)