| 2024 | } |
| 2025 | |
| 2026 | int nth_packed_object_id(struct object_id *oid, |
| 2027 | struct packed_git *p, |
| 2028 | uint32_t n) |
| 2029 | { |
| 2030 | const unsigned char *index = p->index_data; |
| 2031 | const unsigned int hashsz = p->repo->hash_algo->rawsz; |
| 2032 | if (!index) { |
| 2033 | if (open_pack_index(p)) |
| 2034 | return -1; |
| 2035 | index = p->index_data; |
| 2036 | } |
| 2037 | if (n >= p->num_objects) |
| 2038 | return -1; |
| 2039 | index += 4 * 256; |
| 2040 | if (p->index_version == 1) { |
| 2041 | oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4), |
| 2042 | p->repo->hash_algo); |
| 2043 | } else { |
| 2044 | index += 8; |
| 2045 | oidread(oid, index + st_mult(hashsz, n), p->repo->hash_algo); |
| 2046 | } |
| 2047 | return 0; |
| 2048 | } |
| 2049 | |
| 2050 | void check_pack_index_ptr(const struct packed_git *p, const void *vptr) |
| 2051 | { |