git-am: add am.threeWay config variable
[gitweb.git] / git.c
diff --git a/git.c b/git.c
index f22783894c161850b8e36fa5426bf61f4fc98a51..5feba410cab6d95e3b9ff9745db56a9d045f0c20 100644 (file)
--- a/git.c
+++ b/git.c
@@ -1,15 +1,12 @@
 #include "builtin.h"
-#include "cache.h"
 #include "exec_cmd.h"
 #include "help.h"
-#include "quote.h"
 #include "run-command.h"
-#include "commit.h"
 
 const char git_usage_string[] =
        "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 | --no-pager] [--no-replace-objects] [--bare]\n"
        "           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n"
        "           <command> [<args>]";
 
@@ -207,10 +204,12 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                                fprintf(stderr, "No directory given for -C.\n" );
                                usage(git_usage_string);
                        }
-                       if (chdir((*argv)[1]))
-                               die_errno("Cannot change to '%s'", (*argv)[1]);
-                       if (envchanged)
-                               *envchanged = 1;
+                       if ((*argv)[1][0]) {
+                               if (chdir((*argv)[1]))
+                                       die_errno("Cannot change to '%s'", (*argv)[1]);
+                               if (envchanged)
+                                       *envchanged = 1;
+                       }
                        (*argv)++;
                        (*argc)--;
                } else {
@@ -371,6 +370,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 
 static struct cmd_struct commands[] = {
        { "add", cmd_add, RUN_SETUP | NEED_WORK_TREE },
+       { "am", cmd_am, RUN_SETUP | NEED_WORK_TREE },
        { "annotate", cmd_annotate, RUN_SETUP },
        { "apply", cmd_apply, RUN_SETUP_GENTLY },
        { "archive", cmd_archive },
@@ -383,7 +383,7 @@ static struct cmd_struct commands[] = {
        { "check-ignore", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE },
        { "check-mailmap", cmd_check_mailmap, RUN_SETUP },
        { "check-ref-format", cmd_check_ref_format },
-       { "checkout", cmd_checkout, RUN_SETUP },
+       { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },
        { "checkout-index", cmd_checkout_index,
                RUN_SETUP | NEED_WORK_TREE},
        { "cherry", cmd_cherry, RUN_SETUP },
@@ -446,6 +446,7 @@ static struct cmd_struct commands[] = {
        { "pickaxe", cmd_blame, RUN_SETUP },
        { "prune", cmd_prune, RUN_SETUP },
        { "prune-packed", cmd_prune_packed, RUN_SETUP },
+       { "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
        { "push", cmd_push, RUN_SETUP },
        { "read-tree", cmd_read_tree, RUN_SETUP },
        { "receive-pack", cmd_receive_pack },
@@ -488,15 +489,20 @@ static struct cmd_struct commands[] = {
        { "write-tree", cmd_write_tree, RUN_SETUP },
 };
 
-int is_builtin(const char *s)
+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;
+               struct cmd_struct *p = commands + i;
                if (!strcmp(s, p->cmd))
-                       return 1;
+                       return p;
        }
-       return 0;
+       return NULL;
+}
+
+int is_builtin(const char *s)
+{
+       return !!get_builtin(s);
 }
 
 static void handle_builtin(int argc, const char **argv)
@@ -504,6 +510,7 @@ static void handle_builtin(int argc, const char **argv)
        const char *cmd = argv[0];
        int i;
        static const char ext[] = STRIP_EXTENSION;
+       struct cmd_struct *builtin;
 
        if (sizeof(ext) > 1) {
                i = strlen(argv[0]) - strlen(ext);
@@ -520,15 +527,12 @@ static void handle_builtin(int argc, const char **argv)
                argv[0] = cmd = "help";
        }
 
-       for (i = 0; i < ARRAY_SIZE(commands); i++) {
-               struct cmd_struct *p = commands+i;
-               if (strcmp(p->cmd, cmd))
-                       continue;
-               if (saved_environment && (p->option & NO_SETUP)) {
+       builtin = get_builtin(cmd);
+       if (builtin) {
+               if (saved_environment && (builtin->option & NO_SETUP))
                        restore_env();
-                       break;
-               }
-               exit(run_builtin(p, argc, argv));
+               else
+                       exit(run_builtin(builtin, argc, argv));
        }
 }
 
@@ -619,6 +623,7 @@ int main(int argc, char **av)
 {
        const char **argv = (const char **) av;
        const char *cmd;
+       int done_help = 0;
 
        startup_info = &git_startup_info;
 
@@ -681,9 +686,7 @@ int main(int argc, char **av)
        setup_path();
 
        while (1) {
-               static int done_help = 0;
-               static int was_alias = 0;
-               was_alias = run_argv(&argc, &argv);
+               int was_alias = run_argv(&argc, &argv);
                if (errno != ENOENT)
                        break;
                if (was_alias) {