Skip to content

Commit f64ba53

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c8d521f commit f64ba53

File tree

1 file changed

+50
-40
lines changed

1 file changed

+50
-40
lines changed

builtin/pack-objects.c

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -667,48 +667,15 @@ static void add_family_to_write_order(struct object_entry **wo,
667667
add_descendants_to_write_order(wo, endp, root);
668668
}
669669

670-
static struct object_entry **compute_write_order(void)
670+
static void compute_layer_order(struct object_entry **wo, unsigned int *wo_end)
671671
{
672-
unsigned int i, wo_end, last_untagged;
673-
674-
struct object_entry **wo;
672+
unsigned int i, last_untagged;
675673
struct object_entry *objects = to_pack.objects;
676674

677675
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++) {
709676
if (objects[i].tagged)
710677
break;
711-
add_to_write_order(wo, &wo_end, &objects[i]);
678+
add_to_write_order(wo, wo_end, &objects[i]);
712679
}
713680
last_untagged = i;
714681

@@ -717,7 +684,7 @@ static struct object_entry **compute_write_order(void)
717684
*/
718685
for (; i < to_pack.nr_objects; i++) {
719686
if (objects[i].tagged)
720-
add_to_write_order(wo, &wo_end, &objects[i]);
687+
add_to_write_order(wo, wo_end, &objects[i]);
721688
}
722689

723690
/*
@@ -727,7 +694,7 @@ static struct object_entry **compute_write_order(void)
727694
if (oe_type(&objects[i]) != OBJ_COMMIT &&
728695
oe_type(&objects[i]) != OBJ_TAG)
729696
continue;
730-
add_to_write_order(wo, &wo_end, &objects[i]);
697+
add_to_write_order(wo, wo_end, &objects[i]);
731698
}
732699

733700
/*
@@ -736,16 +703,59 @@ static struct object_entry **compute_write_order(void)
736703
for (i = last_untagged; i < to_pack.nr_objects; i++) {
737704
if (oe_type(&objects[i]) != OBJ_TREE)
738705
continue;
739-
add_to_write_order(wo, &wo_end, &objects[i]);
706+
add_to_write_order(wo, wo_end, &objects[i]);
740707
}
741708

742709
/*
743710
* Finally all the rest in really tight order
744711
*/
745712
for (i = last_untagged; i < to_pack.nr_objects; i++) {
746713
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]);
748715
}
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);
749759

750760
if (wo_end != to_pack.nr_objects)
751761
die("ordered %u objects, expected %"PRIu32, wo_end, to_pack.nr_objects);

0 commit comments

Comments
 (0)