shell.con commit Merge branch 'np/pack' (99ebd06)
   1#include "cache.h"
   2#include "quote.h"
   3#include "exec_cmd.h"
   4
   5static int do_generic_cmd(const char *me, char *arg)
   6{
   7        const char *my_argv[4];
   8
   9        if (!arg || !(arg = sq_dequote(arg)))
  10                die("bad argument");
  11        if (prefixcmp(me, "git-"))
  12                die("bad command");
  13
  14        my_argv[0] = me + 4;
  15        my_argv[1] = arg;
  16        my_argv[2] = NULL;
  17
  18        return execv_git_cmd(my_argv);
  19}
  20
  21static struct commands {
  22        const char *name;
  23        int (*exec)(const char *me, char *arg);
  24} cmd_list[] = {
  25        { "git-receive-pack", do_generic_cmd },
  26        { "git-upload-pack", do_generic_cmd },
  27        { NULL },
  28};
  29
  30int main(int argc, char **argv)
  31{
  32        char *prog;
  33        struct commands *cmd;
  34
  35        /* We want to see "-c cmd args", and nothing else */
  36        if (argc != 3 || strcmp(argv[1], "-c"))
  37                die("What do you think I am? A shell?");
  38
  39        prog = argv[2];
  40        argv += 2;
  41        argc -= 2;
  42        for (cmd = cmd_list ; cmd->name ; cmd++) {
  43                int len = strlen(cmd->name);
  44                char *arg;
  45                if (strncmp(cmd->name, prog, len))
  46                        continue;
  47                arg = NULL;
  48                switch (prog[len]) {
  49                case '\0':
  50                        arg = NULL;
  51                        break;
  52                case ' ':
  53                        arg = prog + len + 1;
  54                        break;
  55                default:
  56                        continue;
  57                }
  58                exit(cmd->exec(cmd->name, arg));
  59        }
  60        die("unrecognized command '%s'", prog);
  61}