Skip to content

Commit 873700c

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent ef635b9 commit 873700c

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

upload-pack.c

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -552,28 +552,24 @@ static void send_shallow(struct commit_list *result)
552552
}
553553
}
554554

555-
static void deepen(int depth, const struct object_array *shallows)
555+
static void send_unshallow(const struct object_array *shallows)
556556
{
557-
struct commit_list *result = NULL;
558557
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+
569559
for (i = 0; i < shallows->nr; i++) {
570560
struct object *object = shallows->objects[i].item;
571561
if (object->flags & NOT_SHALLOW) {
572562
struct commit_list *parents;
573563
packet_write(1, "unshallow %s",
574564
oid_to_hex(&object->oid));
575565
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+
*/
577573
unregister_shallow(object->oid.hash);
578574
object->parsed = 0;
579575
parse_commit_or_die((struct commit *)object);
@@ -588,6 +584,27 @@ static void deepen(int depth, const struct object_array *shallows)
588584
/* make sure commit traversal conforms to client */
589585
register_shallow(object->oid.hash);
590586
}
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);
591608
packet_flush(1);
592609
}
593610

0 commit comments

Comments
 (0)