repack: do not accidentally pack kept objects by default
[gitweb.git] / shell.c
diff --git a/shell.c b/shell.c
index f0f6c2d3be924e976fe1bbc7e962b8ceaf83f37d..66350b220cc74abd383e10770f8325ba4e658e87 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -6,6 +6,7 @@
 
 #define COMMAND_DIR "git-shell-commands"
 #define HELP_COMMAND COMMAND_DIR "/help"
+#define NOLOGIN_COMMAND COMMAND_DIR "/no-interactive-login"
 
 static int do_generic_cmd(const char *me, char *arg)
 {
@@ -65,6 +66,18 @@ static void run_shell(void)
 {
        int done = 0;
        static const char *help_argv[] = { HELP_COMMAND, NULL };
+
+       if (!access(NOLOGIN_COMMAND, F_OK)) {
+               /* Interactive login disabled. */
+               const char *argv[] = { NOLOGIN_COMMAND, NULL };
+               int status;
+
+               status = run_command_v_opt(argv, 0);
+               if (status < 0)
+                       exit(127);
+               exit(status);
+       }
+
        /* Print help if enabled */
        run_command_v_opt(help_argv, RUN_SILENT_EXEC_FAILURE);
 
@@ -73,8 +86,10 @@ static void run_shell(void)
                const char *prog;
                char *full_cmd;
                char *rawargs;
+               char *split_args;
                const char **argv;
                int code;
+               int count;
 
                fprintf(stderr, "git> ");
                if (strbuf_getline(&line, stdin, '\n') == EOF) {
@@ -84,7 +99,12 @@ static void run_shell(void)
                }
                strbuf_trim(&line);
                rawargs = strbuf_detach(&line, NULL);
-               if (split_cmdline(rawargs, &argv) == -1) {
+               split_args = xstrdup(rawargs);
+               count = split_cmdline(split_args, &argv);
+               if (count < 0) {
+                       fprintf(stderr, "invalid command format '%s': %s\n", rawargs,
+                               split_cmdline_strerror(count));
+                       free(split_args);
                        free(rawargs);
                        continue;
                }
@@ -127,19 +147,18 @@ int main(int argc, char **argv)
        char *prog;
        const char **user_argv;
        struct commands *cmd;
-       int devnull_fd;
+       int count;
+
+       git_setup_gettext();
+
+       git_extract_argv0_path(argv[0]);
 
        /*
         * Always open file descriptors 0/1/2 to avoid clobbering files
-        * in die().  It also avoids not messing up when the pipes are
-        * dup'ed onto stdin/stdout/stderr in the child processes we spawn.
+        * in die().  It also avoids messing up when the pipes are dup'ed
+        * onto stdin/stdout/stderr in the child processes we spawn.
         */
-       devnull_fd = open("/dev/null", O_RDWR);
-       while (devnull_fd >= 0 && devnull_fd <= 2)
-               devnull_fd = dup(devnull_fd);
-       if (devnull_fd == -1)
-               die_errno("opening /dev/null failed");
-       close (devnull_fd);
+       sanitize_stdfds();
 
        /*
         * Special hack to pretend to be a CVS server
@@ -190,7 +209,8 @@ int main(int argc, char **argv)
        }
 
        cd_to_homedir();
-       if (split_cmdline(prog, &user_argv) != -1) {
+       count = split_cmdline(prog, &user_argv);
+       if (count >= 0) {
                if (is_valid_cmd_name(user_argv[0])) {
                        prog = make_cmd(user_argv[0]);
                        user_argv[0] = prog;
@@ -201,6 +221,7 @@ int main(int argc, char **argv)
                die("unrecognized command '%s'", argv[2]);
        } else {
                free(prog);
-               die("invalid command format '%s'", argv[2]);
+               die("invalid command format '%s': %s", argv[2],
+                   split_cmdline_strerror(count));
        }
 }