4 static const char send_pack_usage[] = "git-send-pack [--exec=other] destination [heads]*";
6 static const char *exec = "git-receive-pack";
8 static int send_pack(int in, int out)
11 static char buffer[1000];
14 len = packet_read_line(in, buffer, sizeof(buffer));
16 write(2, buffer, len);
27 * First, make it shell-safe. We do this by just disallowing any
28 * special characters. Somebody who cares can do escaping and let
29 * through the rest. But since we're doing to feed this to ssh as
30 * a command line, we're going to be pretty damn anal for now.
32 static char *shell_safe(char *url)
36 static const char flags[256] = {
45 while ((c = *n++) != 0) {
47 die("I don't like '%c'. Sue me.", c);
53 * Yeah, yeah, fixme. Need to pass in the heads etc.
55 static int setup_connection(int fd[2], char *url, char **heads)
58 const char *host, *path;
62 url = shell_safe(url);
65 colon = strchr(url, ':');
71 snprintf(command, sizeof(command), "%s %s", exec, path);
72 if (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0)
73 die("unable to create pipe pair for communication");
75 dup2(pipefd[1][0], 0);
76 dup2(pipefd[0][1], 1);
82 execlp("ssh", "ssh", host, command, NULL);
84 execlp("sh", "sh", "-c", command, NULL);
94 int main(int argc, char **argv)
102 for (i = 1; i < argc; i++) {
106 if (!strncmp(arg, "--exec=", 7)) {
110 usage(send_pack_usage);
114 nr_heads = argc - i -1;
118 usage(send_pack_usage);
119 if (setup_connection(fd, dest, heads))
121 return send_pack(fd[0], fd[1]);