Skip to content

Commit 861248b

Browse files
pks-tgitster
authored andcommitted
repack-geometry: extract function to compute repacking split
We're about to add a second caller that wants to compute the repacking split for a set of packfiles. Split out the function that computes this split to prepare for that. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0cd306e commit 861248b

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

repack-geometry.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,32 @@ void pack_geometry_init(struct pack_geometry *geometry,
7878
strbuf_release(&buf);
7979
}
8080

81-
void pack_geometry_split(struct pack_geometry *geometry)
81+
static uint32_t compute_pack_geometry_split(struct packed_git **pack, size_t pack_nr,
82+
int split_factor)
8283
{
8384
uint32_t i;
8485
uint32_t split;
8586
off_t total_size = 0;
8687

87-
if (!geometry->pack_nr) {
88-
geometry->split = geometry->pack_nr;
89-
return;
90-
}
88+
if (!pack_nr)
89+
return 0;
9190

9291
/*
9392
* First, count the number of packs (in descending order of size) which
9493
* already form a geometric progression.
9594
*/
96-
for (i = geometry->pack_nr - 1; i > 0; i--) {
97-
struct packed_git *ours = geometry->pack[i];
98-
struct packed_git *prev = geometry->pack[i - 1];
95+
for (i = pack_nr - 1; i > 0; i--) {
96+
struct packed_git *ours = pack[i];
97+
struct packed_git *prev = pack[i - 1];
9998

100-
if (unsigned_mult_overflows(geometry->split_factor,
99+
if (unsigned_mult_overflows(split_factor,
101100
pack_geometry_weight(prev)))
102101
die(_("pack %s too large to consider in geometric "
103102
"progression"),
104103
prev->pack_name);
105104

106105
if (pack_geometry_weight(ours) <
107-
geometry->split_factor * pack_geometry_weight(prev))
106+
split_factor * pack_geometry_weight(prev))
108107
break;
109108
}
110109

@@ -130,21 +129,19 @@ void pack_geometry_split(struct pack_geometry *geometry)
130129
* the geometric progression.
131130
*/
132131
for (i = 0; i < split; i++) {
133-
struct packed_git *p = geometry->pack[i];
132+
struct packed_git *p = pack[i];
134133

135134
if (unsigned_add_overflows(total_size, pack_geometry_weight(p)))
136135
die(_("pack %s too large to roll up"), p->pack_name);
137136
total_size += pack_geometry_weight(p);
138137
}
139-
for (i = split; i < geometry->pack_nr; i++) {
140-
struct packed_git *ours = geometry->pack[i];
138+
for (i = split; i < pack_nr; i++) {
139+
struct packed_git *ours = pack[i];
141140

142-
if (unsigned_mult_overflows(geometry->split_factor,
143-
total_size))
141+
if (unsigned_mult_overflows(split_factor, total_size))
144142
die(_("pack %s too large to roll up"), ours->pack_name);
145143

146-
if (pack_geometry_weight(ours) <
147-
geometry->split_factor * total_size) {
144+
if (pack_geometry_weight(ours) < split_factor * total_size) {
148145
if (unsigned_add_overflows(total_size,
149146
pack_geometry_weight(ours)))
150147
die(_("pack %s too large to roll up"),
@@ -156,7 +153,13 @@ void pack_geometry_split(struct pack_geometry *geometry)
156153
break;
157154
}
158155

159-
geometry->split = split;
156+
return split;
157+
}
158+
159+
void pack_geometry_split(struct pack_geometry *geometry)
160+
{
161+
geometry->split = compute_pack_geometry_split(geometry->pack, geometry->pack_nr,
162+
geometry->split_factor);
160163
}
161164

162165
struct packed_git *pack_geometry_preferred_pack(struct pack_geometry *geometry)

0 commit comments

Comments
 (0)