config: add '--show-scope' to print the scope of a config value
When a user queries config values with --show-origin, often it's difficult to determine what the actual "scope" (local, global, etc.) of a given value is based on just the origin file. Teach 'git config' the '--show-scope' option to print the scope of all displayed config values. Note that we should never see anything of "submodule" scope as that is only ever used by submodule-config.c when parsing the '.gitmodules' file. Signed-off-by: Matthew Rogers <mattr94@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
9a83d088ee
commit
145d59f482
@ -33,6 +33,7 @@ static int end_nul;
|
||||
static int respect_includes_opt = -1;
|
||||
static struct config_options config_options;
|
||||
static int show_origin;
|
||||
static int show_scope;
|
||||
|
||||
#define ACTION_GET (1<<0)
|
||||
#define ACTION_GET_ALL (1<<1)
|
||||
@ -155,6 +156,7 @@ static struct option builtin_config_options[] = {
|
||||
OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")),
|
||||
OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
|
||||
OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")),
|
||||
OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")),
|
||||
OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")),
|
||||
OPT_END(),
|
||||
};
|
||||
@ -189,11 +191,23 @@ static void show_config_origin(struct strbuf *buf)
|
||||
strbuf_addch(buf, term);
|
||||
}
|
||||
|
||||
static void show_config_scope(struct strbuf *buf)
|
||||
{
|
||||
const char term = end_nul ? '\0' : '\t';
|
||||
const char *scope = config_scope_name(current_config_scope());
|
||||
|
||||
strbuf_addstr(buf, N_(scope));
|
||||
strbuf_addch(buf, term);
|
||||
}
|
||||
|
||||
static int show_all_config(const char *key_, const char *value_, void *cb)
|
||||
{
|
||||
if (show_origin) {
|
||||
if (show_origin || show_scope) {
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
show_config_origin(&buf);
|
||||
if (show_scope)
|
||||
show_config_scope(&buf);
|
||||
if (show_origin)
|
||||
show_config_origin(&buf);
|
||||
/* Use fwrite as "buf" can contain \0's if "end_null" is set. */
|
||||
fwrite(buf.buf, 1, buf.len, stdout);
|
||||
strbuf_release(&buf);
|
||||
@ -213,6 +227,8 @@ struct strbuf_list {
|
||||
|
||||
static int format_config(struct strbuf *buf, const char *key_, const char *value_)
|
||||
{
|
||||
if (show_scope)
|
||||
show_config_scope(buf);
|
||||
if (show_origin)
|
||||
show_config_origin(buf);
|
||||
if (show_keys)
|
||||
|
Reference in New Issue
Block a user