Skip to content

Commit 92fb0db

Browse files
peffgitster
authored andcommitted
pack-objects: add checks for duplicate objects
Additional checks are added in have_duplicate_entry() and obj_is_packed() to avoid duplicate objects in the reuse bitmap. It was probably buggy to not have such a check before. Git as a client would never both asks for a tag by sha1 and specify "include-tag", but libgit2 will, so a libgit2 client cloning from a Git server would trigger the bug. If a client both asks for a tag by sha1 and specifies "include-tag", we may end up including the tag in the reuse bitmap (due to the first thing), and then later adding it to the packlist (due to the second). This results in duplicate objects in the pack, which git chokes on. We should notice that we are already including it when doing the include-tag portion, and avoid adding it to the packlist. The simplest place to fix this is right in add_ref_tag(), where we could avoid peeling the tag at all if we know that we are already including it. However, this pushes the check instead into have_duplicate_entry(). This fixes not only this case, but also means that we cannot have any similar problems lurking in other code. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb514de commit 92fb0db

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

builtin/pack-objects.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,10 @@ static int have_duplicate_entry(const struct object_id *oid,
11281128
{
11291129
struct object_entry *entry;
11301130

1131+
if (reuse_packfile_bitmap &&
1132+
bitmap_walk_contains(bitmap_git, reuse_packfile_bitmap, oid))
1133+
return 1;
1134+
11311135
entry = packlist_find(&to_pack, oid, index_pos);
11321136
if (!entry)
11331137
return 0;
@@ -2697,7 +2701,9 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
26972701

26982702
static int obj_is_packed(const struct object_id *oid)
26992703
{
2700-
return !!packlist_find(&to_pack, oid, NULL);
2704+
return packlist_find(&to_pack, oid, NULL) ||
2705+
(reuse_packfile_bitmap &&
2706+
bitmap_walk_contains(bitmap_git, reuse_packfile_bitmap, oid));
27012707
}
27022708

27032709
static void add_tag_chain(const struct object_id *oid)

0 commit comments

Comments
 (0)