Skip to content

Commit 2289880

Browse files
committed
Merge branch 'nd/command-list'
The list of commands with their various attributes were spread across a few places in the build procedure, but it now is getting a bit more consolidated to allow more automation. * 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 2161ed8 + 6532f37 commit 2289880

25 files changed

+589
-313
lines changed

.gitignore

+1-1
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

+8
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,14 @@ credential.<url>.*::
14121412
credentialCache.ignoreSIGHUP::
14131413
Tell git-credential-cache--daemon to ignore SIGHUP, instead of quitting.
14141414

1415+
completion.commands::
1416+
This is only used by git-completion.bash to add or remove
1417+
commands from the list of completed commands. Normally only
1418+
porcelain commands and a few select others are completed. You
1419+
can add more commands, separated by space, in this
1420+
variable. Prefixing the command with '-' will remove it from
1421+
the existing list.
1422+
14151423
include::diff-config.txt[]
14161424

14171425
difftool.<tool>.path::

Documentation/git-help.txt

+3-1
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

+10
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

+1-1
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

+1-1
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

+1-1
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

+8-8
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 \
@@ -2006,9 +2006,9 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
20062006
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
20072007
$(filter %.o,$^) $(LIBS)
20082008

2009-
help.sp help.s help.o: common-cmds.h
2009+
help.sp help.s help.o: command-list.h
20102010

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

2030-
common-cmds.h: generate-cmdlist.sh command-list.txt
2030+
command-list.h: generate-cmdlist.sh command-list.txt
20312031

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

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

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

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

alias.c

+20-2
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

+12
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

builtin/help.c

+8-32
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "run-command.h"
1010
#include "column.h"
1111
#include "help.h"
12+
#include "alias.h"
1213

1314
#ifndef DEFAULT_HELP_FORMAT
1415
#define DEFAULT_HELP_FORMAT "man"
@@ -36,6 +37,7 @@ static const char *html_path;
3637

3738
static int show_all = 0;
3839
static int show_guides = 0;
40+
static int verbose;
3941
static unsigned int colopts;
4042
static enum help_format help_format = HELP_FORMAT_NONE;
4143
static int exclude_guides;
@@ -48,6 +50,7 @@ static struct option builtin_help_options[] = {
4850
HELP_FORMAT_WEB),
4951
OPT_SET_INT('i', "info", &help_format, N_("show info page"),
5052
HELP_FORMAT_INFO),
53+
OPT__VERBOSE(&verbose, N_("print command description")),
5154
OPT_END(),
5255
};
5356

@@ -400,38 +403,6 @@ static void show_html_page(const char *git_cmd)
400403
open_html(page_path.buf);
401404
}
402405

403-
static struct {
404-
const char *name;
405-
const char *help;
406-
} common_guides[] = {
407-
{ "attributes", N_("Defining attributes per path") },
408-
{ "everyday", N_("Everyday Git With 20 Commands Or So") },
409-
{ "glossary", N_("A Git glossary") },
410-
{ "ignore", N_("Specifies intentionally untracked files to ignore") },
411-
{ "modules", N_("Defining submodule properties") },
412-
{ "revisions", N_("Specifying revisions and ranges for Git") },
413-
{ "tutorial", N_("A tutorial introduction to Git (for version 1.5.1 or newer)") },
414-
{ "workflows", N_("An overview of recommended workflows with Git") },
415-
};
416-
417-
static void list_common_guides_help(void)
418-
{
419-
int i, longest = 0;
420-
421-
for (i = 0; i < ARRAY_SIZE(common_guides); i++) {
422-
if (longest < strlen(common_guides[i].name))
423-
longest = strlen(common_guides[i].name);
424-
}
425-
426-
puts(_("The common Git guides are:\n"));
427-
for (i = 0; i < ARRAY_SIZE(common_guides); i++) {
428-
printf(" %s ", common_guides[i].name);
429-
mput_char(' ', longest - strlen(common_guides[i].name));
430-
puts(_(common_guides[i].help));
431-
}
432-
putchar('\n');
433-
}
434-
435406
static const char *check_git_cmd(const char* cmd)
436407
{
437408
char *alias;
@@ -463,6 +434,11 @@ int cmd_help(int argc, const char **argv, const char *prefix)
463434

464435
if (show_all) {
465436
git_config(git_help_config, NULL);
437+
if (verbose) {
438+
setup_pager();
439+
list_all_cmds_help();
440+
return 0;
441+
}
466442
printf(_("usage: %s%s"), _(git_usage_string), "\n\n");
467443
load_command_list("git-", &main_cmds, &other_cmds);
468444
list_commands(colopts, &main_cmds, &other_cmds);

builtin/merge.c

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "string-list.h"
3636
#include "packfile.h"
3737
#include "tag.h"
38+
#include "alias.h"
3839

3940
#define DEFAULT_TWOHEAD (1<<0)
4041
#define DEFAULT_OCTOPUS (1<<1)

cache.h

-5
Original file line numberDiff line numberDiff line change
@@ -1826,11 +1826,6 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule);
18261826
void overlay_tree_on_index(struct index_state *istate,
18271827
const char *tree_name, const char *prefix);
18281828

1829-
char *alias_lookup(const char *alias);
1830-
int split_cmdline(char *cmdline, const char ***argv);
1831-
/* Takes a negative value returned by split_cmdline */
1832-
const char *split_cmdline_strerror(int cmdline_errno);
1833-
18341829
/* setup.c */
18351830
struct startup_info {
18361831
int have_repository;

0 commit comments

Comments
 (0)