upload-pack: move "unshallow" sending code out of deepen()

Also add some more comments in this code because it takes too long to understand what it does (to me, who should be familiar enough to understand this code well!) 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 873700c92e01dbd5ccbe5d36878bb96d1bef3c36
1 file changed +30 -13
upload-pack.c
+30 -13
@@ -552,20 +552,10 @@ static void send_shallow(struct commit_list *result)
552 }
553 }
554
555 -static void deepen(int depth, const struct object_array *shallows)
555 +static void send_unshallow(const struct object_array *shallows)
556 {
557 - struct commit_list *result = NULL;
557 int i;
559 - if (depth == INFINITE_DEPTH && !is_repository_shallow())
560 - for (i = 0; i < shallows->nr; i++) {
561 - struct object *object = shallows->objects[i].item;
562 - object->flags |= NOT_SHALLOW;
563 - }
564 - else
565 - result = get_shallow_commits(&want_obj, depth,
566 - SHALLOW, NOT_SHALLOW);
567 - send_shallow(result);
568 - free_commit_list(result);
558 +
559 for (i = 0; i < shallows->nr; i++) {
560 struct object *object = shallows->objects[i].item;
561 if (object->flags & NOT_SHALLOW) {
@@ -573,7 +563,13 @@ static void deepen(int depth, const struct object_array *shallows)
563 packet_write(1, "unshallow %s",
564 oid_to_hex(&object->oid));
565 object->flags &= ~CLIENT_SHALLOW;
576 - /* make sure the real parents are parsed */
566 + /*
567 + * We want to _register_ "object" as shallow, but we
568 + * also need to traverse object's parents to deepen a
569 + * shallow clone. Unregister it for now so we can
570 + * parse and add the parents to the want list, then
571 + * re-register it.
572 + */
573 unregister_shallow(object->oid.hash);
574 object->parsed = 0;
575 parse_commit_or_die((struct commit *)object);
@@ -588,6 +584,27 @@ static void deepen(int depth, const struct object_array *shallows)
584 /* make sure commit traversal conforms to client */
585 register_shallow(object->oid.hash);
586 }
587 +}
588 +
589 +static void deepen(int depth, const struct object_array *shallows)
590 +{
591 + if (depth == INFINITE_DEPTH && !is_repository_shallow()) {
592 + int i;
593 +
594 + for (i = 0; i < shallows->nr; i++) {
595 + struct object *object = shallows->objects[i].item;
596 + object->flags |= NOT_SHALLOW;
597 + }
598 + } else {
599 + struct commit_list *result;
600 +
601 + result = get_shallow_commits(&want_obj, depth,
602 + SHALLOW, NOT_SHALLOW);
603 + send_shallow(result);
604 + free_commit_list(result);
605 + }
606 +
607 + send_unshallow(shallows);
608 packet_flush(1);
609 }
610