shell.con commit return the prune-packed progress display to the inner loop (93ff3f6)
   1#include "cache.h"
   2#include "quote.h"
   3#include "exec_cmd.h"
   4#include "strbuf.h"
   5
   6static int do_generic_cmd(const char *me, char *arg)
   7{
   8        const char *my_argv[4];
   9
  10        if (!arg || !(arg = sq_dequote(arg)))
  11                die("bad argument");
  12        if (prefixcmp(me, "git-"))
  13                die("bad command");
  14
  15        my_argv[0] = me + 4;
  16        my_argv[1] = arg;
  17        my_argv[2] = NULL;
  18
  19        return execv_git_cmd(my_argv);
  20}
  21
  22static int do_cvs_cmd(const char *me, char *arg)
  23{
  24        const char *cvsserver_argv[3] = {
  25                "cvsserver", "server", NULL
  26        };
  27        const char *oldpath = getenv("PATH");
  28        struct strbuf newpath = STRBUF_INIT;
  29
  30        if (!arg || strcmp(arg, "server"))
  31                die("git-cvsserver only handles server: %s", arg);
  32
  33        strbuf_addstr(&newpath, git_exec_path());
  34        strbuf_addch(&newpath, ':');
  35        strbuf_addstr(&newpath, oldpath);
  36
  37        setenv("PATH", strbuf_detach(&newpath, NULL), 1);
  38
  39        return execv_git_cmd(cvsserver_argv);
  40}
  41
  42
  43static struct commands {
  44        const char *name;
  45        int (*exec)(const char *me, char *arg);
  46} cmd_list[] = {
  47        { "git-receive-pack", do_generic_cmd },
  48        { "git-upload-pack", do_generic_cmd },
  49        { "cvs", do_cvs_cmd },
  50        { NULL },
  51};
  52
  53int main(int argc, char **argv)
  54{
  55        char *prog;
  56        struct commands *cmd;
  57
  58        if (argc == 2 && !strcmp(argv[1], "cvs server"))
  59                argv--;
  60        /* We want to see "-c cmd args", and nothing else */
  61        else if (argc != 3 || strcmp(argv[1], "-c"))
  62                die("What do you think I am? A shell?");
  63
  64        prog = argv[2];
  65        argv += 2;
  66        argc -= 2;
  67        for (cmd = cmd_list ; cmd->name ; cmd++) {
  68                int len = strlen(cmd->name);
  69                char *arg;
  70                if (strncmp(cmd->name, prog, len))
  71                        continue;
  72                arg = NULL;
  73                switch (prog[len]) {
  74                case '\0':
  75                        arg = NULL;
  76                        break;
  77                case ' ':
  78                        arg = prog + len + 1;
  79                        break;
  80                default:
  81                        continue;
  82                }
  83                exit(cmd->exec(cmd->name, arg));
  84        }
  85        die("unrecognized command '%s'", prog);
  86}