builtin/commit.c: extract ignore_non_trailer() helper function
[gitweb.git] / git.c
diff --git a/git.c b/git.c
index 850d3f5527f4100f45cb5eb1a7d8772e04ae4443..cb5208de6a5aab7c222a1d1655fe37089a119fe0 100644 (file)
--- a/git.c
+++ b/git.c
@@ -4,16 +4,19 @@
 #include "help.h"
 #include "quote.h"
 #include "run-command.h"
+#include "commit.h"
 
 const char git_usage_string[] =
-       "git [--version] [--help] [-c name=value]\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"
        "           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n"
        "           <command> [<args>]";
 
 const char git_more_info_string[] =
-       N_("See 'git help <command>' for more information on a specific command.");
+       N_("'git help -a' and 'git help -g' lists available subcommands and some\n"
+          "concept guides. See 'git help <command>' or 'git help <concept>'\n"
+          "to read about a specific subcommand or concept.");
 
 static struct startup_info git_startup_info;
 static int use_pager = -1;
@@ -144,6 +147,35 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                        setenv(GIT_LITERAL_PATHSPECS_ENVIRONMENT, "0", 1);
                        if (envchanged)
                                *envchanged = 1;
+               } else if (!strcmp(cmd, "--glob-pathspecs")) {
+                       setenv(GIT_GLOB_PATHSPECS_ENVIRONMENT, "1", 1);
+                       if (envchanged)
+                               *envchanged = 1;
+               } else if (!strcmp(cmd, "--noglob-pathspecs")) {
+                       setenv(GIT_NOGLOB_PATHSPECS_ENVIRONMENT, "1", 1);
+                       if (envchanged)
+                               *envchanged = 1;
+               } else if (!strcmp(cmd, "--icase-pathspecs")) {
+                       setenv(GIT_ICASE_PATHSPECS_ENVIRONMENT, "1", 1);
+                       if (envchanged)
+                               *envchanged = 1;
+               } else if (!strcmp(cmd, "--shallow-file")) {
+                       (*argv)++;
+                       (*argc)--;
+                       set_alternate_shallow_file((*argv)[0]);
+                       if (envchanged)
+                               *envchanged = 1;
+               } else if (!strcmp(cmd, "-C")) {
+                       if (*argc < 2) {
+                               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;
+                       (*argv)++;
+                       (*argc)--;
                } else {
                        fprintf(stderr, "Unknown option: %s\n", cmd);
                        usage(git_usage_string);
@@ -315,6 +347,7 @@ static void handle_internal_command(int argc, const char **argv)
                { "cat-file", cmd_cat_file, RUN_SETUP },
                { "check-attr", cmd_check_attr, RUN_SETUP },
                { "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 | NEED_WORK_TREE },
                { "checkout-index", cmd_checkout_index,
@@ -386,6 +419,7 @@ static void handle_internal_command(int argc, const char **argv)
                { "remote", cmd_remote, RUN_SETUP },
                { "remote-ext", cmd_remote_ext },
                { "remote-fd", cmd_remote_fd },
+               { "repack", cmd_repack, RUN_SETUP },
                { "replace", cmd_replace, RUN_SETUP },
                { "repo-config", cmd_repo_config, RUN_SETUP_GENTLY },
                { "rerere", cmd_rerere, RUN_SETUP },
@@ -505,8 +539,9 @@ static int run_argv(int *argcp, const char ***argv)
 }
 
 
-int main(int argc, const char **argv)
+int main(int argc, char **av)
 {
+       const char **argv = (const char **) av;
        const char *cmd;
 
        startup_info = &git_startup_info;
@@ -515,6 +550,13 @@ int main(int argc, const char **argv)
        if (!cmd)
                cmd = "git-help";
 
+       /*
+        * Always open file descriptors 0/1/2 to avoid clobbering files
+        * in die().  It also avoids messing up when the pipes are dup'ed
+        * onto stdin/stdout/stderr in the child processes we spawn.
+        */
+       sanitize_stdfds();
+
        git_setup_gettext();
 
        /*