Skip to content

Commit 373c67d

Browse files
peffgitster
authored andcommitted
pack-objects: turn off bitmaps when skipping objects
The pack bitmap format requires that we have a single bit for each object in the pack, and that each object's bitmap represents its complete set of reachable objects. Therefore we have no way to represent the bitmap of an object which references objects outside the pack. We notice this problem while generating the bitmaps, as we try to find the offset of a particular object and realize that we do not have it. In this case we die, and neither the bitmap nor the pack is generated. This is correct, but perhaps a little unfriendly. If you have bitmaps turned on in the config, many repacks will fail which would otherwise succeed. E.g., incremental repacks, repacks with "-l" when you have alternates, ".keep" files. Instead, this patch notices early that we are omitting some objects from the pack and turns off bitmaps (with a warning). Note that this is not strictly correct, as it's possible that the object being omitted is not reachable from any other object in the pack. In practice, this is almost never the case, and there are two advantages to doing it this way: 1. The code is much simpler, as we do not have to cleanly abort the bitmap-generation process midway through. 2. We do not waste time partially generating bitmaps only to find out that some object deep in the history is not being packed. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6b5b3a2 commit 373c67d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

builtin/pack-objects.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,10 @@ static void create_object_entry(const unsigned char *sha1,
10001000
entry->no_try_delta = no_try_delta;
10011001
}
10021002

1003+
static const char no_closure_warning[] = N_(
1004+
"disabling bitmap writing, as some objects are not being packed"
1005+
);
1006+
10031007
static int add_object_entry(const unsigned char *sha1, enum object_type type,
10041008
const char *name, int exclude)
10051009
{
@@ -1010,8 +1014,14 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
10101014
if (have_duplicate_entry(sha1, exclude, &index_pos))
10111015
return 0;
10121016

1013-
if (!want_object_in_pack(sha1, exclude, &found_pack, &found_offset))
1017+
if (!want_object_in_pack(sha1, exclude, &found_pack, &found_offset)) {
1018+
/* The pack is missing an object, so it will not have closure */
1019+
if (write_bitmap_index) {
1020+
warning(_(no_closure_warning));
1021+
write_bitmap_index = 0;
1022+
}
10141023
return 0;
1024+
}
10151025

10161026
create_object_entry(sha1, type, pack_name_hash(name),
10171027
exclude, name && no_try_delta(name),

t/t5310-pack-bitmaps.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ test_expect_success 'fetch (partial bitmap)' '
9191

9292
test_expect_success 'incremental repack cannot create bitmaps' '
9393
test_commit more-1 &&
94-
test_must_fail git repack -d
94+
find .git/objects/pack -name "*.bitmap" >expect &&
95+
git repack -d &&
96+
find .git/objects/pack -name "*.bitmap" >actual &&
97+
test_cmp expect actual
9598
'
9699

97100
test_expect_success 'incremental repack can disable bitmaps' '

0 commit comments

Comments
 (0)