| 2308 | } |
| 2309 | |
| 2310 | int for_each_object_in_pack(struct packed_git *p, |
| 2311 | each_packed_object_fn cb, void *data, |
| 2312 | enum odb_for_each_object_flags flags) |
| 2313 | { |
| 2314 | uint32_t i; |
| 2315 | int r = 0; |
| 2316 | |
| 2317 | if (flags & ODB_FOR_EACH_OBJECT_PACK_ORDER) { |
| 2318 | if (load_pack_revindex(p->repo, p)) |
| 2319 | return -1; |
| 2320 | } |
| 2321 | |
| 2322 | for (i = 0; i < p->num_objects; i++) { |
| 2323 | uint32_t index_pos; |
| 2324 | struct object_id oid; |
| 2325 | |
| 2326 | /* |
| 2327 | * We are iterating "i" from 0 up to num_objects, but its |
| 2328 | * meaning may be different, depending on the requested output |
| 2329 | * order: |
| 2330 | * |
| 2331 | * - in object-name order, it is the same as the index order |
| 2332 | * used by nth_packed_object_id(), so we can pass it |
| 2333 | * directly |
| 2334 | * |
| 2335 | * - in pack-order, it is pack position, which we must |
| 2336 | * convert to an index position in order to get the oid. |
| 2337 | */ |
| 2338 | if (flags & ODB_FOR_EACH_OBJECT_PACK_ORDER) |
| 2339 | index_pos = pack_pos_to_index(p, i); |
| 2340 | else |
| 2341 | index_pos = i; |
| 2342 | |
| 2343 | if (nth_packed_object_id(&oid, p, index_pos) < 0) |
| 2344 | return error("unable to get sha1 of object %u in %s", |
| 2345 | index_pos, p->pack_name); |
| 2346 | |
| 2347 | r = cb(&oid, p, index_pos, data); |
| 2348 | if (r) |
| 2349 | break; |
| 2350 | } |
| 2351 | return r; |
| 2352 | } |
| 2353 | |
| 2354 | struct packfile_store_for_each_object_wrapper_data { |
| 2355 | struct packfile_store *store; |