builtin-fast-export: Only output a single parent per line
[git/git.git] / shell.c
CommitLineData
35eb2d36
LT
1#include "cache.h"
2#include "quote.h"
77cb17e9 3#include "exec_cmd.h"
0c696fe7 4#include "strbuf.h"
35eb2d36
LT
5
6static int do_generic_cmd(const char *me, char *arg)
7{
8 const char *my_argv[4];
9
ab5f8627 10 if (!arg || !(arg = sq_dequote(arg)))
35eb2d36 11 die("bad argument");
cc44c765 12 if (prefixcmp(me, "git-"))
77cb17e9 13 die("bad command");
35eb2d36 14
77cb17e9 15 my_argv[0] = me + 4;
35eb2d36
LT
16 my_argv[1] = arg;
17 my_argv[2] = NULL;
18
9201c707 19 return execv_git_cmd(my_argv);
35eb2d36
LT
20}
21
0c696fe7
JS
22static int do_cvs_cmd(const char *me, char *arg)
23{
24 const char *cvsserver_argv[3] = {
25 "cvsserver", "server", NULL
26 };
0c696fe7
JS
27
28 if (!arg || strcmp(arg, "server"))
29 die("git-cvsserver only handles server: %s", arg);
30
e8f5d870 31 setup_path(NULL);
0c696fe7
JS
32
33 return execv_git_cmd(cvsserver_argv);
34}
35
36
35eb2d36
LT
37static 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 },
0c696fe7 43 { "cvs", do_cvs_cmd },
35eb2d36
LT
44 { NULL },
45};
46
47int main(int argc, char **argv)
48{
49 char *prog;
50 struct commands *cmd;
51
0c696fe7
JS
52 if (argc == 2 && !strcmp(argv[1], "cvs server"))
53 argv--;
35eb2d36 54 /* We want to see "-c cmd args", and nothing else */
0c696fe7 55 else if (argc != 3 || strcmp(argv[1], "-c"))
35eb2d36
LT
56 die("What do you think I am? A shell?");
57
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;
76 }
77 exit(cmd->exec(cmd->name, arg));
78 }
79 die("unrecognized command '%s'", prog);
80}