shell.con commit Remove the temp file if it is empty after the request has failed (50496b2)
   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        arg = sq_dequote(arg);
   9        if (!arg)
  10                die("bad argument");
  11
  12        my_argv[0] = me;
  13        my_argv[1] = arg;
  14        my_argv[2] = NULL;
  15
  16        return execvp(me, (char**) my_argv);
  17}
  18
  19static struct commands {
  20        const char *name;
  21        int (*exec)(const char *me, char *arg);
  22} cmd_list[] = {
  23        { "git-receive-pack", do_generic_cmd },
  24        { "git-upload-pack", do_generic_cmd },
  25        { NULL },
  26};
  27
  28int main(int argc, char **argv)
  29{
  30        char *prog;
  31        struct commands *cmd;
  32
  33        /* We want to see "-c cmd args", and nothing else */
  34        if (argc != 3 || strcmp(argv[1], "-c"))
  35                die("What do you think I am? A shell?");
  36
  37        prog = argv[2];
  38        argv += 2;
  39        argc -= 2;
  40        for (cmd = cmd_list ; cmd->name ; cmd++) {
  41                int len = strlen(cmd->name);
  42                char *arg;
  43                if (strncmp(cmd->name, prog, len))
  44                        continue;
  45                arg = NULL;
  46                switch (prog[len]) {
  47                case '\0':
  48                        arg = NULL;
  49                        break;
  50                case ' ':
  51                        arg = prog + len + 1;
  52                        break;
  53                default:
  54                        continue;
  55                }
  56                exit(cmd->exec(cmd->name, arg));
  57        }
  58        die("unrecognized command '%s'", prog);
  59}