1 #ifndef PACK_REVINDEX_H
2 #define PACK_REVINDEX_H
5 * A revindex allows converting efficiently between three properties
6 * of an object within a pack:
8 * - index position: the numeric position within the list of sorted object ids
9 * found in the .idx file
11 * - pack position: the numeric position within the list of objects in their
12 * order within the actual .pack file (i.e., 0 is the first object in the
13 * .pack, 1 is the second, and so on)
15 * - offset: the byte offset within the .pack file at which the object contents
22 * load_pack_revindex populates the revindex's internal data-structures for the
23 * given pack, returning zero on success and a negative value otherwise.
25 int load_pack_revindex(struct packed_git
*p
);
28 * offset_to_pack_pos converts an object offset to a pack position. This
29 * function returns zero on success, and a negative number otherwise. The
30 * parameter 'pos' is usable only on success.
32 * If the reverse index has not yet been loaded, this function loads it lazily,
33 * and returns an negative number if an error was encountered.
35 * This function runs in time O(log N) with the number of objects in the pack.
37 int offset_to_pack_pos(struct packed_git
*p
, off_t ofs
, uint32_t *pos
);
40 * pack_pos_to_index converts the given pack-relative position 'pos' by
41 * returning an index-relative position.
43 * If the reverse index has not yet been loaded, or the position is out of
44 * bounds, this function aborts.
46 * This function runs in constant time.
48 uint32_t pack_pos_to_index(struct packed_git
*p
, uint32_t pos
);
51 * pack_pos_to_offset converts the given pack-relative position 'pos' into a
52 * pack offset. For a pack with 'N' objects, asking for position 'N' will return
53 * the total size (in bytes) of the pack.
55 * If the reverse index has not yet been loaded, or the position is out of
56 * bounds, this function aborts.
58 * This function runs in constant time.
60 off_t
pack_pos_to_offset(struct packed_git
*p
, uint32_t pos
);