Skip to content

Commit e8e44de

Browse files
pcloudsgitster
authored andcommitted
upload-pack: move shallow deepen code out of receive_needs()
This is a prep step for further refactoring. Besides reindentation and s/shallows\./shallows->/g, no other changes are expected. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 9318c5d commit e8e44de

File tree

1 file changed

+52
-47
lines changed

1 file changed

+52
-47
lines changed

upload-pack.c

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,55 @@ static void check_non_tip(void)
538538
}
539539
}
540540

541+
static void deepen(int depth, const struct object_array *shallows)
542+
{
543+
struct commit_list *result = NULL, *backup = NULL;
544+
int i;
545+
if (depth == INFINITE_DEPTH && !is_repository_shallow())
546+
for (i = 0; i < shallows->nr; i++) {
547+
struct object *object = shallows->objects[i].item;
548+
object->flags |= NOT_SHALLOW;
549+
}
550+
else
551+
backup = result =
552+
get_shallow_commits(&want_obj, depth,
553+
SHALLOW, NOT_SHALLOW);
554+
while (result) {
555+
struct object *object = &result->item->object;
556+
if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
557+
packet_write(1, "shallow %s",
558+
oid_to_hex(&object->oid));
559+
register_shallow(object->oid.hash);
560+
shallow_nr++;
561+
}
562+
result = result->next;
563+
}
564+
free_commit_list(backup);
565+
for (i = 0; i < shallows->nr; i++) {
566+
struct object *object = shallows->objects[i].item;
567+
if (object->flags & NOT_SHALLOW) {
568+
struct commit_list *parents;
569+
packet_write(1, "unshallow %s",
570+
oid_to_hex(&object->oid));
571+
object->flags &= ~CLIENT_SHALLOW;
572+
/* make sure the real parents are parsed */
573+
unregister_shallow(object->oid.hash);
574+
object->parsed = 0;
575+
parse_commit_or_die((struct commit *)object);
576+
parents = ((struct commit *)object)->parents;
577+
while (parents) {
578+
add_object_array(&parents->item->object,
579+
NULL, &want_obj);
580+
parents = parents->next;
581+
}
582+
add_object_array(object, NULL, &extra_edge_obj);
583+
}
584+
/* make sure commit traversal conforms to client */
585+
register_shallow(object->oid.hash);
586+
}
587+
packet_flush(1);
588+
}
589+
541590
static void receive_needs(void)
542591
{
543592
struct object_array shallows = OBJECT_ARRAY_INIT;
@@ -630,53 +679,9 @@ static void receive_needs(void)
630679

631680
if (depth == 0 && shallows.nr == 0)
632681
return;
633-
if (depth > 0) {
634-
struct commit_list *result = NULL, *backup = NULL;
635-
int i;
636-
if (depth == INFINITE_DEPTH && !is_repository_shallow())
637-
for (i = 0; i < shallows.nr; i++) {
638-
struct object *object = shallows.objects[i].item;
639-
object->flags |= NOT_SHALLOW;
640-
}
641-
else
642-
backup = result =
643-
get_shallow_commits(&want_obj, depth,
644-
SHALLOW, NOT_SHALLOW);
645-
while (result) {
646-
struct object *object = &result->item->object;
647-
if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
648-
packet_write(1, "shallow %s",
649-
oid_to_hex(&object->oid));
650-
register_shallow(object->oid.hash);
651-
shallow_nr++;
652-
}
653-
result = result->next;
654-
}
655-
free_commit_list(backup);
656-
for (i = 0; i < shallows.nr; i++) {
657-
struct object *object = shallows.objects[i].item;
658-
if (object->flags & NOT_SHALLOW) {
659-
struct commit_list *parents;
660-
packet_write(1, "unshallow %s",
661-
oid_to_hex(&object->oid));
662-
object->flags &= ~CLIENT_SHALLOW;
663-
/* make sure the real parents are parsed */
664-
unregister_shallow(object->oid.hash);
665-
object->parsed = 0;
666-
parse_commit_or_die((struct commit *)object);
667-
parents = ((struct commit *)object)->parents;
668-
while (parents) {
669-
add_object_array(&parents->item->object,
670-
NULL, &want_obj);
671-
parents = parents->next;
672-
}
673-
add_object_array(object, NULL, &extra_edge_obj);
674-
}
675-
/* make sure commit traversal conforms to client */
676-
register_shallow(object->oid.hash);
677-
}
678-
packet_flush(1);
679-
} else
682+
if (depth > 0)
683+
deepen(depth, &shallows);
684+
else
680685
if (shallows.nr > 0) {
681686
int i;
682687
for (i = 0; i < shallows.nr; i++)

0 commit comments

Comments
 (0)