diff options
author | Jeff King <peff@peff.net> | 2016-05-26 20:32:23 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-05-27 10:44:54 -0700 |
commit | 0d44a2dacc84fb7dcb5d684800e976f3b3c76d00 (patch) | |
tree | 2e66639973179ad660efd496b83eb328bd3a20de /t/helper/test-config.c | |
parent | config: set up config_source for command-line config (diff) | |
download | tgif-0d44a2dacc84fb7dcb5d684800e976f3b3c76d00.tar.xz |
config: return configset value for current_config_ functions
When 473166b (config: add 'origin_type' to config_source
struct, 2016-02-19) added accessor functions for the origin
type and name, it taught them only to look at the "cf"
struct that is filled in while we are parsing the config.
This is sufficient to make it work with git-config, which
uses git_config_with_options() under the hood. That function
freshly parses the config files and triggers the callback
when it parses each key.
Most git programs, however, use git_config(). This interface
will populate a cache during the actual parse, and then
serve values from the cache. Calling current_config_filename()
in a callback here will find a NULL cf and produce an error.
There are no such callers right now, but let's prepare for
adding some by making this work.
We already record source information in a struct attached to
each value. We just need to make it globally available and
then consult it from the accessor functions.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/helper/test-config.c')
-rw-r--r-- | t/helper/test-config.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 6a77552210..3605ef8ee6 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -25,6 +25,9 @@ * ascending order of priority from a config_set * constructed from files entered as arguments. * + * iterate -> iterate over all values using git_config(), and print some + * data for each + * * Examples: * * To print the value with highest priority for key "foo.bAr Baz.rock": @@ -32,6 +35,20 @@ * */ +static int iterate_cb(const char *var, const char *value, void *data) +{ + static int nr; + + if (nr++) + putchar('\n'); + + printf("key=%s\n", var); + printf("value=%s\n", value ? value : "(null)"); + printf("origin=%s\n", current_config_origin_type()); + printf("name=%s\n", current_config_name()); + + return 0; +} int main(int argc, char **argv) { @@ -134,6 +151,9 @@ int main(int argc, char **argv) printf("Value not found for \"%s\"\n", argv[2]); goto exit1; } + } else if (!strcmp(argv[1], "iterate")) { + git_config(iterate_cb, NULL); + goto exit0; } die("%s: Please check the syntax and the function name", argv[0]); |