Skip to content

Commit

Permalink
Merge branch 'tb/bitmap-fix-pack-reuse' into next
Browse files Browse the repository at this point in the history
Code to reuse objects based on bitmap contents have been tightened
to avoid race condition even when multiple packs are involved.

* tb/bitmap-fix-pack-reuse:
  pack-bitmap.c: ensure pack validity for all reuse packs
  • Loading branch information
gitster committed Dec 21, 2024
2 parents 11a5c3d + 62b3ec8 commit 1044634
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions pack-bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
struct stat st;
char *bitmap_name = midx_bitmap_filename(midx);
int fd = git_open(bitmap_name);
uint32_t i, preferred_pack;
struct packed_git *preferred;
uint32_t i;

if (fd < 0) {
if (errno != ENOENT)
Expand Down Expand Up @@ -456,18 +455,6 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
}
}

if (midx_preferred_pack(bitmap_git->midx, &preferred_pack) < 0) {
warning(_("could not determine MIDX preferred pack"));
goto cleanup;
}

preferred = bitmap_git->midx->packs[preferred_pack];
if (!is_pack_valid(preferred)) {
warning(_("preferred pack (%s) is invalid"),
preferred->pack_name);
goto cleanup;
}

return 0;

cleanup:
Expand Down Expand Up @@ -2306,8 +2293,10 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
if (!pack.bitmap_nr)
continue;

ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
memcpy(&packs[packs_nr++], &pack, sizeof(pack));
if (is_pack_valid(pack.p)) {
ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
memcpy(&packs[packs_nr++], &pack, sizeof(pack));
}

objects_nr += pack.p->num_objects;
}
Expand Down Expand Up @@ -2341,16 +2330,22 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
pack_int_id = -1;
}

ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
packs[packs_nr].p = pack;
packs[packs_nr].pack_int_id = pack_int_id;
packs[packs_nr].bitmap_nr = pack->num_objects;
packs[packs_nr].bitmap_pos = 0;
packs[packs_nr].from_midx = bitmap_git->midx;
if (is_pack_valid(pack)) {
ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
packs[packs_nr].p = pack;
packs[packs_nr].pack_int_id = pack_int_id;
packs[packs_nr].bitmap_nr = pack->num_objects;
packs[packs_nr].bitmap_pos = 0;
packs[packs_nr].from_midx = bitmap_git->midx;
packs_nr++;
}

objects_nr = packs[packs_nr++].bitmap_nr;
objects_nr = pack->num_objects;
}

if (!packs_nr)
return;

word_alloc = objects_nr / BITS_IN_EWORD;
if (objects_nr % BITS_IN_EWORD)
word_alloc++;
Expand Down

0 comments on commit 1044634

Please sign in to comment.