MCPcopy Create free account
hub / github.com/git/git / write_reused_pack

Function write_reused_pack

builtin/pack-objects.c:1240–1306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1238}
1239
1240static void write_reused_pack(struct bitmapped_pack *reuse_packfile,
1241 struct hashfile *f)
1242{
1243 size_t i = reuse_packfile->bitmap_pos / BITS_IN_EWORD;
1244 uint32_t offset;
1245 off_t pack_start = hashfile_total(f) - sizeof(struct pack_header);
1246 struct pack_window *w_curs = NULL;
1247
1248 if (allow_ofs_delta)
1249 i = write_reused_pack_verbatim(reuse_packfile, f, &w_curs);
1250
1251 for (; i < reuse_packfile_bitmap->word_alloc; ++i) {
1252 eword_t word = reuse_packfile_bitmap->words[i];
1253 size_t pos = (i * BITS_IN_EWORD);
1254
1255 for (offset = 0; offset < BITS_IN_EWORD; ++offset) {
1256 uint32_t pack_pos;
1257 if ((word >> offset) == 0)
1258 break;
1259
1260 offset += ewah_bit_ctz64(word >> offset);
1261 if (pos + offset < reuse_packfile->bitmap_pos)
1262 continue;
1263 if (pos + offset >= reuse_packfile->bitmap_pos + reuse_packfile->bitmap_nr)
1264 goto done;
1265
1266 if (reuse_packfile->bitmap_pos) {
1267 /*
1268 * When doing multi-pack reuse on a
1269 * non-preferred pack, translate bit positions
1270 * from the MIDX pseudo-pack order back to their
1271 * pack-relative positions before attempting
1272 * reuse.
1273 */
1274 struct multi_pack_index *m = reuse_packfile->from_midx;
1275 uint32_t midx_pos;
1276 off_t pack_ofs;
1277
1278 if (!m)
1279 BUG("non-zero bitmap position without MIDX");
1280
1281 midx_pos = pack_pos_to_midx(m, pos + offset);
1282 pack_ofs = nth_midxed_offset(m, midx_pos);
1283
1284 if (offset_to_pack_pos(reuse_packfile->p,
1285 pack_ofs, &pack_pos) < 0)
1286 BUG("could not find expected object at offset %"PRIuMAX" in pack %s",
1287 (uintmax_t)pack_ofs,
1288 pack_basename(reuse_packfile->p));
1289 } else {
1290 /*
1291 * Can use bit positions directly, even for MIDX
1292 * bitmaps. See comment in try_partial_reuse()
1293 * for why.
1294 */
1295 pack_pos = pos + offset;
1296 }
1297

Callers 1

write_pack_fileFunction · 0.85

Calls 10

hashfile_totalFunction · 0.85
ewah_bit_ctz64Function · 0.85
pack_pos_to_midxFunction · 0.85
nth_midxed_offsetFunction · 0.85
offset_to_pack_posFunction · 0.85
pack_basenameFunction · 0.85
write_reused_pack_oneFunction · 0.85
display_progressFunction · 0.85
unuse_packFunction · 0.85

Tested by

no test coverage detected