Skip to content

Commit a08ebf8

Browse files
committed
Merge branch 'tb/bitmap-fix-pack-reuse'
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
2 parents 8650022 + 62b3ec8 commit a08ebf8

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

pack-bitmap.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
398398
struct stat st;
399399
char *bitmap_name = midx_bitmap_filename(midx);
400400
int fd = git_open(bitmap_name);
401-
uint32_t i, preferred_pack;
402-
struct packed_git *preferred;
401+
uint32_t i;
403402

404403
if (fd < 0) {
405404
if (errno != ENOENT)
@@ -456,18 +455,6 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
456455
}
457456
}
458457

459-
if (midx_preferred_pack(bitmap_git->midx, &preferred_pack) < 0) {
460-
warning(_("could not determine MIDX preferred pack"));
461-
goto cleanup;
462-
}
463-
464-
preferred = bitmap_git->midx->packs[preferred_pack];
465-
if (!is_pack_valid(preferred)) {
466-
warning(_("preferred pack (%s) is invalid"),
467-
preferred->pack_name);
468-
goto cleanup;
469-
}
470-
471458
return 0;
472459

473460
cleanup:
@@ -2306,8 +2293,10 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
23062293
if (!pack.bitmap_nr)
23072294
continue;
23082295

2309-
ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
2310-
memcpy(&packs[packs_nr++], &pack, sizeof(pack));
2296+
if (is_pack_valid(pack.p)) {
2297+
ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
2298+
memcpy(&packs[packs_nr++], &pack, sizeof(pack));
2299+
}
23112300

23122301
objects_nr += pack.p->num_objects;
23132302
}
@@ -2341,16 +2330,22 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
23412330
pack_int_id = -1;
23422331
}
23432332

2344-
ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
2345-
packs[packs_nr].p = pack;
2346-
packs[packs_nr].pack_int_id = pack_int_id;
2347-
packs[packs_nr].bitmap_nr = pack->num_objects;
2348-
packs[packs_nr].bitmap_pos = 0;
2349-
packs[packs_nr].from_midx = bitmap_git->midx;
2333+
if (is_pack_valid(pack)) {
2334+
ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
2335+
packs[packs_nr].p = pack;
2336+
packs[packs_nr].pack_int_id = pack_int_id;
2337+
packs[packs_nr].bitmap_nr = pack->num_objects;
2338+
packs[packs_nr].bitmap_pos = 0;
2339+
packs[packs_nr].from_midx = bitmap_git->midx;
2340+
packs_nr++;
2341+
}
23502342

2351-
objects_nr = packs[packs_nr++].bitmap_nr;
2343+
objects_nr = pack->num_objects;
23522344
}
23532345

2346+
if (!packs_nr)
2347+
return;
2348+
23542349
word_alloc = objects_nr / BITS_IN_EWORD;
23552350
if (objects_nr % BITS_IN_EWORD)
23562351
word_alloc++;

0 commit comments

Comments
 (0)