upload-pack: move rev-list code out of check_non_tip()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jun 12, 2016 at 17:53 UTC 3f0f6624f554a663ca0c83fd80f769dc9cef93e2
1 file changed +23 -13
upload-pack.c
+23 -13
@@ -451,7 +451,7 @@ static int is_our_ref(struct object *o)
451 return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF);
452 }
453
454 -static void check_non_tip(void)
454 +static int has_unreachable(struct object_array *src)
455 {
456 static const char *argv[] = {
457 "rev-list", "--stdin", NULL,
@@ -461,14 +461,6 @@ static void check_non_tip(void)
461 char namebuf[42]; /* ^ + SHA-1 + LF */
462 int i;
463
464 - /*
465 - * In the normal in-process case without
466 - * uploadpack.allowReachableSHA1InWant,
467 - * non-tip requests can never happen.
468 - */
469 - if (!stateless_rpc && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
470 - goto error;
471 -
464 cmd.argv = argv;
465 cmd.git_cmd = 1;
466 cmd.no_stderr = 1;
@@ -498,8 +490,8 @@ static void check_non_tip(void)
490 goto error;
491 }
492 namebuf[40] = '\n';
501 - for (i = 0; i < want_obj.nr; i++) {
502 - o = want_obj.objects[i].item;
493 + for (i = 0; i < src->nr; i++) {
494 + o = src->objects[i].item;
495 if (is_our_ref(o))
496 continue;
497 memcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
@@ -530,7 +522,7 @@ static void check_non_tip(void)
522 sigchain_pop(SIGPIPE);
523
524 /* All the non-tip ones are ancestors of what we advertised */
533 - return;
525 + return 0;
526
527 error:
528 sigchain_pop(SIGPIPE);
@@ -539,10 +531,28 @@ error:
531 close(cmd.in);
532 if (cmd.out >= 0)
533 close(cmd.out);
534 + return 1;
535 +}
536
537 +static void check_non_tip(void)
538 +{
539 + int i;
540 +
541 + /*
542 + * In the normal in-process case without
543 + * uploadpack.allowReachableSHA1InWant,
544 + * non-tip requests can never happen.
545 + */
546 + if (!stateless_rpc && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
547 + goto error;
548 + if (!has_unreachable(&want_obj))
549 + /* All the non-tip ones are ancestors of what we advertised */
550 + return;
551 +
552 +error:
553 /* Pick one of them (we know there at least is one) */
554 for (i = 0; i < want_obj.nr; i++) {
545 - o = want_obj.objects[i].item;
555 + struct object *o = want_obj.objects[i].item;
556 if (!is_our_ref(o))
557 die("git upload-pack: not our ref %s",
558 oid_to_hex(&o->oid));