3 static const char send_pack_usage
[] = "git-send-pack [--exec=other] destination [heads]*";
5 static const char *exec
= "git-receive-pack";
7 static int send_pack(int in
, int out
)
10 static char buffer
[1000];
11 int ret
= read(in
, buffer
, sizeof(buffer
));
13 write(1, buffer
, ret
);
23 * First, make it shell-safe. We do this by just disallowing any
24 * special characters. Somebody who cares can do escaping and let
25 * through the rest. But since we're doing to feed this to ssh as
26 * a command line, we're going to be pretty damn anal for now.
28 static char *shell_safe(char *url
)
32 static const char flags
[256] = {
41 while ((c
= *n
++) != 0) {
43 die("I don't like '%c'. Sue me.", c
);
49 * Yeah, yeah, fixme. Need to pass in the heads etc.
51 static int setup_connection(int fd
[2], char *url
, char **heads
)
54 const char *host
, *path
;
58 url
= shell_safe(url
);
61 colon
= strchr(url
, ':');
67 snprintf(command
, sizeof(command
), "%s %s", exec
, path
);
68 if (pipe(pipefd
[0]) < 0 || pipe(pipefd
[1]) < 0)
69 die("unable to create pipe pair for communication");
71 dup2(pipefd
[1][0], 0);
72 dup2(pipefd
[0][1], 1);
78 execlp("ssh", "ssh", host
, command
, NULL
);
80 execlp(host
, command
, NULL
);
90 int main(int argc
, char **argv
)
98 for (i
= 1; i
< argc
; i
++) {
102 if (!strncmp(arg
, "--exec=", 7)) {
106 usage(send_pack_usage
);
110 nr_heads
= argc
- i
-1;
114 usage(send_pack_usage
);
115 if (setup_connection(fd
, dest
, heads
))
117 return send_pack(fd
[0], fd
[1]);