Skip to content

Commit 440e470

Browse files
ttaylorrgitster
authored andcommitted
midx-write.c: check count of packs to repack after grouping
In both fill_included_packs_all() and fill_included_packs_batch(), we accumulate a list of packs whose contents we want to repack together, and then use that information to feed a list of objects as input to pack-objects. In both cases, the `fill_included_packs_` functions keep track of how many packs they want to repack together, and only execute pack-objects if there are at least two packs that need repacking. Having both of these functions keep track of this information themselves is not strictly necessary, since they also log which packs to repack via the `include_pack` array, so we can simply count the non-zero entries in that array after either function is done executing, reducing the overall amount of code necessary. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e94be60 commit 440e470

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

midx-write.c

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,11 +1367,11 @@ static int want_included_pack(struct repository *r,
13671367
return 1;
13681368
}
13691369

1370-
static int fill_included_packs_all(struct repository *r,
1371-
struct multi_pack_index *m,
1372-
unsigned char *include_pack)
1370+
static void fill_included_packs_all(struct repository *r,
1371+
struct multi_pack_index *m,
1372+
unsigned char *include_pack)
13731373
{
1374-
uint32_t i, count = 0;
1374+
uint32_t i;
13751375
int pack_kept_objects = 0;
13761376

13771377
repo_config_get_bool(r, "repack.packkeptobjects", &pack_kept_objects);
@@ -1381,18 +1381,15 @@ static int fill_included_packs_all(struct repository *r,
13811381
continue;
13821382

13831383
include_pack[i] = 1;
1384-
count++;
13851384
}
1386-
1387-
return count < 2;
13881385
}
13891386

1390-
static int fill_included_packs_batch(struct repository *r,
1391-
struct multi_pack_index *m,
1392-
unsigned char *include_pack,
1393-
size_t batch_size)
1387+
static void fill_included_packs_batch(struct repository *r,
1388+
struct multi_pack_index *m,
1389+
unsigned char *include_pack,
1390+
size_t batch_size)
13941391
{
1395-
uint32_t i, packs_to_repack;
1392+
uint32_t i;
13961393
size_t total_size;
13971394
struct repack_info *pack_info;
13981395
int pack_kept_objects = 0;
@@ -1418,7 +1415,6 @@ static int fill_included_packs_batch(struct repository *r,
14181415
QSORT(pack_info, m->num_packs, compare_by_mtime);
14191416

14201417
total_size = 0;
1421-
packs_to_repack = 0;
14221418
for (i = 0; total_size < batch_size && i < m->num_packs; i++) {
14231419
int pack_int_id = pack_info[i].pack_int_id;
14241420
struct packed_git *p = m->packs[pack_int_id];
@@ -1434,23 +1430,17 @@ static int fill_included_packs_batch(struct repository *r,
14341430
if (expected_size >= batch_size)
14351431
continue;
14361432

1437-
packs_to_repack++;
14381433
total_size += expected_size;
14391434
include_pack[pack_int_id] = 1;
14401435
}
14411436

14421437
free(pack_info);
1443-
1444-
if (packs_to_repack < 2)
1445-
return 1;
1446-
1447-
return 0;
14481438
}
14491439

14501440
int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, unsigned flags)
14511441
{
14521442
int result = 0;
1453-
uint32_t i;
1443+
uint32_t i, packs_to_repack = 0;
14541444
unsigned char *include_pack;
14551445
struct child_process cmd = CHILD_PROCESS_INIT;
14561446
FILE *cmd_in;
@@ -1469,10 +1459,16 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
14691459

14701460
CALLOC_ARRAY(include_pack, m->num_packs);
14711461

1472-
if (batch_size) {
1473-
if (fill_included_packs_batch(r, m, include_pack, batch_size))
1474-
goto cleanup;
1475-
} else if (fill_included_packs_all(r, m, include_pack))
1462+
if (batch_size)
1463+
fill_included_packs_batch(r, m, include_pack, batch_size);
1464+
else
1465+
fill_included_packs_all(r, m, include_pack);
1466+
1467+
for (i = 0; i < m->num_packs; i++) {
1468+
if (include_pack[i])
1469+
packs_to_repack++;
1470+
}
1471+
if (packs_to_repack <= 1)
14761472
goto cleanup;
14771473

14781474
repo_config_get_bool(r, "repack.usedeltabaseoffset", &delta_base_offset);

0 commit comments

Comments
 (0)