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] = {
65 while ((c
= *n
++) != 0) {
67 die("I don't like '%c'. Sue me.", c
);
73 * Yeah, yeah, fixme. Need to pass in the heads etc.
75 int git_connect(int fd
[2], char *url
, const char *prog
)
78 const char *host
, *path
;
83 url
= shell_safe(url
);
86 colon
= strchr(url
, ':');
92 snprintf(command
, sizeof(command
), "%s %s", prog
, path
);
93 if (pipe(pipefd
[0]) < 0 || pipe(pipefd
[1]) < 0)
94 die("unable to create pipe pair for communication");
97 dup2(pipefd
[1][0], 0);
98 dup2(pipefd
[0][1], 1);
104 execlp("ssh", "ssh", host
, command
, NULL
);
106 execlp("sh", "sh", "-c", command
, NULL
);
109 fd
[0] = pipefd
[0][0];
110 fd
[1] = pipefd
[1][1];
116 int finish_connect(pid_t pid
)
121 ret
= waitpid(pid
, NULL
, 0);