@matheusbsbs / matheus-bagliano / commits / 0f8fdc3958
Fork 0

git-upload-pack: Support sending multiple ACK messages

The current fetch/upload protocol works like this: - client sends revs it wants to have via "want" messages - client sends a flush message (message with len 0) - client sends revs it has via "have" messages - after one window (32 revs), a flush is sent - after each subsequent window, a flush is sent, and an ACK/NAK is received. (NAK means that server does not have any of the transmitted revs; ACK sends also the sha1 of the rev server has) - when the first ACK is received, client sends "done", and does not expect any further messages One special case, though: - if no ACK is received (only NAK's), and client runs out of revs to send, "done" is sent, and server sends just one more "NAK" A smarter scheme, which actually has a chance to detect more than one common rev, would be to send more than just one ACK. This patch implements the server side of the following extension to the protocol: - client sends at least one "want" message with "multi_ack" appended, like "want 1234567890123456789012345678901234567890 multi_ack" - if the server understands that extension, it will send ACK messages for all revs it has, not just the first one - server appends "continue" to the ACK messages like "ACK 1234567890123456789012345678901234567890 continue" until it has MAX_HAS-1 revs. In this manner, client knows when to stop sending revs by checking for the substring "continue" (and further knows that server understands multi_ack) In this manner, the protocol stays backwards compatible, since both client must send "want ... multi_ack" and server must answer with "ACK ... continue" to enable the extension. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Oct 23, 2005 at 03:37 UTC 0f8fdc3958ad0cb7c740b76189f98307eebcd64b
1 file changed +15 -22
upload-pack.c
+15 -22
@@ -10,7 +10,7 @@ static const char upload_pack_usage[] = "git-upload-pack [--strict] [--timeout=n
10 #define THEY_HAVE (1U << 0)
11 #define MAX_HAS 256
12 #define MAX_NEEDS 256
13 -static int nr_has = 0, nr_needs = 0;
13 +static int nr_has = 0, nr_needs = 0, multi_ack = 0;
14 static unsigned char has_sha1[MAX_HAS][20];
15 static unsigned char needs_sha1[MAX_NEEDS][20];
16 static unsigned int timeout = 0;
@@ -124,39 +124,28 @@ static int get_common_commits(void)
124 reset_timeout();
125
126 if (!len) {
127 - packet_write(1, "NAK\n");
127 + if (multi_ack || nr_has == 0)
128 + packet_write(1, "NAK\n");
129 continue;
130 }
131 len = strip(line, len);
132 if (!strncmp(line, "have ", 5)) {
132 - if (got_sha1(line+5, sha1)) {
133 - packet_write(1, "ACK %s\n", sha1_to_hex(sha1));
134 - break;
135 - }
133 + if (got_sha1(line+5, sha1) &&
134 + (multi_ack || nr_has == 1))
135 + packet_write(1, "ACK %s%s\n",
136 + sha1_to_hex(sha1),
137 + multi_ack && nr_has < MAX_HAS ?
138 + " continue" : "");
139 continue;
140 }
141 if (!strcmp(line, "done")) {
142 + if (nr_has > 0)
143 + return 0;
144 packet_write(1, "NAK\n");
145 return -1;
146 }
147 die("git-upload-pack: expected SHA1 list, got '%s'", line);
148 }
144 -
145 - for (;;) {
146 - len = packet_read_line(0, line, sizeof(line));
147 - reset_timeout();
148 - if (!len)
149 - continue;
150 - len = strip(line, len);
151 - if (!strncmp(line, "have ", 5)) {
152 - got_sha1(line+5, sha1);
153 - continue;
154 - }
155 - if (!strcmp(line, "done"))
156 - break;
157 - die("git-upload-pack: expected SHA1 list, got '%s'", line);
158 - }
159 - return 0;
149 }
150
151 static int receive_needs(void)
@@ -185,6 +174,10 @@ static int receive_needs(void)
174 if (strncmp("want ", line, 5) || get_sha1_hex(line+5, sha1_buf))
175 die("git-upload-pack: protocol error, "
176 "expected to get sha, not '%s'", line);
177 +
178 + if (strstr(line+45, "multi_ack"))
179 + multi_ack = 1;
180 +
181 needs++;
182 }
183 }