MCPcopy Index your code
hub / github.com/git/git / try_partial_reuse

Function try_partial_reuse

pack-bitmap.c:2263–2356  ·  view source on GitHub ↗

* -1 means "stop trying further objects"; 0 means we may or may not have * reused, but you can keep feeding bits. */

Source from the content-addressed store, hash-verified

2261 * reused, but you can keep feeding bits.
2262 */
2263static int try_partial_reuse(struct bitmap_index *bitmap_git,
2264 struct bitmapped_pack *pack,
2265 size_t bitmap_pos,
2266 uint32_t pack_pos,
2267 off_t offset,
2268 struct bitmap *reuse,
2269 struct pack_window **w_curs)
2270{
2271 off_t delta_obj_offset;
2272 enum object_type type;
2273 size_t size;
2274
2275 if (pack_pos >= pack->p->num_objects)
2276 return -1; /* not actually in the pack */
2277
2278 delta_obj_offset = offset;
2279 type = unpack_object_header(pack->p, w_curs, &offset, &size);
2280 if (type < 0)
2281 return -1; /* broken packfile, punt */
2282
2283 if (type == OBJ_REF_DELTA || type == OBJ_OFS_DELTA) {
2284 off_t base_offset;
2285 uint32_t base_pos;
2286 uint32_t base_bitmap_pos;
2287
2288 /*
2289 * Find the position of the base object so we can look it up
2290 * in our bitmaps. If we can't come up with an offset, or if
2291 * that offset is not in the revidx, the pack is corrupt.
2292 * There's nothing we can do, so just punt on this object,
2293 * and the normal slow path will complain about it in
2294 * more detail.
2295 */
2296 base_offset = get_delta_base(pack->p, w_curs, &offset, type,
2297 delta_obj_offset);
2298 if (!base_offset)
2299 return 0;
2300
2301 offset_to_pack_pos(pack->p, base_offset, &base_pos);
2302
2303 if (bitmap_is_midx(bitmap_git)) {
2304 /*
2305 * Cross-pack deltas are rejected for now, but could
2306 * theoretically be supported in the future.
2307 *
2308 * We would need to ensure that we're sending both
2309 * halves of the delta/base pair, regardless of whether
2310 * or not the two cross a pack boundary. If they do,
2311 * then we must convert the delta to an REF_DELTA to
2312 * refer back to the base in the other pack.
2313 * */
2314 if (midx_pair_to_pack_pos(bitmap_git->midx,
2315 pack->pack_int_id,
2316 base_offset,
2317 &base_bitmap_pos) < 0) {
2318 return 0;
2319 }
2320 } else {

Callers 1

Calls 7

unpack_object_headerFunction · 0.85
get_delta_baseFunction · 0.85
offset_to_pack_posFunction · 0.85
bitmap_is_midxFunction · 0.85
midx_pair_to_pack_posFunction · 0.85
bitmap_getFunction · 0.85
bitmap_setFunction · 0.85

Tested by

no test coverage detected