pack-objects: refactor code into compute_layer_order()
In a following commit, as we will use delta islands, we will have to compute the write order for different layers, not just for one. Let's prepare for that by refactoring the code that will be used to compute the write order for a given layer into a new compute_layer_order() function. This will make it easier to see and understand what the following changes are doing. Helped-by: Duy Nguyen <pclouds@gmail.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Aug 16, 2018 at 08:13 UTC
f64ba53ee74b1ee2909d3804818b09481b3e64b2
1 file changed
+50
-40
builtin/pack-objects.c
+50
-40
@@ -667,48 +667,15 @@ static void add_family_to_write_order(struct object_entry **wo,
667
add_descendants_to_write_order(wo, endp, root);
668
}
669
670
-static struct object_entry **compute_write_order(void)
670
+static void compute_layer_order(struct object_entry **wo, unsigned int *wo_end)
671
{
672
- unsigned int i, wo_end, last_untagged;
673
-
674
- struct object_entry **wo;
672
+ unsigned int i, last_untagged;
673
struct object_entry *objects = to_pack.objects;
674
675
for (i = 0; i < to_pack.nr_objects; i++) {
678
- objects[i].tagged = 0;
679
- objects[i].filled = 0;
680
- SET_DELTA_CHILD(&objects[i], NULL);
681
- SET_DELTA_SIBLING(&objects[i], NULL);
682
- }
683
-
684
- /*
685
- * Fully connect delta_child/delta_sibling network.
686
- * Make sure delta_sibling is sorted in the original
687
- * recency order.
688
- */
689
- for (i = to_pack.nr_objects; i > 0;) {
690
- struct object_entry *e = &objects[--i];
691
- if (!DELTA(e))
692
- continue;
693
- /* Mark me as the first child */
694
- e->delta_sibling_idx = DELTA(e)->delta_child_idx;
695
- SET_DELTA_CHILD(DELTA(e), e);
696
- }
697
-
698
- /*
699
- * Mark objects that are at the tip of tags.
700
- */
701
- for_each_tag_ref(mark_tagged, NULL);
702
-
703
- /*
704
- * Give the objects in the original recency order until
705
- * we see a tagged tip.
706
- */
707
- ALLOC_ARRAY(wo, to_pack.nr_objects);
708
- for (i = wo_end = 0; i < to_pack.nr_objects; i++) {
676
if (objects[i].tagged)
677
break;
711
- add_to_write_order(wo, &wo_end, &objects[i]);
678
+ add_to_write_order(wo, wo_end, &objects[i]);
679
}
680
last_untagged = i;
681
@@ -717,7 +684,7 @@ static struct object_entry **compute_write_order(void)
684
*/
685
for (; i < to_pack.nr_objects; i++) {
686
if (objects[i].tagged)
720
- add_to_write_order(wo, &wo_end, &objects[i]);
687
+ add_to_write_order(wo, wo_end, &objects[i]);
688
}
689
690
/*
@@ -727,7 +694,7 @@ static struct object_entry **compute_write_order(void)
694
if (oe_type(&objects[i]) != OBJ_COMMIT &&
695
oe_type(&objects[i]) != OBJ_TAG)
696
continue;
730
- add_to_write_order(wo, &wo_end, &objects[i]);
697
+ add_to_write_order(wo, wo_end, &objects[i]);
698
}
699
700
/*
@@ -736,7 +703,7 @@ static struct object_entry **compute_write_order(void)
703
for (i = last_untagged; i < to_pack.nr_objects; i++) {
704
if (oe_type(&objects[i]) != OBJ_TREE)
705
continue;
739
- add_to_write_order(wo, &wo_end, &objects[i]);
706
+ add_to_write_order(wo, wo_end, &objects[i]);
707
}
708
709
/*
@@ -744,8 +711,51 @@ static struct object_entry **compute_write_order(void)
711
*/
712
for (i = last_untagged; i < to_pack.nr_objects; i++) {
713
if (!objects[i].filled)
747
- add_family_to_write_order(wo, &wo_end, &objects[i]);
714
+ add_family_to_write_order(wo, wo_end, &objects[i]);
715
}
716
+}
717
+
718
+static struct object_entry **compute_write_order(void)
719
+{
720
+ unsigned int i, wo_end;
721
+
722
+ struct object_entry **wo;
723
+ struct object_entry *objects = to_pack.objects;
724
+
725
+ for (i = 0; i < to_pack.nr_objects; i++) {
726
+ objects[i].tagged = 0;
727
+ objects[i].filled = 0;
728
+ SET_DELTA_CHILD(&objects[i], NULL);
729
+ SET_DELTA_SIBLING(&objects[i], NULL);
730
+ }
731
+
732
+ /*
733
+ * Fully connect delta_child/delta_sibling network.
734
+ * Make sure delta_sibling is sorted in the original
735
+ * recency order.
736
+ */
737
+ for (i = to_pack.nr_objects; i > 0;) {
738
+ struct object_entry *e = &objects[--i];
739
+ if (!DELTA(e))
740
+ continue;
741
+ /* Mark me as the first child */
742
+ e->delta_sibling_idx = DELTA(e)->delta_child_idx;
743
+ SET_DELTA_CHILD(DELTA(e), e);
744
+ }
745
+
746
+ /*
747
+ * Mark objects that are at the tip of tags.
748
+ */
749
+ for_each_tag_ref(mark_tagged, NULL);
750
+
751
+ /*
752
+ * Give the objects in the original recency order until
753
+ * we see a tagged tip.
754
+ */
755
+ ALLOC_ARRAY(wo, to_pack.nr_objects);
756
+ wo_end = 0;
757
+
758
+ compute_layer_order(wo, &wo_end);
759
760
if (wo_end != to_pack.nr_objects)
761
die("ordered %u objects, expected %"PRIu32, wo_end, to_pack.nr_objects);