Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
Diffstat (limited to 'git.c')
-rw-r--r--git.c97
1 files changed, 84 insertions, 13 deletions
diff --git a/git.c b/git.c
index f598fae7b7..3fded74519 100644
--- a/git.c
+++ b/git.c
@@ -3,6 +3,7 @@
#include "exec-cmd.h"
#include "help.h"
#include "run-command.h"
+#include "alias.h"
#define RUN_SETUP (1<<0)
#define RUN_SETUP_GENTLY (1<<1)
@@ -25,7 +26,7 @@ struct cmd_struct {
const char git_usage_string[] =
N_("git [--version] [--help] [-C <path>] [-c <name>=<value>]\n"
" [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n"
- " [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]\n"
+ " [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]\n"
" [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n"
" <command> [<args>]");
@@ -36,7 +37,66 @@ const char git_more_info_string[] =
static int use_pager = -1;
-static void list_builtins(unsigned int exclude_option, char sep);
+static void list_builtins(struct string_list *list, unsigned int exclude_option);
+
+static void exclude_helpers_from_list(struct string_list *list)
+{
+ int i = 0;
+
+ while (i < list->nr) {
+ if (strstr(list->items[i].string, "--"))
+ unsorted_string_list_delete_item(list, i, 0);
+ else
+ i++;
+ }
+}
+
+static int match_token(const char *spec, int len, const char *token)
+{
+ int token_len = strlen(token);
+
+ return len == token_len && !strncmp(spec, token, token_len);
+}
+
+static int list_cmds(const char *spec)
+{
+ struct string_list list = STRING_LIST_INIT_DUP;
+ int i;
+
+ while (*spec) {
+ const char *sep = strchrnul(spec, ',');
+ int len = sep - spec;
+
+ if (match_token(spec, len, "builtins"))
+ list_builtins(&list, 0);
+ else if (match_token(spec, len, "main"))
+ list_all_main_cmds(&list);
+ else if (match_token(spec, len, "others"))
+ list_all_other_cmds(&list);
+ else if (match_token(spec, len, "nohelpers"))
+ exclude_helpers_from_list(&list);
+ else if (match_token(spec, len, "alias"))
+ list_aliases(&list);
+ else if (match_token(spec, len, "config"))
+ list_cmds_by_config(&list);
+ else if (len > 5 && !strncmp(spec, "list-", 5)) {
+ struct strbuf sb = STRBUF_INIT;
+
+ strbuf_add(&sb, spec + 5, len - 5);
+ list_cmds_by_category(&list, sb.buf);
+ strbuf_release(&sb);
+ }
+ else
+ die(_("unsupported command listing type '%s'"), spec);
+ spec += len;
+ if (*spec == ',')
+ spec++;
+ }
+ for (i = 0; i < list.nr; i++)
+ puts(list.items[i].string);
+ string_list_clear(&list, 0);
+ return 0;
+}
static void commit_pager_choice(void) {
switch (use_pager) {
@@ -83,7 +143,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
*/
if (skip_prefix(cmd, "--exec-path", &cmd)) {
if (*cmd == '=')
- git_set_argv_exec_path(cmd + 1);
+ git_set_exec_path(cmd + 1);
else {
puts(git_exec_path());
exit(0);
@@ -99,7 +159,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
exit(0);
} else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
use_pager = 1;
- } else if (!strcmp(cmd, "--no-pager")) {
+ } else if (!strcmp(cmd, "-P") || !strcmp(cmd, "--no-pager")) {
use_pager = 0;
if (envchanged)
*envchanged = 1;
@@ -207,7 +267,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
} else if (!strcmp(cmd, "--shallow-file")) {
(*argv)++;
(*argc)--;
- set_alternate_shallow_file((*argv)[0], 1);
+ set_alternate_shallow_file(the_repository, (*argv)[0], 1);
if (envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "-C")) {
@@ -223,12 +283,19 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
}
(*argv)++;
(*argc)--;
- } else if (!strcmp(cmd, "--list-builtins")) {
- list_builtins(0, '\n');
- exit(0);
- } else if (!strcmp(cmd, "--list-parseopt-builtins")) {
- list_builtins(NO_PARSEOPT, ' ');
- exit(0);
+ } else if (skip_prefix(cmd, "--list-cmds=", &cmd)) {
+ if (!strcmp(cmd, "parseopt")) {
+ struct string_list list = STRING_LIST_INIT_DUP;
+ int i;
+
+ list_builtins(&list, NO_PARSEOPT);
+ for (i = 0; i < list.nr; i++)
+ printf("%s ", list.items[i].string);
+ string_list_clear(&list, 0);
+ exit(0);
+ } else {
+ exit(list_cmds(cmd));
+ }
} else {
fprintf(stderr, _("unknown option: %s\n"), cmd);
usage(git_usage_string);
@@ -392,6 +459,7 @@ static struct cmd_struct commands[] = {
{ "clone", cmd_clone },
{ "column", cmd_column, RUN_SETUP_GENTLY },
{ "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE },
+ { "commit-graph", cmd_commit_graph, RUN_SETUP },
{ "commit-tree", cmd_commit_tree, RUN_SETUP | NO_PARSEOPT },
{ "config", cmd_config, RUN_SETUP_GENTLY | DELAY_PAGER_CONFIG },
{ "count-objects", cmd_count_objects, RUN_SETUP },
@@ -465,9 +533,11 @@ static struct cmd_struct commands[] = {
{ "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
{ "rm", cmd_rm, RUN_SETUP },
{ "send-pack", cmd_send_pack, RUN_SETUP },
+ { "serve", cmd_serve, RUN_SETUP },
{ "shortlog", cmd_shortlog, RUN_SETUP_GENTLY | USE_PAGER },
{ "show", cmd_show, RUN_SETUP },
{ "show-branch", cmd_show_branch, RUN_SETUP },
+ { "show-index", cmd_show_index },
{ "show-ref", cmd_show_ref, RUN_SETUP },
{ "stage", cmd_add, RUN_SETUP | NEED_WORK_TREE },
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
@@ -482,6 +552,7 @@ static struct cmd_struct commands[] = {
{ "update-server-info", cmd_update_server_info, RUN_SETUP },
{ "upload-archive", cmd_upload_archive, NO_PARSEOPT },
{ "upload-archive--writer", cmd_upload_archive_writer, NO_PARSEOPT },
+ { "upload-pack", cmd_upload_pack },
{ "var", cmd_var, RUN_SETUP_GENTLY | NO_PARSEOPT },
{ "verify-commit", cmd_verify_commit, RUN_SETUP },
{ "verify-pack", cmd_verify_pack },
@@ -508,14 +579,14 @@ int is_builtin(const char *s)
return !!get_builtin(s);
}
-static void list_builtins(unsigned int exclude_option, char sep)
+static void list_builtins(struct string_list *out, unsigned int exclude_option)
{
int i;
for (i = 0; i < ARRAY_SIZE(commands); i++) {
if (exclude_option &&
(commands[i].option & exclude_option))
continue;
- printf("%s%c", commands[i].cmd, sep);
+ string_list_append(out, commands[i].cmd);
}
}