Skip to content

Commit 6baba94

Browse files
committed
Merge branch 'sn/midx-repack-with-config'
"git multi-pack-index repack" has been taught to honor some repack.* configuration variables. * sn/midx-repack-with-config: multi-pack-index: respect repack.packKeptObjects=false midx: teach "git multi-pack-index repack" honor "git repack" configurations
2 parents 4b1e5e5 + 3ce4ca0 commit 6baba94

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-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: 37 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

@@ -1370,6 +1386,14 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
13701386
struct strbuf base_name = STRBUF_INIT;
13711387
struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
13721388

1389+
/*
1390+
* When updating the default for these configuration
1391+
* variables in builtin/repack.c, these must be adjusted
1392+
* to match.
1393+
*/
1394+
int delta_base_offset = 1;
1395+
int use_delta_islands = 0;
1396+
13731397
if (!m)
13741398
return 0;
13751399

@@ -1378,15 +1402,23 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
13781402
if (batch_size) {
13791403
if (fill_included_packs_batch(r, m, include_pack, batch_size))
13801404
goto cleanup;
1381-
} else if (fill_included_packs_all(m, include_pack))
1405+
} else if (fill_included_packs_all(r, m, include_pack))
13821406
goto cleanup;
13831407

1408+
repo_config_get_bool(r, "repack.usedeltabaseoffset", &delta_base_offset);
1409+
repo_config_get_bool(r, "repack.usedeltaislands", &use_delta_islands);
1410+
13841411
argv_array_push(&cmd.args, "pack-objects");
13851412

13861413
strbuf_addstr(&base_name, object_dir);
13871414
strbuf_addstr(&base_name, "/pack/pack");
13881415
argv_array_push(&cmd.args, base_name.buf);
13891416

1417+
if (delta_base_offset)
1418+
argv_array_push(&cmd.args, "--delta-base-offset");
1419+
if (use_delta_islands)
1420+
argv_array_push(&cmd.args, "--delta-islands");
1421+
13901422
if (flags & MIDX_PROGRESS)
13911423
argv_array_push(&cmd.args, "--progress");
13921424
else

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)