summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
Diffstat (limited to 'git.c')
-rw-r--r--git.c71
1 files changed, 18 insertions, 53 deletions
diff --git a/git.c b/git.c
index c887272b12..489aab4d83 100644
--- a/git.c
+++ b/git.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "exec_cmd.h"
#include "help.h"
#include "run-command.h"
@@ -16,50 +17,8 @@ const char git_more_info_string[] =
"to read about a specific subcommand or concept.");
static int use_pager = -1;
-static char *orig_cwd;
-static const char *env_names[] = {
- GIT_DIR_ENVIRONMENT,
- GIT_WORK_TREE_ENVIRONMENT,
- GIT_IMPLICIT_WORK_TREE_ENVIRONMENT,
- GIT_PREFIX_ENVIRONMENT
-};
-static char *orig_env[4];
-static int save_restore_env_balance;
-
-static void save_env_before_alias(void)
-{
- int i;
-
- assert(save_restore_env_balance == 0);
- save_restore_env_balance = 1;
- orig_cwd = xgetcwd();
- for (i = 0; i < ARRAY_SIZE(env_names); i++) {
- orig_env[i] = getenv(env_names[i]);
- orig_env[i] = xstrdup_or_null(orig_env[i]);
- }
-}
-static void restore_env(int external_alias)
-{
- int i;
-
- assert(save_restore_env_balance == 1);
- save_restore_env_balance = 0;
- if (!external_alias && orig_cwd && chdir(orig_cwd))
- die_errno("could not move to %s", orig_cwd);
- free(orig_cwd);
- for (i = 0; i < ARRAY_SIZE(env_names); i++) {
- if (external_alias &&
- !strcmp(env_names[i], GIT_PREFIX_ENVIRONMENT))
- continue;
- if (orig_env[i]) {
- setenv(env_names[i], orig_env[i], 1);
- free(orig_env[i]);
- } else {
- unsetenv(env_names[i]);
- }
- }
-}
+static void list_builtins(void);
static void commit_pager_choice(void) {
switch (use_pager) {
@@ -232,6 +191,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
}
(*argv)++;
(*argc)--;
+ } else if (!strcmp(cmd, "--list-builtins")) {
+ list_builtins();
+ exit(0);
} else {
fprintf(stderr, "Unknown option: %s\n", cmd);
usage(git_usage_string);
@@ -250,19 +212,18 @@ static int handle_alias(int *argcp, const char ***argv)
const char **new_argv;
const char *alias_command;
char *alias_string;
- int unused_nongit;
-
- save_env_before_alias();
- setup_git_directory_gently(&unused_nongit);
alias_command = (*argv)[0];
alias_string = alias_lookup(alias_command);
if (alias_string) {
if (alias_string[0] == '!') {
struct child_process child = CHILD_PROCESS_INIT;
+ int nongit_ok;
+
+ /* Aliases expect GIT_PREFIX, GIT_DIR etc to be set */
+ setup_git_directory_gently(&nongit_ok);
commit_pager_choice();
- restore_env(1);
child.use_shell = 1;
argv_array_push(&child.args, alias_string + 1);
@@ -308,8 +269,6 @@ static int handle_alias(int *argcp, const char ***argv)
ret = 1;
}
- restore_env(0);
-
errno = saved_errno;
return ret;
@@ -361,8 +320,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
if (!help && get_super_prefix()) {
if (!(p->option & SUPPORT_SUPER_PREFIX))
die("%s doesn't support --super-prefix", p->cmd);
- if (prefix)
- die("can't use --super-prefix from a subdirectory");
}
if (!help && p->option & NEED_WORK_TREE)
@@ -443,7 +400,7 @@ static struct cmd_struct commands[] = {
{ "init-db", cmd_init_db },
{ "interpret-trailers", cmd_interpret_trailers, RUN_SETUP_GENTLY },
{ "log", cmd_log, RUN_SETUP },
- { "ls-files", cmd_ls_files, RUN_SETUP | SUPPORT_SUPER_PREFIX },
+ { "ls-files", cmd_ls_files, RUN_SETUP },
{ "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
{ "ls-tree", cmd_ls_tree, RUN_SETUP },
{ "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY },
@@ -473,6 +430,7 @@ static struct cmd_struct commands[] = {
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
{ "push", cmd_push, RUN_SETUP },
{ "read-tree", cmd_read_tree, RUN_SETUP | SUPPORT_SUPER_PREFIX},
+ { "rebase--helper", cmd_rebase__helper, RUN_SETUP | NEED_WORK_TREE },
{ "receive-pack", cmd_receive_pack },
{ "reflog", cmd_reflog, RUN_SETUP },
{ "remote", cmd_remote, RUN_SETUP },
@@ -530,6 +488,13 @@ int is_builtin(const char *s)
return !!get_builtin(s);
}
+static void list_builtins(void)
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(commands); i++)
+ printf("%s\n", commands[i].cmd);
+}
+
#ifdef STRIP_EXTENSION
static void strip_extension(const char **argv)
{