Skip to content

Commit 7d5387e

Browse files
pks-tgitster
authored andcommitted
builtin/config: move legacy options into cmd_config()
Move the legacy options as well some of the variables it references into `cmd_config_action()`. This reduces our reliance on global state. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8b908f9 commit 7d5387e

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

builtin/config.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,14 @@ static char term = '\n';
7878
static int use_global_config, use_system_config, use_local_config;
7979
static int use_worktree_config;
8080
static struct git_config_source given_config_source;
81-
static int actions, type;
81+
static int type;
8282
static char *default_value;
8383
static int end_nul;
8484
static int respect_includes_opt = -1;
8585
static struct config_options config_options;
8686
static int show_origin;
8787
static int show_scope;
8888
static int fixed_value;
89-
static const char *comment_arg;
9089

9190
#define ACTION_GET (1<<0)
9291
#define ACTION_GET_ALL (1<<1)
@@ -772,33 +771,6 @@ static void handle_nul(void) {
772771
OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), \
773772
OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)"))
774773

775-
static struct option builtin_config_options[] = {
776-
CONFIG_LOCATION_OPTIONS,
777-
OPT_GROUP(N_("Action")),
778-
OPT_CMDMODE(0, "get", &actions, N_("get value: name [<value-pattern>]"), ACTION_GET),
779-
OPT_CMDMODE(0, "get-all", &actions, N_("get all values: key [<value-pattern>]"), ACTION_GET_ALL),
780-
OPT_CMDMODE(0, "get-regexp", &actions, N_("get values for regexp: name-regex [<value-pattern>]"), ACTION_GET_REGEXP),
781-
OPT_CMDMODE(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH),
782-
OPT_CMDMODE(0, "replace-all", &actions, N_("replace all matching variables: name value [<value-pattern>]"), ACTION_REPLACE_ALL),
783-
OPT_CMDMODE(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD),
784-
OPT_CMDMODE(0, "unset", &actions, N_("remove a variable: name [<value-pattern>]"), ACTION_UNSET),
785-
OPT_CMDMODE(0, "unset-all", &actions, N_("remove all matches: name [<value-pattern>]"), ACTION_UNSET_ALL),
786-
OPT_CMDMODE(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION),
787-
OPT_CMDMODE(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION),
788-
OPT_CMDMODE('l', "list", &actions, N_("list all"), ACTION_LIST),
789-
OPT_CMDMODE('e', "edit", &actions, N_("open an editor"), ACTION_EDIT),
790-
OPT_CMDMODE(0, "get-color", &actions, N_("find the color configured: slot [<default>]"), ACTION_GET_COLOR),
791-
OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot [<stdout-is-tty>]"), ACTION_GET_COLORBOOL),
792-
CONFIG_TYPE_OPTIONS,
793-
CONFIG_DISPLAY_OPTIONS,
794-
OPT_GROUP(N_("Other")),
795-
OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")),
796-
OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")),
797-
OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")),
798-
OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
799-
OPT_END(),
800-
};
801-
802774
static int cmd_config_list(int argc, const char **argv, const char *prefix)
803775
{
804776
struct option opts[] = {
@@ -1059,12 +1031,40 @@ static int cmd_config_edit(int argc, const char **argv, const char *prefix)
10591031

10601032
static int cmd_config_actions(int argc, const char **argv, const char *prefix)
10611033
{
1034+
const char *comment_arg = NULL;
1035+
int actions = 0;
1036+
struct option opts[] = {
1037+
CONFIG_LOCATION_OPTIONS,
1038+
OPT_GROUP(N_("Action")),
1039+
OPT_CMDMODE(0, "get", &actions, N_("get value: name [<value-pattern>]"), ACTION_GET),
1040+
OPT_CMDMODE(0, "get-all", &actions, N_("get all values: key [<value-pattern>]"), ACTION_GET_ALL),
1041+
OPT_CMDMODE(0, "get-regexp", &actions, N_("get values for regexp: name-regex [<value-pattern>]"), ACTION_GET_REGEXP),
1042+
OPT_CMDMODE(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH),
1043+
OPT_CMDMODE(0, "replace-all", &actions, N_("replace all matching variables: name value [<value-pattern>]"), ACTION_REPLACE_ALL),
1044+
OPT_CMDMODE(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD),
1045+
OPT_CMDMODE(0, "unset", &actions, N_("remove a variable: name [<value-pattern>]"), ACTION_UNSET),
1046+
OPT_CMDMODE(0, "unset-all", &actions, N_("remove all matches: name [<value-pattern>]"), ACTION_UNSET_ALL),
1047+
OPT_CMDMODE(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION),
1048+
OPT_CMDMODE(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION),
1049+
OPT_CMDMODE('l', "list", &actions, N_("list all"), ACTION_LIST),
1050+
OPT_CMDMODE('e', "edit", &actions, N_("open an editor"), ACTION_EDIT),
1051+
OPT_CMDMODE(0, "get-color", &actions, N_("find the color configured: slot [<default>]"), ACTION_GET_COLOR),
1052+
OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot [<stdout-is-tty>]"), ACTION_GET_COLORBOOL),
1053+
CONFIG_TYPE_OPTIONS,
1054+
CONFIG_DISPLAY_OPTIONS,
1055+
OPT_GROUP(N_("Other")),
1056+
OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")),
1057+
OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")),
1058+
OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")),
1059+
OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
1060+
OPT_END(),
1061+
};
10621062
char *value = NULL, *comment = NULL;
10631063
int flags = 0;
10641064
int ret = 0;
10651065
struct key_value_info default_kvi = KVI_INIT;
10661066

1067-
argc = parse_options(argc, argv, prefix, builtin_config_options,
1067+
argc = parse_options(argc, argv, prefix, opts,
10681068
builtin_config_usage,
10691069
PARSE_OPT_STOP_AT_NON_OPTION);
10701070

0 commit comments

Comments
 (0)