Skip to content

Commit 7328482

Browse files
Eric Wonggitster
Eric Wong
authored andcommitted
repack: disable bitmaps-by-default if .keep files exist
Bitmaps aren't useful with multiple packs, and users with .keep files ended up with redundant packs when bitmaps got enabled by default in bare repos. So detect when .keep files exist and stop enabling bitmaps by default in that case. Wasteful (but otherwise harmless) race conditions with .keep files documented by Jeff King still apply and there's a chance we'd still end up with redundant data on the FS: https://public-inbox.org/git/[email protected]/ v2: avoid subshell in test case, be multi-index aware Fixes: 36eba03 ("repack: enable bitmaps by default on bare repos") Signed-off-by: Eric Wong <[email protected]> Helped-by: Jeff King <[email protected]> Reported-by: Janos Farkas <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d431660 commit 7328482

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

builtin/repack.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ static void remove_pack_on_signal(int signo)
8989
raise(signo);
9090
}
9191

92+
static int has_pack_keep_file(void)
93+
{
94+
struct packed_git *p;
95+
96+
for (p = get_all_packs(the_repository); p; p = p->next) {
97+
if (p->pack_keep)
98+
return 1;
99+
}
100+
return 0;
101+
}
102+
92103
/*
93104
* Adds all packs hex strings to the fname list, which do not
94105
* have a corresponding .keep file. These packs are not to
@@ -343,9 +354,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
343354
(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE)))
344355
die(_("--keep-unreachable and -A are incompatible"));
345356

346-
if (write_bitmaps < 0)
357+
if (write_bitmaps < 0) {
347358
write_bitmaps = (pack_everything & ALL_INTO_ONE) &&
348-
is_bare_repository();
359+
is_bare_repository() &&
360+
keep_pack_list.nr == 0 &&
361+
!has_pack_keep_file();
362+
}
349363
if (pack_kept_objects < 0)
350364
pack_kept_objects = write_bitmaps;
351365

t/t7700-repack.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,14 @@ test_expect_success 'bitmaps can be disabled on bare repos' '
239239
test -z "$bitmap"
240240
'
241241

242+
test_expect_success 'no bitmaps created if .keep files present' '
243+
pack=$(ls bare.git/objects/pack/*.pack) &&
244+
test_path_is_file "$pack" &&
245+
keep=${pack%.pack}.keep &&
246+
>"$keep" &&
247+
git -C bare.git repack -ad &&
248+
find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
249+
test_must_be_empty actual
250+
'
251+
242252
test_done

0 commit comments

Comments
 (0)