Skip to content

Commit 17b3e51

Browse files
committed
Merge branch 'nd/command-list' into nd/complete-config-vars
* nd/command-list: completion: allow to customize the completable command list completion: add and use --list-cmds=alias completion: add and use --list-cmds=nohelpers Move declaration for alias.c to alias.h completion: reduce completable command list completion: let git provide the completable command list command-list.txt: documentation and guide line help: use command-list.txt for the source of guides help: add "-a --verbose" to list all commands with synopsis git: support --list-cmds=list-<category> completion: implement and use --list-cmds=main,others git --list-cmds: collect command list in a string_list git.c: convert --list-* to --list-cmds=* Remove common-cmds.h help: use command-list.h for common command list generate-cmds.sh: export all commands to command-list.h generate-cmds.sh: factor out synopsis extract code
2 parents e144d12 + 6532f37 commit 17b3e51

25 files changed

+589
-313
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
/gitweb/gitweb.cgi
183183
/gitweb/static/gitweb.js
184184
/gitweb/static/gitweb.min.*
185-
/common-cmds.h
185+
/command-list.h
186186
*.tar.gz
187187
*.dsc
188188
*.deb

Documentation/config.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,14 @@ credential.<url>.*::
13851385
credentialCache.ignoreSIGHUP::
13861386
Tell git-credential-cache--daemon to ignore SIGHUP, instead of quitting.
13871387

1388+
completion.commands::
1389+
This is only used by git-completion.bash to add or remove
1390+
commands from the list of completed commands. Normally only
1391+
porcelain commands and a few select others are completed. You
1392+
can add more commands, separated by space, in this
1393+
variable. Prefixing the command with '-' will remove it from
1394+
the existing list.
1395+
13881396
include::diff-config.txt[]
13891397

13901398
difftool.<tool>.path::

Documentation/git-help.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-help - Display help information about Git
88
SYNOPSIS
99
--------
1010
[verse]
11-
'git help' [-a|--all] [-g|--guide]
11+
'git help' [-a|--all [--verbose]] [-g|--guide]
1212
[-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE]
1313

1414
DESCRIPTION
@@ -42,6 +42,8 @@ OPTIONS
4242
--all::
4343
Prints all the available commands on the standard output. This
4444
option overrides any given command or guide name.
45+
When used with `--verbose` print description for all recognized
46+
commands.
4547

4648
-g::
4749
--guides::

Documentation/git.txt

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

167+
--list-cmds=group[,group...]::
168+
List commands by group. This is an internal/experimental
169+
option and may change or be removed in the future. Supported
170+
groups are: builtins, parseopt (builtin commands that use
171+
parse-options), main (all commands in libexec directory),
172+
others (all other commands in `$PATH` that have git- prefix),
173+
list-<category> (see categories in command-list.txt),
174+
nohelpers (exclude helper commands), alias and config
175+
(retrieve command list from config variable completion.commands)
176+
167177
GIT COMMANDS
168178
------------
169179

Documentation/gitattributes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ gitattributes(5)
33

44
NAME
55
----
6-
gitattributes - defining attributes per path
6+
gitattributes - Defining attributes per path
77

88
SYNOPSIS
99
--------

Documentation/gitmodules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ gitmodules(5)
33

44
NAME
55
----
6-
gitmodules - defining submodule properties
6+
gitmodules - Defining submodule properties
77

88
SYNOPSIS
99
--------

Documentation/gitrevisions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ gitrevisions(7)
33

44
NAME
55
----
6-
gitrevisions - specifying revisions and ranges for Git
6+
gitrevisions - Specifying revisions and ranges for Git
77

88
SYNOPSIS
99
--------

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ LIB_FILE = libgit.a
795795
XDIFF_LIB = xdiff/lib.a
796796
VCSSVN_LIB = vcs-svn/lib.a
797797

798-
GENERATED_H += common-cmds.h
798+
GENERATED_H += command-list.h
799799

800800
LIB_H = $(shell $(FIND) . \
801801
-name .git -prune -o \
@@ -2005,9 +2005,9 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
20052005
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
20062006
$(filter %.o,$^) $(LIBS)
20072007

2008-
help.sp help.s help.o: common-cmds.h
2008+
help.sp help.s help.o: command-list.h
20092009

2010-
builtin/help.sp builtin/help.s builtin/help.o: common-cmds.h GIT-PREFIX
2010+
builtin/help.sp builtin/help.s builtin/help.o: command-list.h GIT-PREFIX
20112011
builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
20122012
'-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
20132013
'-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
@@ -2026,9 +2026,9 @@ $(BUILT_INS): git$X
20262026
ln -s $< $@ 2>/dev/null || \
20272027
cp $< $@
20282028

2029-
common-cmds.h: generate-cmdlist.sh command-list.txt
2029+
command-list.h: generate-cmdlist.sh command-list.txt
20302030

2031-
common-cmds.h: $(wildcard Documentation/git-*.txt)
2031+
command-list.h: $(wildcard Documentation/git*.txt)
20322032
$(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh command-list.txt >$@+ && mv $@+ $@
20332033

20342034
SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
@@ -2272,7 +2272,7 @@ else
22722272
# Dependencies on header files, for platforms that do not support
22732273
# the gcc -MMD option.
22742274
#
2275-
# Dependencies on automatically generated headers such as common-cmds.h
2275+
# Dependencies on automatically generated headers such as command-list.h
22762276
# should _not_ be included here, since they are necessary even when
22772277
# building an object for the first time.
22782278

@@ -2652,7 +2652,7 @@ sparse: $(SP_OBJ)
26522652
style:
26532653
git clang-format --style file --diff --extensions c,h
26542654

2655-
check: common-cmds.h
2655+
check: command-list.h
26562656
@if sparse; \
26572657
then \
26582658
echo >&2 "Use 'make sparse' instead"; \
@@ -2900,7 +2900,7 @@ clean: profile-clean coverage-clean
29002900
$(RM) $(TEST_PROGRAMS) $(NO_INSTALL)
29012901
$(RM) -r bin-wrappers $(dep_dirs)
29022902
$(RM) -r po/build/
2903-
$(RM) *.pyc *.pyo */*.pyc */*.pyo common-cmds.h $(ETAGS_TARGET) tags cscope*
2903+
$(RM) *.pyc *.pyo */*.pyc */*.pyo command-list.h $(ETAGS_TARGET) tags cscope*
29042904
$(RM) -r $(GIT_TARNAME) .doc-tmp-dir
29052905
$(RM) $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
29062906
$(RM) $(htmldocs).tar.gz $(manpages).tar.gz

alias.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
#include "cache.h"
2+
#include "alias.h"
23
#include "config.h"
4+
#include "string-list.h"
35

46
struct config_alias_data {
57
const char *alias;
68
char *v;
9+
struct string_list *list;
710
};
811

912
static int config_alias_cb(const char *key, const char *value, void *d)
1013
{
1114
struct config_alias_data *data = d;
1215
const char *p;
1316

14-
if (skip_prefix(key, "alias.", &p) && !strcasecmp(p, data->alias))
15-
return git_config_string((const char **)&data->v, key, value);
17+
if (!skip_prefix(key, "alias.", &p))
18+
return 0;
19+
20+
if (data->alias) {
21+
if (!strcasecmp(p, data->alias))
22+
return git_config_string((const char **)&data->v,
23+
key, value);
24+
} else if (data->list) {
25+
string_list_append(data->list, p);
26+
}
1627

1728
return 0;
1829
}
@@ -26,6 +37,13 @@ char *alias_lookup(const char *alias)
2637
return data.v;
2738
}
2839

40+
void list_aliases(struct string_list *list)
41+
{
42+
struct config_alias_data data = { NULL, NULL, list };
43+
44+
read_early_config(config_alias_cb, &data);
45+
}
46+
2947
#define SPLIT_CMDLINE_BAD_ENDING 1
3048
#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
3149
static const char *split_cmdline_errors[] = {

alias.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __ALIAS_H__
2+
#define __ALIAS_H__
3+
4+
struct string_list;
5+
6+
char *alias_lookup(const char *alias);
7+
int split_cmdline(char *cmdline, const char ***argv);
8+
/* Takes a negative value returned by split_cmdline */
9+
const char *split_cmdline_strerror(int cmdline_errno);
10+
void list_aliases(struct string_list *list);
11+
12+
#endif

0 commit comments

Comments
 (0)