@matheusbsbs / matheus-bagliano / commits / 1bd8c8f00b
Fork 0

git-upload-pack: Support the multi_ack protocol

This implements three things (trying very hard to be backwards compatible): It sends the "multi_ack" capability via the mechanism proposed by Sergey Vlasov. When the client sends "multi_ack" with at least one "want", multi_ack is enabled. When multi_ack is enabled, "continue" is appended to each "ACK" until either the server can not store more refs, or "done" is received. In contrast to the original protocol, as long as "continue" is sent, flushes are answered by a "NAK" (not just until an "ACK" was sent), and if "continue" was sent at least once, the last message is an "ACK" without "continue". Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Oct 28, 2005 at 04:49 UTC 1bd8c8f00b1c7facb67c99047fe777b53f2c49ff
1 file changed +24 -23
upload-pack.c
+24 -23
@@ -12,7 +12,7 @@ static const char upload_pack_usage[] = "git-upload-pack [--strict] [--timeout=n
12 #define WANTED (1U << 2)
13 #define MAX_HAS 256
14 #define MAX_NEEDS 256
15 -static int nr_has = 0, nr_needs = 0, nr_our_refs = 0;
15 +static int nr_has = 0, nr_needs = 0, multi_ack = 0, nr_our_refs = 0;
16 static unsigned char has_sha1[MAX_HAS][20];
17 static unsigned char needs_sha1[MAX_NEEDS][20];
18 static unsigned int timeout = 0;
@@ -119,7 +119,7 @@ static int got_sha1(char *hex, unsigned char *sha1)
119 static int get_common_commits(void)
120 {
121 static char line[1000];
122 - unsigned char sha1[20];
122 + unsigned char sha1[20], last_sha1[20];
123 int len;
124
125 track_object_refs = 0;
@@ -130,39 +130,36 @@ static int get_common_commits(void)
130 reset_timeout();
131
132 if (!len) {
133 - packet_write(1, "NAK\n");
133 + if (nr_has == 0 || multi_ack)
134 + packet_write(1, "NAK\n");
135 continue;
136 }
137 len = strip(line, len);
138 if (!strncmp(line, "have ", 5)) {
138 - if (got_sha1(line+5, sha1)) {
139 - packet_write(1, "ACK %s\n", sha1_to_hex(sha1));
140 - break;
139 + if (got_sha1(line+5, sha1) &&
140 + (multi_ack || nr_has == 1)) {
141 + if (nr_has >= MAX_HAS)
142 + multi_ack = 0;
143 + packet_write(1, "ACK %s%s\n",
144 + sha1_to_hex(sha1),
145 + multi_ack ? " continue" : "");
146 + if (multi_ack)
147 + memcpy(last_sha1, sha1, 20);
148 }
149 continue;
150 }
151 if (!strcmp(line, "done")) {
152 + if (nr_has > 0) {
153 + if (multi_ack)
154 + packet_write(1, "ACK %s\n",
155 + sha1_to_hex(last_sha1));
156 + return 0;
157 + }
158 packet_write(1, "NAK\n");
159 return -1;
160 }
161 die("git-upload-pack: expected SHA1 list, got '%s'", line);
162 }
150 -
151 - for (;;) {
152 - len = packet_read_line(0, line, sizeof(line));
153 - reset_timeout();
154 - if (!len)
155 - continue;
156 - len = strip(line, len);
157 - if (!strncmp(line, "have ", 5)) {
158 - got_sha1(line+5, sha1);
159 - continue;
160 - }
161 - if (!strcmp(line, "done"))
162 - break;
163 - die("git-upload-pack: expected SHA1 list, got '%s'", line);
164 - }
165 - return 0;
163 }
164
165 static int receive_needs(void)
@@ -192,6 +189,8 @@ static int receive_needs(void)
189 if (strncmp("want ", line, 5) || get_sha1_hex(line+5, sha1_buf))
190 die("git-upload-pack: protocol error, "
191 "expected to get sha, not '%s'", line);
192 + if (strstr(line+45, "multi_ack"))
193 + multi_ack = 1;
194
195 /* We have sent all our refs already, and the other end
196 * should have chosen out of them; otherwise they are
@@ -213,9 +212,11 @@ static int receive_needs(void)
212
213 static int send_ref(const char *refname, const unsigned char *sha1)
214 {
215 + static char *capabilities = "\0multi_ack";
216 struct object *o = parse_object(sha1);
217
218 - packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname);
218 + packet_write(1, "%s %s%s\n", sha1_to_hex(sha1), refname, capabilities);
219 + capabilities = "";
220 if (!(o->flags & OUR_REF)) {
221 o->flags |= OUR_REF;
222 nr_our_refs++;