Merge branch 'jc/typebreak'
[git/jnareb-git/bp-gitweb.git] / shell.c
blob9826109d5b1b3746aea33dc6b7ebe7b6da19bd22
1 #include "cache.h"
2 #include "quote.h"
3 #include "exec_cmd.h"
4 #include "strbuf.h"
6 static int do_generic_cmd(const char *me, char *arg)
8 const char *my_argv[4];
10 if (!arg || !(arg = sq_dequote(arg)))
11 die("bad argument");
12 if (prefixcmp(me, "git-"))
13 die("bad command");
15 my_argv[0] = me + 4;
16 my_argv[1] = arg;
17 my_argv[2] = NULL;
19 return execv_git_cmd(my_argv);
22 static int do_cvs_cmd(const char *me, char *arg)
24 const char *cvsserver_argv[3] = {
25 "cvsserver", "server", NULL
28 if (!arg || strcmp(arg, "server"))
29 die("git-cvsserver only handles server: %s", arg);
31 setup_path(NULL);
33 return execv_git_cmd(cvsserver_argv);
37 static 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 },
47 int main(int argc, char **argv)
49 char *prog;
50 struct commands *cmd;
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?");
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;
77 exit(cmd->exec(cmd->name, arg));
79 die("unrecognized command '%s'", prog);