git-fetch-pack: Implement client part of the multi_ack extension
This patch concludes the series, which makes git-fetch-pack/git-upload-pack negotiate a potentially better set of common revs. It should make a difference when fetching from a repository with a few branches. 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:40 UTC
40a10462498bdd23d4e49f02867b8be50eb78704
2 files changed
+41
-14
connect.c
+4
-1
@@ -59,8 +59,11 @@ int get_ack(int fd, unsigned char *result_sha1)
59
if (!strcmp(line, "NAK"))
60
return 0;
61
if (!strncmp(line, "ACK ", 3)) {
62
- if (!get_sha1_hex(line+4, result_sha1))
62
+ if (!get_sha1_hex(line+4, result_sha1)) {
63
+ if (strstr(line+45, "continue"))
64
+ return 2;
65
return 1;
66
+ }
67
}
68
die("git-fetch_pack: expected ACK/NAK, got '%s'", line);
69
}
fetch-pack.c
+37
-13
@@ -125,7 +125,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,
125
struct ref *refs)
126
{
127
int fetching;
128
- int count = 0, flushes = 0, retval;
128
+ int count = 0, flushes = 0, multi_ack = 0, retval;
129
const unsigned char *sha1;
130
131
for_each_ref(rev_list_append_sha1);
@@ -156,20 +156,22 @@ static int find_common(int fd[2], unsigned char *result_sha1,
156
continue;
157
}
158
159
- packet_write(fd[1], "want %s\n", sha1_to_hex(remote));
159
+ packet_write(fd[1], "want %s multi_ack\n", sha1_to_hex(remote));
160
fetching++;
161
}
162
packet_flush(fd[1]);
163
if (!fetching)
164
return 1;
165
166
- flushes = 1;
166
+ flushes = 0;
167
retval = -1;
168
while ((sha1 = get_rev())) {
169
packet_write(fd[1], "have %s\n", sha1_to_hex(sha1));
170
if (verbose)
171
fprintf(stderr, "have %s\n", sha1_to_hex(sha1));
172
if (!(31 & ++count)) {
173
+ int ack;
174
+
175
packet_flush(fd[1]);
176
flushes++;
177
@@ -179,26 +181,48 @@ static int find_common(int fd[2], unsigned char *result_sha1,
181
*/
182
if (count == 32)
183
continue;
182
- if (get_ack(fd[0], result_sha1)) {
183
- flushes = 0;
184
- retval = 0;
185
- if (verbose)
186
- fprintf(stderr, "got ack\n");
187
- break;
188
- }
184
+
185
+ do {
186
+ ack = get_ack(fd[0], result_sha1);
187
+ if (verbose && ack)
188
+ fprintf(stderr, "got ack %d %s\n", ack,
189
+ sha1_to_hex(result_sha1));
190
+ if (ack == 1) {
191
+ if (!multi_ack)
192
+ flushes = 0;
193
+ retval = 0;
194
+ goto done;
195
+ } else if (ack == 2) {
196
+ multi_ack = 1;
197
+ mark_common((struct commit *)
198
+ lookup_object(result_sha1));
199
+ retval = 0;
200
+ }
201
+ } while(ack);
202
flushes--;
203
}
204
}
205
+done:
206
+ if (multi_ack) {
207
+ packet_flush(fd[1]);
208
+ flushes++;
209
+ }
210
packet_write(fd[1], "done\n");
211
if (verbose)
212
fprintf(stderr, "done\n");
213
+ if (retval != 0)
214
+ flushes++;
215
while (flushes) {
196
- flushes--;
216
if (get_ack(fd[0], result_sha1)) {
217
if (verbose)
199
- fprintf(stderr, "got ack\n");
200
- return 0;
218
+ fprintf(stderr, "got ack %s\n",
219
+ sha1_to_hex(result_sha1));
220
+ if (!multi_ack)
221
+ return 0;
222
+ retval = 0;
223
+ continue;
224
}
225
+ flushes--;
226
}
227
return retval;
228
}