Skip to content

Change how we process subcommands #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: demonstration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 18 additions & 120 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1060,126 +1060,24 @@ LIB_OBJS += wt-status.o
LIB_OBJS += xdiff-interface.o
LIB_OBJS += zlib.o

BUILTIN_OBJS += builtin/add.o
BUILTIN_OBJS += builtin/am.o
BUILTIN_OBJS += builtin/annotate.o
BUILTIN_OBJS += builtin/apply.o
BUILTIN_OBJS += builtin/archive.o
BUILTIN_OBJS += builtin/bisect--helper.o
BUILTIN_OBJS += builtin/blame.o
BUILTIN_OBJS += builtin/branch.o
BUILTIN_OBJS += builtin/bugreport.o
BUILTIN_OBJS += builtin/bundle.o
BUILTIN_OBJS += builtin/cat-file.o
BUILTIN_OBJS += builtin/check-attr.o
BUILTIN_OBJS += builtin/check-ignore.o
BUILTIN_OBJS += builtin/check-mailmap.o
BUILTIN_OBJS += builtin/check-ref-format.o
BUILTIN_OBJS += builtin/checkout--worker.o
BUILTIN_OBJS += builtin/checkout-index.o
BUILTIN_OBJS += builtin/checkout.o
BUILTIN_OBJS += builtin/clean.o
BUILTIN_OBJS += builtin/clone.o
BUILTIN_OBJS += builtin/column.o
BUILTIN_OBJS += builtin/commit-graph.o
BUILTIN_OBJS += builtin/commit-tree.o
BUILTIN_OBJS += builtin/commit.o
BUILTIN_OBJS += builtin/config.o
BUILTIN_OBJS += builtin/count-objects.o
BUILTIN_OBJS += builtin/credential-cache--daemon.o
BUILTIN_OBJS += builtin/credential-cache.o
BUILTIN_OBJS += builtin/credential-store.o
BUILTIN_OBJS += builtin/credential.o
BUILTIN_OBJS += builtin/describe.o
BUILTIN_OBJS += builtin/diff-files.o
BUILTIN_OBJS += builtin/diff-index.o
BUILTIN_OBJS += builtin/diff-tree.o
BUILTIN_OBJS += builtin/diff.o
BUILTIN_OBJS += builtin/difftool.o
BUILTIN_OBJS += builtin/env--helper.o
BUILTIN_OBJS += builtin/fast-export.o
BUILTIN_OBJS += builtin/fast-import.o
BUILTIN_OBJS += builtin/fetch-pack.o
BUILTIN_OBJS += builtin/fetch.o
BUILTIN_OBJS += builtin/fmt-merge-msg.o
BUILTIN_OBJS += builtin/for-each-ref.o
BUILTIN_OBJS += builtin/for-each-repo.o
BUILTIN_OBJS += builtin/fsck.o
BUILTIN_OBJS += builtin/gc.o
BUILTIN_OBJS += builtin/get-tar-commit-id.o
BUILTIN_OBJS += builtin/grep.o
BUILTIN_OBJS += builtin/hash-object.o
BUILTIN_OBJS += builtin/help.o
BUILTIN_OBJS += builtin/index-pack.o
BUILTIN_OBJS += builtin/init-db.o
BUILTIN_OBJS += builtin/interpret-trailers.o
BUILTIN_OBJS += builtin/log.o
BUILTIN_OBJS += builtin/ls-files.o
BUILTIN_OBJS += builtin/ls-remote.o
BUILTIN_OBJS += builtin/ls-tree.o
BUILTIN_OBJS += builtin/mailinfo.o
BUILTIN_OBJS += builtin/mailsplit.o
BUILTIN_OBJS += builtin/merge-base.o
BUILTIN_OBJS += builtin/merge-file.o
BUILTIN_OBJS += builtin/merge-index.o
BUILTIN_OBJS += builtin/merge-ours.o
BUILTIN_OBJS += builtin/merge-recursive.o
BUILTIN_OBJS += builtin/merge-tree.o
BUILTIN_OBJS += builtin/merge.o
BUILTIN_OBJS += builtin/mktag.o
BUILTIN_OBJS += builtin/mktree.o
BUILTIN_OBJS += builtin/multi-pack-index.o
BUILTIN_OBJS += builtin/mv.o
BUILTIN_OBJS += builtin/name-rev.o
BUILTIN_OBJS += builtin/notes.o
BUILTIN_OBJS += builtin/pack-objects.o
BUILTIN_OBJS += builtin/pack-redundant.o
BUILTIN_OBJS += builtin/pack-refs.o
BUILTIN_OBJS += builtin/patch-id.o
BUILTIN_OBJS += builtin/prune-packed.o
BUILTIN_OBJS += builtin/prune.o
BUILTIN_OBJS += builtin/pull.o
BUILTIN_OBJS += builtin/push.o
BUILTIN_OBJS += builtin/range-diff.o
BUILTIN_OBJS += builtin/read-tree.o
BUILTIN_OBJS += builtin/rebase.o
BUILTIN_OBJS += builtin/receive-pack.o
BUILTIN_OBJS += builtin/reflog.o
BUILTIN_OBJS += builtin/remote-ext.o
BUILTIN_OBJS += builtin/remote-fd.o
BUILTIN_OBJS += builtin/remote.o
BUILTIN_OBJS += builtin/repack.o
BUILTIN_OBJS += builtin/replace.o
BUILTIN_OBJS += builtin/rerere.o
BUILTIN_OBJS += builtin/reset.o
BUILTIN_OBJS += builtin/rev-list.o
BUILTIN_OBJS += builtin/rev-parse.o
BUILTIN_OBJS += builtin/revert.o
BUILTIN_OBJS += builtin/rm.o
BUILTIN_OBJS += builtin/send-pack.o
BUILTIN_OBJS += builtin/shortlog.o
BUILTIN_OBJS += builtin/show-branch.o
BUILTIN_OBJS += builtin/show-index.o
BUILTIN_OBJS += builtin/show-ref.o
BUILTIN_OBJS += builtin/sparse-checkout.o
BUILTIN_OBJS += builtin/stash.o
BUILTIN_OBJS += builtin/stripspace.o
BUILTIN_OBJS += builtin/submodule--helper.o
BUILTIN_OBJS += builtin/symbolic-ref.o
BUILTIN_OBJS += builtin/tag.o
BUILTIN_OBJS += builtin/unpack-file.o
BUILTIN_OBJS += builtin/unpack-objects.o
BUILTIN_OBJS += builtin/update-index.o
BUILTIN_OBJS += builtin/update-ref.o
BUILTIN_OBJS += builtin/update-server-info.o
BUILTIN_OBJS += builtin/upload-archive.o
BUILTIN_OBJS += builtin/upload-pack.o
BUILTIN_OBJS += builtin/var.o
BUILTIN_OBJS += builtin/verify-commit.o
BUILTIN_OBJS += builtin/verify-pack.o
BUILTIN_OBJS += builtin/verify-tag.o
BUILTIN_OBJS += builtin/worktree.o
BUILTIN_OBJS += builtin/write-tree.o
SOMETHING_DIFFERENT += 'Swimm Demo'
SOMETHING_DIFFERENT += 'Swimm Demo!'
SOMETHING_DIFFERENT += 'Swimm Demo!!'
SOMETHING_DIFFERENT += 'Swimm Demo'
SOMETHING_DIFFERENT += 'Swimm Demo!'
SOMETHING_DIFFERENT += 'Swimm Demo!!'
SOMETHING_DIFFERENT += 'Swimm Demo'
SOMETHING_DIFFERENT += 'Swimm Demo!'
SOMETHING_DIFFERENT += 'Swimm Demo!!'
SOMETHING_DIFFERENT += 'Swimm Demo'
SOMETHING_DIFFERENT += 'Swimm Demo!'
SOMETHING_DIFFERENT += 'Swimm Demo!!'
SOMETHING_DIFFERENT += 'Swimm Demo'
SOMETHING_DIFFERENT += 'Swimm Demo!'
SOMETHING_DIFFERENT += 'Swimm Demo!!'
SOMETHING_DIFFERENT += 'Swimm Demo'
SOMETHING_DIFFERENT += 'Swimm Demo!'
SOMETHING_DIFFERENT += 'Swimm Demo!!'

# THIRD_PARTY_SOURCES is a list of patterns compatible with the
# $(filter) and $(filter-out) family of functions. They specify source
Expand Down
36 changes: 20 additions & 16 deletions git.c → main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const char git_usage_string[] =
" <command> [<args>]");

const char git_more_info_string[] =
N_("'git help -a' and 'git help -g' list available subcommands and some\n"
N_("'git help -a' and 'git help -g' list available subsub_commands and some\n"
"concept guides. See 'git help <command>' or 'git help <concept>'\n"
"to read about a specific subcommand or concept.\n"
"See 'git help git' for an overview of the system.");
Expand Down Expand Up @@ -69,7 +69,7 @@ static int list_cmds(const char *spec)

/*
* Set up the repository so we can pick up any repo-level config (like
* completion.commands).
* completion.sub_commands).
*/
setup_git_directory_gently(&nongit);

Expand Down Expand Up @@ -143,7 +143,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)

/*
* For legacy reasons, the "version" and "help"
* commands can be written with "--" prepended
* sub_commands can be written with "--" prepended
* to make them look like flags.
*/
if (!strcmp(cmd, "--help") || !strcmp(cmd, "--version"))
Expand Down Expand Up @@ -416,6 +416,10 @@ static int handle_alias(int *argcp, const char ***argv)
return ret;
}

/*
* Some new comments
*/

static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
{
int status, help;
Expand Down Expand Up @@ -481,7 +485,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
return 0;
}

static struct cmd_struct commands[] = {
static struct cmd_struct sub_commands[] = {
{ "add", cmd_add, RUN_SETUP | NEED_WORK_TREE },
{ "am", cmd_am, RUN_SETUP | NEED_WORK_TREE },
{ "annotate", cmd_annotate, RUN_SETUP | NO_PARSEOPT },
Expand Down Expand Up @@ -628,8 +632,8 @@ static struct cmd_struct commands[] = {
static struct cmd_struct *get_builtin(const char *s)
{
int i;
for (i = 0; i < ARRAY_SIZE(commands); i++) {
struct cmd_struct *p = commands + i;
for (i = 0; i < ARRAY_SIZE(sub_commands); i++) {
struct cmd_struct *p = sub_commands + i;
if (!strcmp(s, p->cmd))
return p;
}
Expand All @@ -644,30 +648,30 @@ int is_builtin(const char *s)
static void list_builtins(struct string_list *out, unsigned int exclude_option)
{
int i;
for (i = 0; i < ARRAY_SIZE(commands); i++) {
for (i = 0; i < ARRAY_SIZE(sub_commands); i++) {
if (exclude_option &&
(commands[i].option & exclude_option))
(sub_commands[i].option & exclude_option))
continue;
string_list_append(out, commands[i].cmd);
string_list_append(out, sub_commands[i].cmd);
}
}

void load_builtin_commands(const char *prefix, struct cmdnames *cmds)
void load_builtin_sub_commands(const char *prefix, struct cmdnames *cmds)
{
const char *name;
int i;

/*
* Callers can ask for a subset of the commands based on a certain
* Callers can ask for a subset of the sub_commands based on a certain
* prefix, which is then dropped from the added names. The names in
* the `commands[]` array do not have the `git-` prefix, though,
* the `sub_commands[]` array do not have the `git-` prefix, though,
* therefore we must expect the `prefix` to at least start with `git-`.
*/
if (!skip_prefix(prefix, "git-", &prefix))
BUG("prefix '%s' must start with 'git-'", prefix);

for (i = 0; i < ARRAY_SIZE(commands); i++)
if (skip_prefix(commands[i].cmd, prefix, &name))
for (i = 0; i < ARRAY_SIZE(sub_commands); i++)
if (skip_prefix(sub_commands[i].cmd, prefix, &name))
add_cmdname(cmds, name, strlen(name));
}

Expand Down Expand Up @@ -888,7 +892,7 @@ int cmd_main(int argc, const char **argv)
argc--;
handle_options(&argv, &argc, NULL);
if (argc > 0) {
/* translate --help and --version into commands */
/* translate --help and --version into sub_commands */
skip_prefix(argv[0], "--", &argv[0]);
} else {
/* The user didn't specify a command; give them help */
Expand All @@ -901,7 +905,7 @@ int cmd_main(int argc, const char **argv)
cmd = argv[0];

/*
* We use PATH to find git commands, but we prepend some higher
* We use PATH to find git sub_commands, but we prepend some higher
* precedence paths: the "--exec-path" option, the GIT_EXEC_PATH
* environment, and the $(gitexecdir) from the Makefile at build
* time.
Expand Down