5 #define TR2_ENVVAR_CFG_PARAM "GIT_TR2_CONFIG_PARAMS"
7 static struct strbuf **tr2_cfg_patterns;
8 static int tr2_cfg_count_patterns;
9 static int tr2_cfg_loaded;
12 * Parse a string containing a comma-delimited list of config keys
13 * or wildcard patterns into a list of strbufs.
15 static int tr2_cfg_load_patterns(void)
21 return tr2_cfg_count_patterns;
24 envvar = getenv(TR2_ENVVAR_CFG_PARAM);
25 if (!envvar || !*envvar)
26 return tr2_cfg_count_patterns;
28 tr2_cfg_patterns = strbuf_split_buf(envvar, strlen(envvar), ',', -1);
29 for (s = tr2_cfg_patterns; *s; s++) {
30 struct strbuf *buf = *s;
32 if (buf->len && buf->buf[buf->len - 1] == ',')
33 strbuf_setlen(buf, buf->len - 1);
34 strbuf_trim_trailing_newline(*s);
38 tr2_cfg_count_patterns = s - tr2_cfg_patterns;
39 return tr2_cfg_count_patterns;
42 void tr2_cfg_free_patterns(void)
45 strbuf_list_free(tr2_cfg_patterns);
46 tr2_cfg_count_patterns = 0;
56 * See if the given config key matches any of our patterns of interest.
58 static int tr2_cfg_cb(const char *key, const char *value, void *d)
61 struct tr2_cfg_data *data = (struct tr2_cfg_data *)d;
63 for (s = tr2_cfg_patterns; *s; s++) {
64 struct strbuf *buf = *s;
65 int wm = wildmatch(buf->buf, key, WM_CASEFOLD);
67 trace2_def_param_fl(data->file, data->line, key, value);
75 void tr2_cfg_list_config_fl(const char *file, int line)
77 struct tr2_cfg_data data = { file, line };
79 if (tr2_cfg_load_patterns() > 0)
80 read_early_config(tr2_cfg_cb, &data);
83 void tr2_cfg_set_fl(const char *file, int line, const char *key,
86 struct tr2_cfg_data data = { file, line };
88 if (tr2_cfg_load_patterns() > 0)
89 tr2_cfg_cb(key, value, &data);