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

upload-pack: minor clean-up in multi-ack logic

No changes to what it does, but separating the codepath clearly with if ... else if ... chain makes it easier to follow. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jul 5, 2006 at 18:12 UTC c04c4e5708c9ad3dc534ff50ad8f28de5a7cfbff
1 file changed +12 -10
upload-pack.c
+12 -10
@@ -351,7 +351,8 @@ static int got_sha1(char *hex, unsigned char *sha1)
351 static int get_common_commits(void)
352 {
353 static char line[1000];
354 - unsigned char sha1[20], last_sha1[20];
354 + unsigned char sha1[20];
355 + char hex[41], last_hex[41];
356 int len;
357
358 track_object_refs = 0;
@@ -368,21 +369,22 @@ static int get_common_commits(void)
369 }
370 len = strip(line, len);
371 if (!strncmp(line, "have ", 5)) {
371 - if (got_sha1(line+5, sha1) &&
372 - (multi_ack || have_obj.nr == 1)) {
373 - packet_write(1, "ACK %s%s\n",
374 - sha1_to_hex(sha1),
375 - multi_ack ? " continue" : "");
376 - if (multi_ack)
377 - memcpy(last_sha1, sha1, 20);
372 + if (got_sha1(line+5, sha1)) {
373 + memcpy(hex, sha1_to_hex(sha1), 41);
374 + if (multi_ack) {
375 + const char *msg = "ACK %s continue\n";
376 + packet_write(1, msg, hex);
377 + memcpy(last_hex, hex, 41);
378 + }
379 + else if (have_obj.nr == 1)
380 + packet_write(1, "ACK %s\n", hex);
381 }
382 continue;
383 }
384 if (!strcmp(line, "done")) {
385 if (have_obj.nr > 0) {
386 if (multi_ack)
384 - packet_write(1, "ACK %s\n",
385 - sha1_to_hex(last_sha1));
387 + packet_write(1, "ACK %s\n", last_hex);
388 return 0;
389 }
390 packet_write(1, "NAK\n");