Skip to content

Commit 0089521

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 60f487a commit 0089521

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

Documentation/git.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
163163
Do not perform optional operations that require locks. This is
164164
equivalent to setting the `GIT_OPTIONAL_LOCKS` to `0`.
165165

166+
--list-cmds=group[,group...]::
167+
List commands by group. This is an internal/experimental
168+
option and may change or be removed in the future. Supported
169+
groups are: builtins, parseopt (builtin commands that use
170+
parse-options).
171+
166172
GIT COMMANDS
167173
------------
168174

contrib/completion/git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,7 @@ __git_complete_common () {
30493049
__git_cmds_with_parseopt_helper=
30503050
__git_support_parseopt_helper () {
30513051
test -n "$__git_cmds_with_parseopt_helper" ||
3052-
__git_cmds_with_parseopt_helper="$(__git --list-parseopt-builtins)"
3052+
__git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
30533053

30543054
case " $__git_cmds_with_parseopt_helper " in
30553055
*" $1 "*)

git.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ static int use_pager = -1;
3838

3939
static void list_builtins(unsigned int exclude_option, char sep);
4040

41+
static int match_token(const char *spec, int len, const char *token)
42+
{
43+
int token_len = strlen(token);
44+
45+
return len == token_len && !strncmp(spec, token, token_len);
46+
}
47+
48+
static int list_cmds(const char *spec)
49+
{
50+
while (*spec) {
51+
const char *sep = strchrnul(spec, ',');
52+
int len = sep - spec;
53+
54+
if (match_token(spec, len, "builtins"))
55+
list_builtins(0, '\n');
56+
else
57+
die(_("unsupported command listing type '%s'"), spec);
58+
spec += len;
59+
if (*spec == ',')
60+
spec++;
61+
}
62+
return 0;
63+
}
64+
4165
static void commit_pager_choice(void) {
4266
switch (use_pager) {
4367
case 0:
@@ -223,12 +247,13 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
223247
}
224248
(*argv)++;
225249
(*argc)--;
226-
} else if (!strcmp(cmd, "--list-builtins")) {
227-
list_builtins(0, '\n');
228-
exit(0);
229-
} else if (!strcmp(cmd, "--list-parseopt-builtins")) {
230-
list_builtins(NO_PARSEOPT, ' ');
231-
exit(0);
250+
} else if (skip_prefix(cmd, "--list-cmds=", &cmd)) {
251+
if (!strcmp(cmd, "parseopt")) {
252+
list_builtins(NO_PARSEOPT, ' ');
253+
exit(0);
254+
} else {
255+
exit(list_cmds(cmd));
256+
}
232257
} else {
233258
fprintf(stderr, _("unknown option: %s\n"), cmd);
234259
usage(git_usage_string);

t/t0012-help.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test_expect_success 'git help' '
5959
'
6060

6161
test_expect_success 'generate builtin list' '
62-
git --list-builtins >builtins
62+
git --list-cmds=builtins >builtins
6363
'
6464

6565
while read builtin

0 commit comments

Comments
 (0)