{"thread":{"id":"41307","subject":"[RFC] Identify where a Git config is defined","startedAt":"2016-02-02T09:27:06Z","lastAt":"2016-02-02T10:32:16Z","messageCount":3,"participants":["Lars Schneider","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"277216","messageId":"3226E251-73F9-4410-84DE-49C8FFAD92EB@gmail.com","threadId":"41307","inReplyTo":null,"subject":"[RFC] Identify where a Git config is defined","fromName":"Lars Schneider","fromEmail":"larsxschneider@gmail.com","sentAt":"2016-02-02T09:27:06Z","receivedAt":"2016-02-02T09:27:06Z","isPatch":false,"sender":{"key":"larsxschneider@gmail.com","avatar":"https://avatars.githubusercontent.com/u/477434?v=4"},"body":"Hi,\n\nUsing \"git config --list\" shows me all configs but sometimes I have a hard time to figure out where a certain config is defined. This is especially true on Windows as I found the system config in various places. I wonder if other people would find it useful to enable something like \"git config --list --print-source\" where every config value is printed with the file where it originates from.\n\nIf I read the source correctly this would mean I would need to change \"config_fn_t\" to pass not only key and value but also the config source file in addition. Since \"config_fn_t\" is used in many places this would be a big change that probably is not worth the effort?!\n\nAlternatively I was thinking about \"git config --print-source-files\" to print all config files that Git would parse. This would already help to find the configs and would probably be a smaller change.\n\nThoughts?\n\nThanks,\nLars"},{"id":"277217","messageId":"20160202101551.GA17349@sigill.intra.peff.net","threadId":"41307","inReplyTo":"3226E251-73F9-4410-84DE-49C8FFAD92EB@gmail.com","subject":"Re: [RFC] Identify where a Git config is defined","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-02-02T10:15:51Z","receivedAt":"2016-02-02T10:15:51Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Feb 02, 2016 at 10:27:06AM +0100, Lars Schneider wrote:\n\n> Using \"git config --list\" shows me all configs but sometimes I have a\n> hard time to figure out where a certain config is defined. This is\n> especially true on Windows as I found the system config in various\n> places. I wonder if other people would find it useful to enable\n> something like \"git config --list --print-source\" where every config\n> value is printed with the file where it originates from.\n\nWe discussed this exact thing a while ago, and it looks like I started\non a patch, but didn't pursue it much further. There's some discussion\nin there if you are interested in designing such a feature:\n\n  http://thread.gmane.org/gmane.comp.version-control.git/190027/focus=190267\n\nIt looks like I tweaked it at some point, and I've been carrying this in\nmy tree (rebasing forward and using it in my normal build):\n\n  git fetch git://github.com/peff/git jk/config-sources\n\nFeel free to use it as a starting point if that's helpful. I don't\nrecall offhand how close it is to ready.\n\n> If I read the source correctly this would mean I would need to change\n> \"config_fn_t\" to pass not only key and value but also the config\n> source file in addition. Since \"config_fn_t\" is used in many places\n> this would be a big change that probably is not worth the effort?!\n\nThere's a global struct for the current config file.  In the patches\nabove, I just added an accessor function. Hooray for single-threaded\nprograms.\n\n> Alternatively I was thinking about \"git config --print-source-files\"\n> to print all config files that Git would parse. This would already\n> help to find the configs and would probably be a smaller change.\n\nI think the \"--sources\" option is more useful, because it can show\nincluded files, too.\n\n-Peff\n"},{"id":"277219","messageId":"20160202103215.GA18074@sigill.intra.peff.net","threadId":"41307","inReplyTo":"20160202101551.GA17349@sigill.intra.peff.net","subject":"Re: [RFC] Identify where a Git config is defined","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-02-02T10:32:16Z","receivedAt":"2016-02-02T10:32:16Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Feb 02, 2016 at 05:15:51AM -0500, Jeff King wrote:\n\n> It looks like I tweaked it at some point, and I've been carrying this in\n> my tree (rebasing forward and using it in my normal build):\n> \n>   git fetch git://github.com/peff/git jk/config-sources\n> \n> Feel free to use it as a starting point if that's helpful. I don't\n> recall offhand how close it is to ready.\n\nJust to leave a record in the list archive, here's the patch itself:\n\n-- >8 --\nSubject: [PATCH] show sources of config options (WIP)\n\n - needs tests\n - probably should complain when not LIST or getting a value\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n builtin/config.c | 32 ++++++++++++++++++++++++++++++++\n cache.h          |  1 +\n config.c         |  7 +++++++\n 3 files changed, 40 insertions(+)\n\ndiff --git a/builtin/config.c b/builtin/config.c\nindex adc7727..b8caf18 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -3,6 +3,7 @@\n #include \"color.h\"\n #include \"parse-options.h\"\n #include \"urlmatch.h\"\n+#include \"quote.h\"\n \n static const char *const builtin_config_usage[] = {\n \tN_(\"git config [<options>]\"),\n@@ -27,6 +28,7 @@ static int actions, types;\n static const char *get_color_slot, *get_colorbool_slot;\n static int end_null;\n static int respect_includes = -1;\n+static int show_sources;\n \n #define ACTION_GET (1<<0)\n #define ACTION_GET_ALL (1<<1)\n@@ -81,6 +83,7 @@ static struct option builtin_config_options[] = {\n \tOPT_BOOL('z', \"null\", &end_null, N_(\"terminate values with NUL byte\")),\n \tOPT_BOOL(0, \"name-only\", &omit_values, N_(\"show variable names only\")),\n \tOPT_BOOL(0, \"includes\", &respect_includes, N_(\"respect include directives on lookup\")),\n+\tOPT_BOOL(0, \"sources\", &show_sources, N_(\"show source filenames of config\")),\n \tOPT_END(),\n };\n \n@@ -91,8 +94,35 @@ static void check_argc(int argc, int min, int max) {\n \tusage_with_options(builtin_config_usage, builtin_config_options);\n }\n \n+/* output to either fp or buf; only one should be non-NULL */\n+static void show_config_source(struct strbuf *buf, FILE *fp)\n+{\n+\tchar term = '\\t';\n+\tconst char *fn = current_config_filename();\n+\n+\tif (!fn)\n+\t\tfn = \"\";\n+\n+\tif (!end_null)\n+\t\tquote_c_style(fn, buf, fp, 0);\n+\telse {\n+\t\tterm = '\\0';\n+\t\tif (fp)\n+\t\t\tfprintf(fp, \"%s\", fn);\n+\t\telse\n+\t\t\tstrbuf_addstr(buf, fn);\n+\t}\n+\n+\tif (fp)\n+\t\tfputc(term, fp);\n+\telse\n+\t\tstrbuf_addch(buf, term);\n+}\n+\n static int show_all_config(const char *key_, const char *value_, void *cb)\n {\n+\tif (show_sources)\n+\t\tshow_config_source(NULL, stdout);\n \tif (!omit_values && value_)\n \t\tprintf(\"%s%c%s%c\", key_, delim, value_, term);\n \telse\n@@ -108,6 +138,8 @@ struct strbuf_list {\n \n static int format_config(struct strbuf *buf, const char *key_, const char *value_)\n {\n+\tif (show_sources)\n+\t\tshow_config_source(buf, NULL);\n \tif (show_keys)\n \t\tstrbuf_addstr(buf, key_);\n \tif (!omit_values) {\ndiff --git a/cache.h b/cache.h\nindex dfc459c..95a7f65 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1528,6 +1528,7 @@ extern const char *get_log_output_encoding(void);\n extern const char *get_commit_output_encoding(void);\n \n extern int git_config_parse_parameter(const char *, config_fn_t fn, void *data);\n+extern const char *current_config_filename(void);\n \n struct config_include_data {\n \tint depth;\ndiff --git a/config.c b/config.c\nindex 86a5eb2..b437002 100644\n--- a/config.c\n+++ b/config.c\n@@ -2385,3 +2385,10 @@ int parse_config_key(const char *var,\n \n \treturn 0;\n }\n+\n+const char *current_config_filename(void)\n+{\n+\tif (cf && cf->name)\n+\t\treturn cf->name;\n+\treturn NULL;\n+}\n-- \n2.7.0.489.g6faad84\n"}]}