5 int get_ack(int fd, unsigned char *result_sha1)
7 static char line[1000];
8 int len = packet_read_line(fd, line, sizeof(line));
11 die("git-fetch-pack: expected ACK/NAK, got EOF");
12 if (line[len-1] == '\n')
14 if (!strcmp(line, "NAK"))
16 if (!strncmp(line, "ACK ", 3)) {
17 if (!get_sha1_hex(line+4, result_sha1))
20 die("git-fetch_pack: expected ACK/NAK, got '%s'", line);
23 int path_match(const char *path, int nr, char **match)
26 int pathlen = strlen(path);
28 for (i = 0; i < nr; i++) {
32 if (!len || len > pathlen)
34 if (memcmp(path + pathlen - len, s, len))
36 if (pathlen > len && path[pathlen - len - 1] != '/')
45 * First, make it shell-safe. We do this by just disallowing any
46 * special characters. Somebody who cares can do escaping and let
47 * through the rest. But since we're doing to feed this to ssh as
48 * a command line, we're going to be pretty damn anal for now.
50 static char *shell_safe(char *url)
54 static const char flags[256] = {
63 while ((c = *n++) != 0) {
65 die("I don't like '%c'. Sue me.", c);
71 * Yeah, yeah, fixme. Need to pass in the heads etc.
73 int git_connect(int fd[2], char *url, const char *prog)
76 const char *host, *path;
81 url = shell_safe(url);
84 colon = strchr(url, ':');
90 snprintf(command, sizeof(command), "%s %s", prog, path);
91 if (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0)
92 die("unable to create pipe pair for communication");
95 dup2(pipefd[1][0], 0);
96 dup2(pipefd[0][1], 1);
102 execlp("ssh", "ssh", host, command, NULL);
104 execlp("sh", "sh", "-c", command, NULL);
107 fd[0] = pipefd[0][0];
108 fd[1] = pipefd[1][1];
114 int finish_connect(pid_t pid)
119 ret = waitpid(pid, NULL, 0);