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>
Nguyễn Thái Ngọc Duy committed
Jun 12, 2016 at 17:53 UTC
e8e44de7874f6ea7cdf35b526f790cc7fa8f34e6
1 file changed
+52
-47
upload-pack.c
+52
-47
@@ -538,6 +538,55 @@ error:
538
}
539
}
540
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
+
590
static void receive_needs(void)
591
{
592
struct object_array shallows = OBJECT_ARRAY_INIT;
@@ -630,53 +679,9 @@ static void receive_needs(void)
679
680
if (depth == 0 && shallows.nr == 0)
681
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
685
if (shallows.nr > 0) {
686
int i;
687
for (i = 0; i < shallows.nr; i++)