]> git.ipfire.org Git - thirdparty/git.git/blame - pack-revindex.h
bitmap_position_packfile(): convert to new revindex API
[thirdparty/git.git] / pack-revindex.h
CommitLineData
3449f8c4
NP
1#ifndef PACK_REVINDEX_H
2#define PACK_REVINDEX_H
3
f33fb6e4
TB
4/**
5 * A revindex allows converting efficiently between three properties
6 * of an object within a pack:
7 *
8 * - index position: the numeric position within the list of sorted object ids
9 * found in the .idx file
10 *
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)
14 *
15 * - offset: the byte offset within the .pack file at which the object contents
16 * can be found
17 */
18
9d98bbf5
JK
19struct packed_git;
20
3449f8c4
NP
21struct revindex_entry {
22 off_t offset;
23 unsigned int nr;
24};
25
f33fb6e4
TB
26/*
27 * load_pack_revindex populates the revindex's internal data-structures for the
28 * given pack, returning zero on success and a negative value otherwise.
29 */
4828ce98 30int load_pack_revindex(struct packed_git *p);
9d98bbf5 31int find_revindex_position(struct packed_git *p, off_t ofs);
92e5c77c 32
3449f8c4
NP
33struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs);
34
f33fb6e4
TB
35/*
36 * offset_to_pack_pos converts an object offset to a pack position. This
37 * function returns zero on success, and a negative number otherwise. The
38 * parameter 'pos' is usable only on success.
39 *
40 * If the reverse index has not yet been loaded, this function loads it lazily,
41 * and returns an negative number if an error was encountered.
42 *
43 * This function runs in time O(log N) with the number of objects in the pack.
44 */
45int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos);
46
47/*
48 * pack_pos_to_index converts the given pack-relative position 'pos' by
49 * returning an index-relative position.
50 *
51 * If the reverse index has not yet been loaded, or the position is out of
52 * bounds, this function aborts.
53 *
54 * This function runs in constant time.
55 */
56uint32_t pack_pos_to_index(struct packed_git *p, uint32_t pos);
57
58/*
59 * pack_pos_to_offset converts the given pack-relative position 'pos' into a
60 * pack offset. For a pack with 'N' objects, asking for position 'N' will return
61 * the total size (in bytes) of the pack.
62 *
63 * If the reverse index has not yet been loaded, or the position is out of
64 * bounds, this function aborts.
65 *
66 * This function runs in constant time.
67 */
68off_t pack_pos_to_offset(struct packed_git *p, uint32_t pos);
69
3449f8c4 70#endif