Skip to content

Commit e94be60

Browse files
ttaylorrgitster
authored andcommitted
midx-write.c: factor out common want_included_pack() routine
When performing a 'git multi-pack-index repack', the MIDX machinery tries to aggregate MIDX'd packs together either to (a) fill the given `--batch-size` argument, or (b) combine all packs together. In either case (using the `midx-write.c::fill_included_packs_batch()` or `midx-write.c::fill_included_packs_all()` function, respectively), we evaluate whether or not we want to repack each MIDX'd pack, according to whether or it is loadable, kept, cruft, or non-empty. Between the two `fill_included_packs_` callers, they both care about the same conditions, except for `fill_included_packs_batch()` which also cares that the pack is non-empty. We could extract two functions (say, `want_included_pack()` and a `_nonempty()` variant), but this is not necessary. For the case in `fill_included_packs_all()` which does not check the pack size, we add all of the pack's objects assuming that the pack meets all other criteria. But if the pack is empty in the first place, we add all of its zero objects, so whether or not we "accept" or "reject" it in the first place is irrelevant. This change improves the readability in both `fill_included_packs_` functions. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 748b88a commit e94be60

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

midx-write.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,24 @@ static int compare_by_mtime(const void *a_, const void *b_)
13491349
return 0;
13501350
}
13511351

1352+
static int want_included_pack(struct repository *r,
1353+
struct multi_pack_index *m,
1354+
int pack_kept_objects,
1355+
uint32_t pack_int_id)
1356+
{
1357+
struct packed_git *p;
1358+
if (prepare_midx_pack(r, m, pack_int_id))
1359+
return 0;
1360+
p = m->packs[pack_int_id];
1361+
if (!pack_kept_objects && p->pack_keep)
1362+
return 0;
1363+
if (p->is_cruft)
1364+
return 0;
1365+
if (open_pack_index(p) || !p->num_objects)
1366+
return 0;
1367+
return 1;
1368+
}
1369+
13521370
static int fill_included_packs_all(struct repository *r,
13531371
struct multi_pack_index *m,
13541372
unsigned char *include_pack)
@@ -1359,11 +1377,7 @@ static int fill_included_packs_all(struct repository *r,
13591377
repo_config_get_bool(r, "repack.packkeptobjects", &pack_kept_objects);
13601378

13611379
for (i = 0; i < m->num_packs; i++) {
1362-
if (prepare_midx_pack(r, m, i))
1363-
continue;
1364-
if (!pack_kept_objects && m->packs[i]->pack_keep)
1365-
continue;
1366-
if (m->packs[i]->is_cruft)
1380+
if (!want_included_pack(r, m, pack_kept_objects, i))
13671381
continue;
13681382

13691383
include_pack[i] = 1;
@@ -1410,13 +1424,7 @@ static int fill_included_packs_batch(struct repository *r,
14101424
struct packed_git *p = m->packs[pack_int_id];
14111425
size_t expected_size;
14121426

1413-
if (!p)
1414-
continue;
1415-
if (!pack_kept_objects && p->pack_keep)
1416-
continue;
1417-
if (p->is_cruft)
1418-
continue;
1419-
if (open_pack_index(p) || !p->num_objects)
1427+
if (!want_included_pack(r, m, pack_kept_objects, pack_int_id))
14201428
continue;
14211429

14221430
expected_size = st_mult(p->pack_size,

0 commit comments

Comments
 (0)