6 static int do_generic_cmd(const char *me, char *arg)
8 const char *my_argv[4];
11 if (!arg || !(arg = sq_dequote(arg)))
13 if (prefixcmp(me, "git-"))
20 return execv_git_cmd(my_argv);
23 static int do_cvs_cmd(const char *me, char *arg)
25 const char *cvsserver_argv[3] = {
26 "cvsserver", "server", NULL
29 if (!arg || strcmp(arg, "server"))
30 die("git-cvsserver only handles server: %s", arg);
33 return execv_git_cmd(cvsserver_argv);
37 static struct commands {
39 int (*exec)(const char *me, char *arg);
41 { "git-receive-pack", do_generic_cmd },
42 { "git-upload-pack", do_generic_cmd },
43 { "git-upload-archive", do_generic_cmd },
44 { "cvs", do_cvs_cmd },
48 int main(int argc, char **argv)
55 * Always open file descriptors 0/1/2 to avoid clobbering files
56 * in die(). It also avoids not messing up when the pipes are
57 * dup'ed onto stdin/stdout/stderr in the child processes we spawn.
59 devnull_fd = open("/dev/null", O_RDWR);
60 while (devnull_fd >= 0 && devnull_fd <= 2)
61 devnull_fd = dup(devnull_fd);
63 die("opening /dev/null failed (%s)", strerror(errno));
67 * Special hack to pretend to be a CVS server
69 if (argc == 2 && !strcmp(argv[1], "cvs server"))
73 * We do not accept anything but "-c" followed by "cmd arg",
74 * where "cmd" is a very limited subset of git commands.
76 else if (argc != 3 || strcmp(argv[1], "-c"))
77 die("What do you think I am? A shell?");
80 if (!strncmp(prog, "git", 3) && isspace(prog[3]))
81 /* Accept "git foo" as if the caller said "git-foo". */
84 for (cmd = cmd_list ; cmd->name ; cmd++) {
85 int len = strlen(cmd->name);
87 if (strncmp(cmd->name, prog, len))
100 exit(cmd->exec(cmd->name, arg));
102 die("unrecognized command '%s'", prog);