Hi, were there any attempts to implement printing all recognized config options? Simplest method seems to be to manually ask all commands to print their known options. Not very nice, easy to forget about adding option etc. But the alternative requires some kind of formalized registration of options, similar to command line arguments. Not that it's a bad thing, just requires much bigger rewrite IMO. Ultimately I think it'd be nice to have a short description of an option too. What do you think about this and what kind of approach would be acceptable? Attached patch is just an example. Adds "--list-all": $ ./git config --list-all Listing all configs [core] filemode = 1 trustctime = 1 quotepath = 1 symlinks = 1 ignorecase = 0 abbrevguard = 0 bare = 0 ignorestat = 0 prefersymlinkrefs = 0 [advice] pushnonfastforward = 1 statushints = 1 commitbeforemerge = 1 resolveconflict = 1 implicitidentity = 1 detachedhead = 1 From: Piotr Krukowiecki <piotr.krukowiecki@xxxxxxxxx> Date: Wed, 16 Feb 2011 21:55:10 +0100 Subject: [PATCH] Call functions to print config values --- advice.c | 9 +++++++++ advice.h | 1 + builtin/config.c | 7 +++++++ cache.h | 1 + config.c | 27 +++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 0 deletions(-) diff --git a/advice.c b/advice.c index 0be4b5f..c077fc5 100644 --- a/advice.c +++ b/advice.c @@ -19,6 +19,15 @@ static struct { { "detachedhead", &advice_detached_head }, }; +void git_advice_config_list_defaults(void) +{ + int i; + printf("[advice]\n"); + for (i = 0; i < ARRAY_SIZE(advice_config); i++) { + printf("\t%s\t= %d\n", advice_config[i].name, *advice_config[i].preference); + } +} + int git_default_advice_config(const char *var, const char *value) { const char *k = skip_prefix(var, "advice."); diff --git a/advice.h b/advice.h index 3244ebb..890f342 100644 --- a/advice.h +++ b/advice.h @@ -10,6 +10,7 @@ extern int advice_resolve_conflict; extern int advice_implicit_identity; extern int advice_detached_head; +void git_advice_config_list_defaults(void); int git_default_advice_config(const char *var, const char *value); extern void NORETURN die_resolve_conflict(const char *me); diff --git a/builtin/config.c b/builtin/config.c index dad86fe..b0bb84d 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -41,6 +41,7 @@ static int end_null; #define ACTION_SET_ALL (1<<12) #define ACTION_GET_COLOR (1<<13) #define ACTION_GET_COLORBOOL (1<<14) +#define ACTION_LIST_ALL (1<<15) #define TYPE_BOOL (1<<0) #define TYPE_INT (1<<1) @@ -64,6 +65,7 @@ static struct option builtin_config_options[] = { OPT_BIT(0, "rename-section", &actions, "rename section: old-name new-name", ACTION_RENAME_SECTION), OPT_BIT(0, "remove-section", &actions, "remove a section: name", ACTION_REMOVE_SECTION), OPT_BIT('l', "list", &actions, "list all", ACTION_LIST), + OPT_BIT(0, "list-all", &actions, "list all registered options", ACTION_LIST_ALL), OPT_BIT('e', "edit", &actions, "opens an editor", ACTION_EDIT), OPT_STRING(0, "get-color", &get_color_slot, "slot", "find the color configured: [default]"), OPT_STRING(0, "get-colorbool", &get_colorbool_slot, "slot", "find the color setting: [stdout-is-tty]"), @@ -413,6 +415,11 @@ int cmd_config(int argc, const char **argv, const char *prefix) die("error processing config file(s)"); } } + else if (actions == ACTION_LIST_ALL) { + check_argc(argc, 0, 0); + printf("Listing all configs\n"); + git_config_list_defaults(); + } else if (actions == ACTION_EDIT) { check_argc(argc, 0, 0); if (!config_exclusive_filename && nongit) diff --git a/cache.h b/cache.h index 3abf895..8b9716a 100644 --- a/cache.h +++ b/cache.h @@ -983,6 +983,7 @@ extern int update_server_info(int); typedef int (*config_fn_t)(const char *, const char *, void *); extern int git_default_config(const char *, const char *, void *); +extern void git_config_list_defaults(void); extern int git_config_from_file(config_fn_t fn, const char *, void *); extern void git_config_push_parameter(const char *text); extern int git_config_parse_parameter(const char *text); diff --git a/config.c b/config.c index 625e051..13ab03a 100644 --- a/config.c +++ b/config.c @@ -472,6 +472,23 @@ int git_config_pathname(const char **dest, const char *var, const char *value) return 0; } +static void git_core_config_list_defaults(void) +{ +#define PRINT_CONFIG_INT(name, var) printf("\t%s\t= %d\n", #name, var); + printf("[core]\n"); + PRINT_CONFIG_INT(filemode, trust_executable_bit); + PRINT_CONFIG_INT(trustctime, trust_ctime); + PRINT_CONFIG_INT(quotepath, quote_path_fully); + PRINT_CONFIG_INT(symlinks, has_symlinks); + PRINT_CONFIG_INT(ignorecase, ignore_case); + PRINT_CONFIG_INT(abbrevguard, unique_abbrev_extra_length); + PRINT_CONFIG_INT(bare, is_bare_repository_cfg); + PRINT_CONFIG_INT(ignorestat, assume_unchanged); + PRINT_CONFIG_INT(prefersymlinkrefs, prefer_symlink_refs); + /* Other from git_default_core_config() should follow */ +#undef PRINT_CONFIG_INT +} + static int git_default_core_config(const char *var, const char *value) { /* This needs a better name */ @@ -762,6 +779,16 @@ static int git_default_mailmap_config(const char *var, const char *value) return 0; } +void git_config_list_defaults(void) +{ + git_core_config_list_defaults(); + git_advice_config_list_defaults(); + /* core.gitproxy set in git_proxy_command_options in connect.c */ + /* branch.* set in git_default_branch_config in config.c and git_branch_config() in branch.c */ + /* color.branch.<nr> */ + /* What about branch.<name>.mergeoptions (merge.c::git_merge_config) etc? */ +} + int git_default_config(const char *var, const char *value, void *dummy) { if (!prefixcmp(var, "core.")) -- 1.7.1 -- Piotrek -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html