summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-05-20 18:39:57 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-05-21 04:23:13 (GMT)
commit0089521cacd99db8018b7a31e205dad0bf0738c7 (patch)
treeea4ccff30a1bd8081885d78d933729a77bfa0759 /git.c
parent60f487ac0ef1165932211ede29ea661c79984b16 (diff)
downloadgit-0089521cacd99db8018b7a31e205dad0bf0738c7.zip
git-0089521cacd99db8018b7a31e205dad0bf0738c7.tar.gz
git-0089521cacd99db8018b7a31e205dad0bf0738c7.tar.bz2
git.c: convert --list-* to --list-cmds=*
Even if these are hidden options, let's make them a bit more generic since we're introducing more listing types shortly. The code is structured to allow combining multiple listing types together because we will soon add more types the 'builtins'. 'parseopt' remains separate because it has separate (SPC) to match git-completion.bash needs and will not combine with others. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git.c')
-rw-r--r--git.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/git.c b/git.c
index 3a89893..cd85355 100644
--- a/git.c
+++ b/git.c
@@ -38,6 +38,30 @@ static int use_pager = -1;
static void list_builtins(unsigned int exclude_option, char sep);
+static int match_token(const char *spec, int len, const char *token)
+{
+ int token_len = strlen(token);
+
+ return len == token_len && !strncmp(spec, token, token_len);
+}
+
+static int list_cmds(const char *spec)
+{
+ while (*spec) {
+ const char *sep = strchrnul(spec, ',');
+ int len = sep - spec;
+
+ if (match_token(spec, len, "builtins"))
+ list_builtins(0, '\n');
+ else
+ die(_("unsupported command listing type '%s'"), spec);
+ spec += len;
+ if (*spec == ',')
+ spec++;
+ }
+ return 0;
+}
+
static void commit_pager_choice(void) {
switch (use_pager) {
case 0:
@@ -223,12 +247,13 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
}
(*argv)++;
(*argc)--;
- } else if (!strcmp(cmd, "--list-builtins")) {
- list_builtins(0, '\n');
- exit(0);
- } else if (!strcmp(cmd, "--list-parseopt-builtins")) {
- list_builtins(NO_PARSEOPT, ' ');
- exit(0);
+ } else if (skip_prefix(cmd, "--list-cmds=", &cmd)) {
+ if (!strcmp(cmd, "parseopt")) {
+ list_builtins(NO_PARSEOPT, ' ');
+ exit(0);
+ } else {
+ exit(list_cmds(cmd));
+ }
} else {
fprintf(stderr, _("unknown option: %s\n"), cmd);
usage(git_usage_string);