git-fetch-pack: Support multi_ack extension
The client side support for multi_ack. 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:50 UTC
c4c86f07d01bc4a05126b129f644e70dd9e244d0
2 files changed
+46
-17
connect.c
+4
-1
@@ -73,8 +73,11 @@ int get_ack(int fd, unsigned char *result_sha1)
73
if (!strcmp(line, "NAK"))
74
return 0;
75
if (!strncmp(line, "ACK ", 3)) {
76
- if (!get_sha1_hex(line+4, result_sha1))
76
+ if (!get_sha1_hex(line+4, result_sha1)) {
77
+ if (strstr(line+45, "continue"))
78
+ return 2;
79
return 1;
80
+ }
81
}
82
die("git-fetch_pack: expected ACK/NAK, got '%s'", line);
83
}
fetch-pack.c
+42
-16
@@ -19,7 +19,7 @@ static const char *exec = "git-upload-pack";
19
#define POPPED (1U << 4)
20
21
static struct commit_list *rev_list = NULL;
22
-static int non_common_revs = 0;
22
+static int non_common_revs = 0, multi_ack = 0;
23
24
static void rev_list_push(struct commit *commit, int mark)
25
{
@@ -157,7 +157,8 @@ static int find_common(int fd[2], unsigned char *result_sha1,
157
continue;
158
}
159
160
- packet_write(fd[1], "want %s\n", sha1_to_hex(remote));
160
+ packet_write(fd[1], "want %s%s\n", sha1_to_hex(remote),
161
+ multi_ack ? " multi_ack" : "");
162
fetching++;
163
}
164
packet_flush(fd[1]);
@@ -171,6 +172,8 @@ static int find_common(int fd[2], unsigned char *result_sha1,
172
if (verbose)
173
fprintf(stderr, "have %s\n", sha1_to_hex(sha1));
174
if (!(31 & ++count)) {
175
+ int ack;
176
+
177
packet_flush(fd[1]);
178
flushes++;
179
@@ -180,29 +183,47 @@ static int find_common(int fd[2], unsigned char *result_sha1,
183
*/
184
if (count == 32)
185
continue;
183
- if (get_ack(fd[0], result_sha1)) {
184
- flushes = 0;
185
- retval = 0;
186
- if (verbose)
187
- fprintf(stderr, "got ack\n");
188
- break;
189
- }
186
+
187
+ do {
188
+ ack = get_ack(fd[0], result_sha1);
189
+ if (verbose && ack)
190
+ fprintf(stderr, "got ack %d %s\n", ack,
191
+ sha1_to_hex(result_sha1));
192
+ if (ack == 1) {
193
+ flushes = 0;
194
+ multi_ack = 0;
195
+ retval = 0;
196
+ goto done;
197
+ } else if (ack == 2) {
198
+ struct commit *commit =
199
+ lookup_commit(result_sha1);
200
+ mark_common(commit, 0, 1);
201
+ retval = 0;
202
+ }
203
+ } while (ack);
204
flushes--;
205
}
206
}
193
-
207
+done:
208
packet_write(fd[1], "done\n");
209
if (verbose)
210
fprintf(stderr, "done\n");
197
- if (retval != 0)
211
+ if (retval != 0) {
212
+ multi_ack = 0;
213
flushes++;
199
- while (flushes) {
200
- flushes--;
201
- if (get_ack(fd[0], result_sha1)) {
214
+ }
215
+ while (flushes || multi_ack) {
216
+ int ack = get_ack(fd[0], result_sha1);
217
+ if (ack) {
218
if (verbose)
203
- fprintf(stderr, "got ack\n");
204
- return 0;
219
+ fprintf(stderr, "got ack (%d) %s\n", ack,
220
+ sha1_to_hex(result_sha1));
221
+ if (ack == 1)
222
+ return 0;
223
+ multi_ack = 1;
224
+ continue;
225
}
226
+ flushes--;
227
}
228
return retval;
229
}
@@ -344,6 +365,11 @@ static int fetch_pack(int fd[2], int nr_match, char **match)
365
pid_t pid;
366
367
get_remote_heads(fd[0], &ref, 0, NULL, 0);
368
+ if (server_supports("multi_ack")) {
369
+ if (verbose)
370
+ fprintf(stderr, "Server supports multi_ack\n");
371
+ multi_ack = 1;
372
+ }
373
if (!ref) {
374
packet_flush(fd[1]);
375
die("no matching remote head");