]>
Commit | Line | Data |
---|---|---|
def88e9a | 1 | #include "cache.h" |
fb9040cc | 2 | #include "refs.h" |
def88e9a | 3 | #include "pkt-line.h" |
75bfc6c2 | 4 | #include <sys/wait.h> |
def88e9a LT |
5 | |
6 | static const char fetch_pack_usage[] = "git-fetch-pack [host:]directory [heads]* < mycommitlist"; | |
7 | static const char *exec = "git-upload-pack"; | |
8 | ||
fb9040cc | 9 | static int find_common(int fd[2], unsigned char *result_sha1, unsigned char *remote) |
def88e9a LT |
10 | { |
11 | static char line[1000]; | |
75bfc6c2 LT |
12 | int count = 0, flushes = 0, retval; |
13 | FILE *revs; | |
def88e9a | 14 | |
75bfc6c2 LT |
15 | revs = popen("git-rev-list $(git-rev-parse --all)", "r"); |
16 | if (!revs) | |
17 | die("unable to run 'git-rev-list'"); | |
fb9040cc LT |
18 | packet_write(fd[1], "want %s\n", sha1_to_hex(remote)); |
19 | packet_flush(fd[1]); | |
75bfc6c2 LT |
20 | flushes = 1; |
21 | retval = -1; | |
22 | while (fgets(line, sizeof(line), revs) != NULL) { | |
def88e9a LT |
23 | unsigned char sha1[20]; |
24 | if (get_sha1_hex(line, sha1)) | |
25 | die("git-fetch-pack: expected object name, got crud"); | |
26 | packet_write(fd[1], "have %s\n", sha1_to_hex(sha1)); | |
27 | if (!(31 & ++count)) { | |
28 | packet_flush(fd[1]); | |
29 | flushes++; | |
30 | ||
31 | /* | |
32 | * We keep one window "ahead" of the other side, and | |
33 | * will wait for an ACK only on the next one | |
34 | */ | |
35 | if (count == 32) | |
36 | continue; | |
75bfc6c2 LT |
37 | if (get_ack(fd[0], result_sha1)) { |
38 | flushes = 0; | |
39 | retval = 0; | |
40 | break; | |
41 | } | |
def88e9a LT |
42 | flushes--; |
43 | } | |
44 | } | |
75bfc6c2 LT |
45 | pclose(revs); |
46 | packet_write(fd[1], "done\n"); | |
def88e9a LT |
47 | while (flushes) { |
48 | flushes--; | |
49 | if (get_ack(fd[0], result_sha1)) | |
50 | return 0; | |
51 | } | |
75bfc6c2 | 52 | return retval; |
def88e9a LT |
53 | } |
54 | ||
fb9040cc LT |
55 | static int get_remote_heads(int fd, int nr_match, char **match, unsigned char *result) |
56 | { | |
57 | int count = 0; | |
58 | ||
def88e9a LT |
59 | for (;;) { |
60 | static char line[1000]; | |
61 | unsigned char sha1[20]; | |
62 | char *refname; | |
63 | int len; | |
64 | ||
65 | len = packet_read_line(fd, line, sizeof(line)); | |
66 | if (!len) | |
67 | break; | |
68 | if (line[len-1] == '\n') | |
69 | line[--len] = 0; | |
70 | if (len < 42 || get_sha1_hex(line, sha1)) | |
4f7770c8 | 71 | Content-type: text/html ]>