Skip to content

Commit

Permalink
Merge branch 'nd/command-list'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Jun 1, 2018
2 parents 2161ed8 + 6532f37 commit 2289880
Show file tree
Hide file tree
Showing 25 changed files with 589 additions and 313 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
/gitweb/gitweb.cgi
/gitweb/static/gitweb.js
/gitweb/static/gitweb.min.*
/common-cmds.h
/command-list.h
*.tar.gz
*.dsc
*.deb
Expand Down
8 changes: 8 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,14 @@ credential.<url>.*::
credentialCache.ignoreSIGHUP::
Tell git-credential-cache--daemon to ignore SIGHUP, instead of quitting.

completion.commands::
This is only used by git-completion.bash to add or remove
commands from the list of completed commands. Normally only
porcelain commands and a few select others are completed. You
can add more commands, separated by space, in this
variable. Prefixing the command with '-' will remove it from
the existing list.

include::diff-config.txt[]

difftool.<tool>.path::
Expand Down
4 changes: 3 additions & 1 deletion Documentation/git-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ git-help - Display help information about Git
SYNOPSIS
--------
[verse]
'git help' [-a|--all] [-g|--guide]
'git help' [-a|--all [--verbose]] [-g|--guide]
[-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE]

DESCRIPTION
Expand Down Expand Up @@ -42,6 +42,8 @@ OPTIONS
--all::
Prints all the available commands on the standard output. This
option overrides any given command or guide name.
When used with `--verbose` print description for all recognized
commands.

-g::
--guides::
Expand Down
10 changes: 10 additions & 0 deletions Documentation/git.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
Do not perform optional operations that require locks. This is
equivalent to setting the `GIT_OPTIONAL_LOCKS` to `0`.

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

GIT COMMANDS
------------

Expand Down
2 changes: 1 addition & 1 deletion Documentation/gitattributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ gitattributes(5)

NAME
----
gitattributes - defining attributes per path
gitattributes - Defining attributes per path

SYNOPSIS
--------
Expand Down
2 changes: 1 addition & 1 deletion Documentation/gitmodules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ gitmodules(5)

NAME
----
gitmodules - defining submodule properties
gitmodules - Defining submodule properties

SYNOPSIS
--------
Expand Down
2 changes: 1 addition & 1 deletion Documentation/gitrevisions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ gitrevisions(7)

NAME
----
gitrevisions - specifying revisions and ranges for Git
gitrevisions - Specifying revisions and ranges for Git

SYNOPSIS
--------
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ LIB_FILE = libgit.a
XDIFF_LIB = xdiff/lib.a
VCSSVN_LIB = vcs-svn/lib.a

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

LIB_H = $(shell $(FIND) . \
-name .git -prune -o \
Expand Down Expand Up @@ -2006,9 +2006,9 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
$(filter %.o,$^) $(LIBS)

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

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

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

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

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

Expand Down Expand Up @@ -2653,7 +2653,7 @@ sparse: $(SP_OBJ)
style:
git clang-format --style file --diff --extensions c,h

check: common-cmds.h
check: command-list.h
@if sparse; \
then \
echo >&2 "Use 'make sparse' instead"; \
Expand Down Expand Up @@ -2901,7 +2901,7 @@ clean: profile-clean coverage-clean
$(RM) $(TEST_PROGRAMS) $(NO_INSTALL)
$(RM) -r bin-wrappers $(dep_dirs)
$(RM) -r po/build/
$(RM) *.pyc *.pyo */*.pyc */*.pyo common-cmds.h $(ETAGS_TARGET) tags cscope*
$(RM) *.pyc *.pyo */*.pyc */*.pyo command-list.h $(ETAGS_TARGET) tags cscope*
$(RM) -r $(GIT_TARNAME) .doc-tmp-dir
$(RM) $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
$(RM) $(htmldocs).tar.gz $(manpages).tar.gz
Expand Down
22 changes: 20 additions & 2 deletions alias.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
#include "cache.h"
#include "alias.h"
#include "config.h"
#include "string-list.h"

struct config_alias_data {
const char *alias;
char *v;
struct string_list *list;
};

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

if (skip_prefix(key, "alias.", &p) && !strcasecmp(p, data->alias))
return git_config_string((const char **)&data->v, key, value);
if (!skip_prefix(key, "alias.", &p))
return 0;

if (data->alias) {
if (!strcasecmp(p, data->alias))
return git_config_string((const char **)&data->v,
key, value);
} else if (data->list) {
string_list_append(data->list, p);
}

return 0;
}
Expand All @@ -26,6 +37,13 @@ char *alias_lookup(const char *alias)
return data.v;
}

void list_aliases(struct string_list *list)
{
struct config_alias_data data = { NULL, NULL, list };

read_early_config(config_alias_cb, &data);
}

#define SPLIT_CMDLINE_BAD_ENDING 1
#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
static const char *split_cmdline_errors[] = {
Expand Down
12 changes: 12 additions & 0 deletions alias.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __ALIAS_H__
#define __ALIAS_H__

struct string_list;

char *alias_lookup(const char *alias);
int split_cmdline(char *cmdline, const char ***argv);
/* Takes a negative value returned by split_cmdline */
const char *split_cmdline_strerror(int cmdline_errno);
void list_aliases(struct string_list *list);

#endif
40 changes: 8 additions & 32 deletions builtin/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "run-command.h"
#include "column.h"
#include "help.h"
#include "alias.h"

#ifndef DEFAULT_HELP_FORMAT
#define DEFAULT_HELP_FORMAT "man"
Expand Down Expand Up @@ -36,6 +37,7 @@ static const char *html_path;

static int show_all = 0;
static int show_guides = 0;
static int verbose;
static unsigned int colopts;
static enum help_format help_format = HELP_FORMAT_NONE;
static int exclude_guides;
Expand All @@ -48,6 +50,7 @@ static struct option builtin_help_options[] = {
HELP_FORMAT_WEB),
OPT_SET_INT('i', "info", &help_format, N_("show info page"),
HELP_FORMAT_INFO),
OPT__VERBOSE(&verbose, N_("print command description")),
OPT_END(),
};

Expand Down Expand Up @@ -400,38 +403,6 @@ static void show_html_page(const char *git_cmd)
open_html(page_path.buf);
}

static struct {
const char *name;
const char *help;
} common_guides[] = {
{ "attributes", N_("Defining attributes per path") },
{ "everyday", N_("Everyday Git With 20 Commands Or So") },
{ "glossary", N_("A Git glossary") },
{ "ignore", N_("Specifies intentionally untracked files to ignore") },
{ "modules", N_("Defining submodule properties") },
{ "revisions", N_("Specifying revisions and ranges for Git") },
{ "tutorial", N_("A tutorial introduction to Git (for version 1.5.1 or newer)") },
{ "workflows", N_("An overview of recommended workflows with Git") },
};

static void list_common_guides_help(void)
{
int i, longest = 0;

for (i = 0; i < ARRAY_SIZE(common_guides); i++) {
if (longest < strlen(common_guides[i].name))
longest = strlen(common_guides[i].name);
}

puts(_("The common Git guides are:\n"));
for (i = 0; i < ARRAY_SIZE(common_guides); i++) {
printf(" %s ", common_guides[i].name);
mput_char(' ', longest - strlen(common_guides[i].name));
puts(_(common_guides[i].help));
}
putchar('\n');
}

static const char *check_git_cmd(const char* cmd)
{
char *alias;
Expand Down Expand Up @@ -463,6 +434,11 @@ int cmd_help(int argc, const char **argv, const char *prefix)

if (show_all) {
git_config(git_help_config, NULL);
if (verbose) {
setup_pager();
list_all_cmds_help();
return 0;
}
printf(_("usage: %s%s"), _(git_usage_string), "\n\n");
load_command_list("git-", &main_cmds, &other_cmds);
list_commands(colopts, &main_cmds, &other_cmds);
Expand Down
1 change: 1 addition & 0 deletions builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "string-list.h"
#include "packfile.h"
#include "tag.h"
#include "alias.h"

#define DEFAULT_TWOHEAD (1<<0)
#define DEFAULT_OCTOPUS (1<<1)
Expand Down
5 changes: 0 additions & 5 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -1826,11 +1826,6 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule);
void overlay_tree_on_index(struct index_state *istate,
const char *tree_name, const char *prefix);

char *alias_lookup(const char *alias);
int split_cmdline(char *cmdline, const char ***argv);
/* Takes a negative value returned by split_cmdline */
const char *split_cmdline_strerror(int cmdline_errno);

/* setup.c */
struct startup_info {
int have_repository;
Expand Down
Loading

0 comments on commit 2289880

Please sign in to comment.