-
Notifications
You must be signed in to change notification settings - Fork 144
config: allow user to know scope of config options #478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
1c4faa7
2c38c72
c832293
14b0f27
1af0237
64c20d0
f619853
6c59c5c
dd37624
f76463e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ static int use_worktree_config; | |
static struct git_config_source given_config_source; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Philip Oakley wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Matt Rogers wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Matt Rogers wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Matt Rogers wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Jeff King wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
|
||
static int actions, type; | ||
static char *default_value; | ||
static int end_null; | ||
static int end_nul; | ||
static int respect_includes_opt = -1; | ||
static struct config_options config_options; | ||
static int show_origin; | ||
|
@@ -151,7 +151,7 @@ static struct option builtin_config_options[] = { | |
OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), | ||
OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE), | ||
OPT_GROUP(N_("Other")), | ||
OPT_BOOL('z', "null", &end_null, N_("terminate values with NUL byte")), | ||
OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), | ||
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)")), | ||
|
@@ -178,11 +178,11 @@ static void check_argc(int argc, int min, int max) | |
|
||
static void show_config_origin(struct strbuf *buf) | ||
{ | ||
const char term = end_null ? '\0' : '\t'; | ||
const char term = end_nul ? '\0' : '\t'; | ||
|
||
strbuf_addstr(buf, current_config_origin_type()); | ||
strbuf_addch(buf, ':'); | ||
if (end_null) | ||
if (end_nul) | ||
strbuf_addstr(buf, current_config_name()); | ||
else | ||
quote_c_style(current_config_name(), buf, NULL, 0); | ||
|
@@ -622,6 +622,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) | |
!strcmp(given_config_source.file, "-")) { | ||
given_config_source.file = NULL; | ||
given_config_source.use_stdin = 1; | ||
given_config_source.scope = CONFIG_SCOPE_COMMAND; | ||
} | ||
|
||
if (use_global_config) { | ||
|
@@ -637,6 +638,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) | |
*/ | ||
die(_("$HOME not set")); | ||
|
||
given_config_source.scope = CONFIG_SCOPE_GLOBAL; | ||
|
||
if (access_or_warn(user_config, R_OK, 0) && | ||
xdg_config && !access_or_warn(xdg_config, R_OK, 0)) { | ||
given_config_source.file = xdg_config; | ||
|
@@ -646,11 +649,13 @@ int cmd_config(int argc, const char **argv, const char *prefix) | |
free(xdg_config); | ||
} | ||
} | ||
else if (use_system_config) | ||
else if (use_system_config) { | ||
given_config_source.file = git_etc_gitconfig(); | ||
else if (use_local_config) | ||
given_config_source.scope = CONFIG_SCOPE_SYSTEM; | ||
} else if (use_local_config) { | ||
given_config_source.file = git_pathdup("config"); | ||
else if (use_worktree_config) { | ||
given_config_source.scope = CONFIG_SCOPE_LOCAL; | ||
} else if (use_worktree_config) { | ||
struct worktree **worktrees = get_worktrees(0); | ||
if (repository_format_worktree_config) | ||
given_config_source.file = git_pathdup("config.worktree"); | ||
|
@@ -662,13 +667,18 @@ int cmd_config(int argc, const char **argv, const char *prefix) | |
"section in \"git help worktree\" for details")); | ||
else | ||
given_config_source.file = git_pathdup("config"); | ||
given_config_source.scope = CONFIG_SCOPE_LOCAL; | ||
free_worktrees(worktrees); | ||
} else if (given_config_source.file) { | ||
if (!is_absolute_path(given_config_source.file) && prefix) | ||
given_config_source.file = | ||
prefix_filename(prefix, given_config_source.file); | ||
given_config_source.scope = CONFIG_SCOPE_COMMAND; | ||
} else if (given_config_source.blob) { | ||
given_config_source.scope = CONFIG_SCOPE_COMMAND; | ||
} | ||
|
||
|
||
if (respect_includes_opt == -1) | ||
config_options.respect_includes = !given_config_source.file; | ||
else | ||
|
@@ -678,7 +688,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) | |
config_options.git_dir = get_git_dir(); | ||
} | ||
|
||
if (end_null) { | ||
if (end_nul) { | ||
term = '\0'; | ||
delim = '\n'; | ||
key_delim = '\n'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1702,6 +1702,7 @@ static int do_git_config_sequence(const struct config_options *opts, | |
char *xdg_config = xdg_config_home("config"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
|
||
char *user_config = expand_user_path("~/.gitconfig", 0); | ||
char *repo_config; | ||
enum config_scope prev_parsing_scope = current_parsing_scope; | ||
|
||
if (opts->commondir) | ||
repo_config = mkpathdup("%s/config", opts->commondir); | ||
|
@@ -1724,27 +1725,24 @@ static int do_git_config_sequence(const struct config_options *opts, | |
if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Matt Rogers wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Matt Rogers wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Matt Rogers wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Matt Rogers wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
|
||
ret += git_config_from_file(fn, user_config, data); | ||
|
||
current_parsing_scope = CONFIG_SCOPE_REPO; | ||
current_parsing_scope = CONFIG_SCOPE_LOCAL; | ||
if (!opts->ignore_repo && repo_config && | ||
!access_or_die(repo_config, R_OK, 0)) | ||
ret += git_config_from_file(fn, repo_config, data); | ||
|
||
/* | ||
* Note: this should have a new scope, CONFIG_SCOPE_WORKTREE. | ||
* But let's not complicate things before it's actually needed. | ||
*/ | ||
current_parsing_scope = CONFIG_SCOPE_WORKTREE; | ||
if (!opts->ignore_worktree && repository_format_worktree_config) { | ||
char *path = git_pathdup("config.worktree"); | ||
if (!access_or_die(path, R_OK, 0)) | ||
ret += git_config_from_file(fn, path, data); | ||
free(path); | ||
} | ||
|
||
current_parsing_scope = CONFIG_SCOPE_CMDLINE; | ||
current_parsing_scope = CONFIG_SCOPE_COMMAND; | ||
if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0) | ||
die(_("unable to parse command-line config")); | ||
|
||
current_parsing_scope = CONFIG_SCOPE_UNKNOWN; | ||
current_parsing_scope = prev_parsing_scope; | ||
free(xdg_config); | ||
free(user_config); | ||
free(repo_config); | ||
|
@@ -1765,6 +1763,9 @@ int config_with_options(config_fn_t fn, void *data, | |
data = &inc; | ||
} | ||
|
||
if (config_source) | ||
current_parsing_scope = config_source->scope; | ||
|
||
/* | ||
* If we have a specific filename, use it. Otherwise, follow the | ||
* regular lookup sequence. | ||
|
@@ -3297,6 +3298,26 @@ const char *current_config_origin_type(void) | |
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Matt Rogers wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Emily Shaffer wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Matt Rogers wrote (reply to this):
|
||
} | ||
|
||
const char *config_scope_name(enum config_scope scope) | ||
{ | ||
switch (scope) { | ||
case CONFIG_SCOPE_SYSTEM: | ||
return "system"; | ||
case CONFIG_SCOPE_GLOBAL: | ||
return "global"; | ||
case CONFIG_SCOPE_LOCAL: | ||
return "local"; | ||
case CONFIG_SCOPE_WORKTREE: | ||
return "worktree"; | ||
case CONFIG_SCOPE_COMMAND: | ||
return "command"; | ||
case CONFIG_SCOPE_SUBMODULE: | ||
return "submodule"; | ||
default: | ||
return "unknown"; | ||
} | ||
} | ||
|
||
const char *current_config_name(void) | ||
{ | ||
const char *name; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Jeff King wrote (reply to this):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Junio C Hamano wrote (reply to this):