Git fork

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 <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Glen Choo and committed by
Junio C Hamano
dc902084 26b66932

+19 -60
-46
config.c
··· 85 85 */ 86 86 struct config_source *source; 87 87 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; 98 88 }; 99 89 /* 100 90 * Where possible, prefer to accept "struct config_reader" as an arg than to use ··· 125 115 static inline void config_reader_set_kvi(struct config_reader *reader, 126 116 struct key_value_info *kvi) 127 117 { 128 - if (kvi && (reader->source || reader->parsing_scope)) 129 - BUG("kvi should not be set while parsing a config source"); 130 118 reader->config_kvi = kvi; 131 - } 132 - 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 119 } 140 120 141 121 static int pack_compression_seen; ··· 412 392 { 413 393 struct config_options opts; 414 394 415 - enum config_scope store_scope = inc->config_reader->parsing_scope; 416 - 417 395 opts = *inc->opts; 418 396 opts.unconditional_remote_url = 1; 419 397 420 - config_reader_set_scope(inc->config_reader, 0); 421 - 422 398 inc->remote_urls = xmalloc(sizeof(*inc->remote_urls)); 423 399 string_list_init_dup(inc->remote_urls); 424 400 config_with_options(add_remote_url, inc->remote_urls, 425 401 inc->config_source, inc->repo, &opts); 426 - 427 - config_reader_set_scope(inc->config_reader, store_scope); 428 402 } 429 403 430 404 static int forbid_remote_url(const char *var, const char *value UNUSED, ··· 2255 2229 char *user_config = NULL; 2256 2230 char *repo_config; 2257 2231 char *worktree_config; 2258 - enum config_scope prev_parsing_scope = reader->parsing_scope; 2259 2232 2260 2233 /* 2261 2234 * Ensure that either: ··· 2273 2246 worktree_config = NULL; 2274 2247 } 2275 2248 2276 - config_reader_set_scope(reader, CONFIG_SCOPE_SYSTEM); 2277 2249 if (git_config_system() && system_config && 2278 2250 !access_or_die(system_config, R_OK, 2279 2251 opts->system_gently ? ACCESS_EACCES_OK : 0)) ··· 2281 2253 data, CONFIG_SCOPE_SYSTEM, 2282 2254 NULL); 2283 2255 2284 - config_reader_set_scope(reader, CONFIG_SCOPE_GLOBAL); 2285 2256 git_global_config(&user_config, &xdg_config); 2286 2257 2287 2258 if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK)) ··· 2292 2263 ret += git_config_from_file_with_options(fn, user_config, data, 2293 2264 CONFIG_SCOPE_GLOBAL, NULL); 2294 2265 2295 - config_reader_set_scope(reader, CONFIG_SCOPE_LOCAL); 2296 2266 if (!opts->ignore_repo && repo_config && 2297 2267 !access_or_die(repo_config, R_OK, 0)) 2298 2268 ret += git_config_from_file_with_options(fn, repo_config, data, 2299 2269 CONFIG_SCOPE_LOCAL, NULL); 2300 2270 2301 - config_reader_set_scope(reader, CONFIG_SCOPE_WORKTREE); 2302 2271 if (!opts->ignore_worktree && worktree_config && 2303 2272 repo && repo->repository_format_worktree_config && 2304 2273 !access_or_die(worktree_config, R_OK, 0)) { ··· 2307 2276 NULL); 2308 2277 } 2309 2278 2310 - config_reader_set_scope(reader, CONFIG_SCOPE_COMMAND); 2311 2279 if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0) 2312 2280 die(_("unable to parse command-line config")); 2313 2281 2314 - config_reader_set_scope(reader, prev_parsing_scope); 2315 2282 free(system_config); 2316 2283 free(xdg_config); 2317 2284 free(user_config); ··· 2326 2293 const struct config_options *opts) 2327 2294 { 2328 2295 struct config_include_data inc = CONFIG_INCLUDE_INIT; 2329 - enum config_scope prev_scope = the_reader.parsing_scope; 2330 2296 int ret; 2331 2297 2332 2298 if (opts->respect_includes) { ··· 2340 2306 data = &inc; 2341 2307 } 2342 2308 2343 - if (config_source) 2344 - config_reader_set_scope(&the_reader, config_source->scope); 2345 - 2346 2309 /* 2347 2310 * If we have a specific filename, use it. Otherwise, follow the 2348 2311 * regular lookup sequence. ··· 2364 2327 string_list_clear(inc.remote_urls, 0); 2365 2328 FREE_AND_NULL(inc.remote_urls); 2366 2329 } 2367 - config_reader_set_scope(&the_reader, prev_scope); 2368 2330 return ret; 2369 2331 } 2370 2332 ··· 4086 4048 else 4087 4049 return 1; 4088 4050 return 0; 4089 - } 4090 - 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 4051 } 4098 4052 4099 4053 int lookup_config(const char **mapping, int nr_mapping, const char *var)
-1
config.h
··· 386 386 387 387 int git_config_parse_parameter(const char *, config_fn_t fn, void *data); 388 388 389 - enum config_scope current_config_scope(void); 390 389 const char *config_origin_type_name(enum config_origin_type type); 391 390 void kvi_from_param(struct key_value_info *out); 392 391
+2 -2
trace2.c
··· 634 634 } 635 635 636 636 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) 638 638 { 639 639 struct tr2_tgt *tgt_j; 640 640 int j; ··· 644 644 645 645 for_each_wanted_builtin (j, tgt_j) 646 646 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); 648 648 } 649 649 650 650 void trace2_def_repo_fl(const char *file, int line, struct repository *repo)
+2 -1
trace2.h
··· 325 325 326 326 #define trace2_thread_exit() trace2_thread_exit_fl(__FILE__, __LINE__) 327 327 328 + struct key_value_info; 328 329 /* 329 330 * Emits a "def_param" message containing a key/value pair. 330 331 * ··· 334 335 * `core.abbrev`, `status.showUntrackedFiles`, or `--no-ahead-behind`. 335 336 */ 336 337 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); 338 339 339 340 #define trace2_def_param(param, value) \ 340 341 trace2_def_param_fl(__FILE__, __LINE__, (param), (value))
+6 -3
trace2/tr2_cfg.c
··· 100 100 * See if the given config key matches any of our patterns of interest. 101 101 */ 102 102 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) 104 104 { 105 105 struct strbuf **s; 106 106 struct tr2_cfg_data *data = (struct tr2_cfg_data *)d; ··· 109 109 struct strbuf *buf = *s; 110 110 int wm = wildmatch(buf->buf, key, WM_CASEFOLD); 111 111 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); 113 114 return 0; 114 115 } 115 116 } ··· 127 128 128 129 void tr2_list_env_vars_fl(const char *file, int line) 129 130 { 131 + struct key_value_info kvi = KVI_INIT; 130 132 struct strbuf **s; 131 133 134 + kvi_from_param(&kvi); 132 135 if (tr2_load_env_vars() <= 0) 133 136 return; 134 137 ··· 136 139 struct strbuf *buf = *s; 137 140 const char *val = getenv(buf->buf); 138 141 if (val && *val) 139 - trace2_def_param_fl(file, line, buf->buf, val); 142 + trace2_def_param_fl(file, line, buf->buf, val, &kvi); 140 143 } 141 144 } 142 145
+3 -1
trace2/tr2_tgt.h
··· 69 69 uint64_t us_elapsed_absolute, 70 70 int exec_id, int code); 71 71 72 + struct key_value_info; 72 73 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); 74 76 75 77 typedef void(tr2_tgt_evt_repo_fl_t)(const char *file, int line, 76 78 const struct repository *repo);
+2 -2
trace2/tr2_tgt_event.c
··· 477 477 } 478 478 479 479 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) 481 481 { 482 482 const char *event_name = "def_param"; 483 483 struct json_writer jw = JSON_WRITER_INIT; 484 - enum config_scope scope = current_config_scope(); 484 + enum config_scope scope = kvi->scope; 485 485 const char *scope_name = config_scope_name(scope); 486 486 487 487 jw_object_begin(&jw, 0);
+2 -2
trace2/tr2_tgt_normal.c
··· 297 297 } 298 298 299 299 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) 301 301 { 302 302 struct strbuf buf_payload = STRBUF_INIT; 303 - enum config_scope scope = current_config_scope(); 303 + enum config_scope scope = kvi->scope; 304 304 const char *scope_name = config_scope_name(scope); 305 305 306 306 strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param,
+2 -2
trace2/tr2_tgt_perf.c
··· 439 439 } 440 440 441 441 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) 443 443 { 444 444 const char *event_name = "def_param"; 445 445 struct strbuf buf_payload = STRBUF_INIT; 446 446 struct strbuf scope_payload = STRBUF_INIT; 447 - enum config_scope scope = current_config_scope(); 447 + enum config_scope scope = kvi->scope; 448 448 const char *scope_name = config_scope_name(scope); 449 449 450 450 strbuf_addf(&buf_payload, "%s:%s", param, value);