Skip to content

Commit 3ce4ca0

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e11d86d commit 3ce4ca0

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

Documentation/git-multi-pack-index.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ repack::
5656
file is created, rewrite the multi-pack-index to reference the
5757
new pack-file. A later run of 'git multi-pack-index expire' will
5858
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.
5962

6063

6164
EXAMPLES

midx.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,15 +1293,26 @@ static int compare_by_mtime(const void *a_, const void *b_)
12931293
return 0;
12941294
}
12951295

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,
12971298
unsigned char *include_pack)
12981299
{
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;
13001310

1301-
for (i = 0; i < m->num_packs; i++)
13021311
include_pack[i] = 1;
1312+
count++;
1313+
}
13031314

1304-
return m->num_packs < 2;
1315+
return count < 2;
13051316
}
13061317

13071318
static int fill_included_packs_batch(struct repository *r,
@@ -1312,6 +1323,9 @@ static int fill_included_packs_batch(struct repository *r,
13121323
uint32_t i, packs_to_repack;
13131324
size_t total_size;
13141325
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);
13151329

13161330
for (i = 0; i < m->num_packs; i++) {
13171331
pack_info[i].pack_int_id = i;
@@ -1338,6 +1352,8 @@ static int fill_included_packs_batch(struct repository *r,
13381352

13391353
if (!p)
13401354
continue;
1355+
if (!pack_kept_objects && p->pack_keep)
1356+
continue;
13411357
if (open_pack_index(p) || !p->num_objects)
13421358
continue;
13431359

@@ -1386,7 +1402,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
13861402
if (batch_size) {
13871403
if (fill_included_packs_batch(r, m, include_pack, batch_size))
13881404
goto cleanup;
1389-
} else if (fill_included_packs_all(m, include_pack))
1405+
} else if (fill_included_packs_all(r, m, include_pack))
13901406
goto cleanup;
13911407

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

t/t5319-multi-pack-index.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,33 @@ test_expect_success 'repack with minimum size does not alter existing packs' '
538538
)
539539
'
540540

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+
541568
test_expect_success 'repack creates a new pack' '
542569
(
543570
cd dup &&

0 commit comments

Comments
 (0)