Skip to content

Commit 5186134

Browse files
pks-tttaylorr
authored andcommitted
repack: fix generating multi-pack-index with only non-local packs
When writing the multi-pack-index with geometric repacking we will add all packfiles to the index that are part of the geometric sequence. This can potentially also include packfiles borrowed from an alternate object directory. But given that a multi-pack-index can only ever include packs that are part of the main object database this does not make much sense whatsoever. In the edge case where all packfiles are contained in the alternate object database and the local repository has none itself this bug can cause us to invoke git-multi-pack-index(1) with only non-local packfiles that it ultimately cannot find. This causes it to return an error and thus causes the geometric repack to fail. Fix the code to skip non-local packfiles. Co-authored-by: Taylor Blau <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d74a23 commit 5186134

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

builtin/repack.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,17 @@ static void midx_included_packs(struct string_list *include,
570570
for (i = geometry->split; i < geometry->pack_nr; i++) {
571571
struct packed_git *p = geometry->pack[i];
572572

573+
/*
574+
* The multi-pack index never refers to packfiles part
575+
* of an alternate object database, so we skip these.
576+
* While git-multi-pack-index(1) would silently ignore
577+
* them anyway, this allows us to skip executing the
578+
* command completely when we have only non-local
579+
* packfiles.
580+
*/
581+
if (!p->pack_local)
582+
continue;
583+
573584
strbuf_addstr(&buf, pack_basename(p));
574585
strbuf_strip_suffix(&buf, ".pack");
575586
strbuf_addstr(&buf, ".idx");

t/t7703-repack-geometric.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,27 @@ test_expect_success '--geometric --write-midx with packfiles in main and alterna
313313
test_cmp expect actual
314314
'
315315

316+
test_expect_success '--geometric --with-midx with no local objects' '
317+
test_when_finished "rm -fr shared member" &&
318+
319+
# Create a repository with a single packfile that acts as alternate
320+
# object database.
321+
git init shared &&
322+
test_commit -C shared "shared-objects" &&
323+
git -C shared repack -ad &&
324+
325+
# Create a second repository linked to the first one and perform a
326+
# geometric repack on it.
327+
git clone --shared shared member &&
328+
git -C member repack --geometric 2 --write-midx 2>err &&
329+
test_must_be_empty err &&
330+
331+
# Assert that we wrote neither a new packfile nor a multi-pack-index.
332+
# We should not have a packfile because the single packfile in the
333+
# alternate object database does not invalidate the geometric sequence.
334+
# And we should not have a multi-pack-index because these only index
335+
# local packfiles, and there are none.
336+
test_dir_is_empty member/$packdir
337+
'
338+
316339
test_done

0 commit comments

Comments
 (0)