multi-pack-index: respect repack.packKeptObjects=false
When selecting a batch of pack-files to repack in the "git multi-pack-index repack" command, Git should respect the repack.packKeptObjects config option. When false, this option says that the pack-files with an associated ".keep" file should not be repacked. This config value is "false" by default. There are two cases for selecting a batch of objects. The first is the case where the input batch-size is zero, which specifies "repack everything". The second is with a non-zero batch size, which selects pack-files using a greedy selection criteria. Both of these cases are updated and tested. Reported-by: Son Luong Ngoc <sluongng@gmail.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
May 10, 2020 at 16:07 UTC
3ce4ca0a56afd4b67105dd580948973cecc79162
3 files changed
+51
-5
Documentation/git-multi-pack-index.txt
+3
@@ -56,6 +56,9 @@ repack::
56
file is created, rewrite the multi-pack-index to reference the
57
new pack-file. A later run of 'git multi-pack-index expire' will
58
delete the pack-files that were part of this batch.
59
++
60
+If `repack.packKeptObjects` is `false`, then any pack-files with an
61
+associated `.keep` file will not be selected for the batch to repack.
62
63
64
EXAMPLES
midx.c
+21
-5
@@ -1293,15 +1293,26 @@ static int compare_by_mtime(const void *a_, const void *b_)
1293
return 0;
1294
}
1295
1296
-static int fill_included_packs_all(struct multi_pack_index *m,
1296
+static int fill_included_packs_all(struct repository *r,
1297
+ struct multi_pack_index *m,
1298
unsigned char *include_pack)
1299
{
1299
- uint32_t i;
1300
+ uint32_t i, count = 0;
1301
+ int pack_kept_objects = 0;
1302
+
1303
+ repo_config_get_bool(r, "repack.packkeptobjects", &pack_kept_objects);
1304
+
1305
+ for (i = 0; i < m->num_packs; i++) {
1306
+ if (prepare_midx_pack(r, m, i))
1307
+ continue;
1308
+ if (!pack_kept_objects && m->packs[i]->pack_keep)
1309
+ continue;
1310
1301
- for (i = 0; i < m->num_packs; i++)
1311
include_pack[i] = 1;
1312
+ count++;
1313
+ }
1314
1304
- return m->num_packs < 2;
1315
+ return count < 2;
1316
}
1317
1318
static int fill_included_packs_batch(struct repository *r,
@@ -1312,6 +1323,9 @@ static int fill_included_packs_batch(struct repository *r,
1323
uint32_t i, packs_to_repack;
1324
size_t total_size;
1325
struct repack_info *pack_info = xcalloc(m->num_packs, sizeof(struct repack_info));
1326
+ int pack_kept_objects = 0;
1327
+
1328
+ repo_config_get_bool(r, "repack.packkeptobjects", &pack_kept_objects);
1329
1330
for (i = 0; i < m->num_packs; i++) {
1331
pack_info[i].pack_int_id = i;
@@ -1338,6 +1352,8 @@ static int fill_included_packs_batch(struct repository *r,
1352
1353
if (!p)
1354
continue;
1355
+ if (!pack_kept_objects && p->pack_keep)
1356
+ continue;
1357
if (open_pack_index(p) || !p->num_objects)
1358
continue;
1359
@@ -1386,7 +1402,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
1402
if (batch_size) {
1403
if (fill_included_packs_batch(r, m, include_pack, batch_size))
1404
goto cleanup;
1389
- } else if (fill_included_packs_all(m, include_pack))
1405
+ } else if (fill_included_packs_all(r, m, include_pack))
1406
goto cleanup;
1407
1408
repo_config_get_bool(r, "repack.usedeltabaseoffset", &delta_base_offset);
t/t5319-multi-pack-index.sh
+27
@@ -538,6 +538,33 @@ test_expect_success 'repack with minimum size does not alter existing packs' '
538
)
539
'
540
541
+test_expect_success 'repack respects repack.packKeptObjects=false' '
542
+ test_when_finished rm -f dup/.git/objects/pack/*keep &&
543
+ (
544
+ cd dup &&
545
+ ls .git/objects/pack/*idx >idx-list &&
546
+ test_line_count = 5 idx-list &&
547
+ ls .git/objects/pack/*.pack | sed "s/\.pack/.keep/" >keep-list &&
548
+ test_line_count = 5 keep-list &&
549
+ for keep in $(cat keep-list)
550
+ do
551
+ touch $keep || return 1
552
+ done &&
553
+ git multi-pack-index repack --batch-size=0 &&
554
+ ls .git/objects/pack/*idx >idx-list &&
555
+ test_line_count = 5 idx-list &&
556
+ test-tool read-midx .git/objects | grep idx >midx-list &&
557
+ test_line_count = 5 midx-list &&
558
+ THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | sed -n 3p) &&
559
+ BATCH_SIZE=$((THIRD_SMALLEST_SIZE + 1)) &&
560
+ git multi-pack-index repack --batch-size=$BATCH_SIZE &&
561
+ ls .git/objects/pack/*idx >idx-list &&
562
+ test_line_count = 5 idx-list &&
563
+ test-tool read-midx .git/objects | grep idx >midx-list &&
564
+ test_line_count = 5 midx-list
565
+ )
566
+'
567
+
568
test_expect_success 'repack creates a new pack' '
569
(
570
cd dup &&