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