shell.con commit checkout: tone down the "forked status" diagnostic messages (b0030db)
   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
  28        if (!arg || strcmp(arg, "server"))
  29                die("git-cvsserver only handles server: %s", arg);
  30
  31        setup_path(NULL);
  32
  33        return execv_git_cmd(cvsserver_argv);
  34}
  35
  36
  37static struct commands {
  38        const char *name;
  39        int (*exec)(const char *me, char *arg);
  40} cmd_list[] = {
  41        { "git-receive-pack", do_generic_cmd },
  42        { "git-upload-pack", do_generic_cmd },
  43        { "cvs", do_cvs_cmd },
  44        { NULL },
  45};
  46
  47int main(int argc, char **argv)
  48{
  49        char *prog;
  50        struct commands *cmd;
  51
  52        if (argc == 2 && !strcmp(argv[1], "cvs server"))
  53                argv--;
  54        /* We want to see "-c cmd args", and nothing else */
  55        else if (argc != 3 || strcmp(argv[1], "-c"))
  56                die("What do you think I am? A shell?");
  57
  58        prog = argv[2];
  59        argv += 2;
  60        argc -= 2;
  61        for (cmd = cmd_list ; cmd->name ; cmd++) {
  62                int len = strlen(cmd->name);
  63                char *arg;
  64                if (strncmp(cmd->name, prog, len))
  65                        continue;
  66                arg = NULL;
  67                switch (prog[len]) {
  68                case '\0':
  69                        arg = NULL;
  70                        break;
  71                case ' ':
  72                        arg = prog + len + 1;
  73                        break;
  74                default:
  75                        continue;
  76                }
  77                exit(cmd->exec(cmd->name, arg));
  78        }
  79        die("unrecognized command '%s'", prog);
  80}