1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-06 21:36:12 +02:00
git/pack-revindex.h
Taylor Blau 8389855a9b pack-revindex: remove unused 'find_revindex_position()'
Now that all 'find_revindex_position()' callers have been removed (and
converted to the more descriptive 'offset_to_pack_pos()'), it is almost
safe to get rid of 'find_revindex_position()' entirely. Almost, except
for the fact that 'offset_to_pack_pos()' calls
'find_revindex_position()'.

Inline 'find_revindex_position()' into 'offset_to_pack_pos()', and
then remove 'find_revindex_position()' entirely.

This is a straightforward refactoring with one minor snag.
'offset_to_pack_pos()' used to load the index before calling
'find_revindex_position()'. That means that by the time
'find_revindex_position()' starts executing, 'p->num_objects' can be
safely read. After inlining, be careful to not read 'p->num_objects'
until _after_ 'load_pack_revindex()' (which loads the index as a
side-effect) has been called.

Another small fix that is included is converting the upper- and
lower-bounds to be unsigned's instead of ints. This dates back to
92e5c77c37 (revindex: export new APIs, 2013-10-24)--ironically, the last
time we introduced new APIs here--but this unifies the types.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-13 21:53:48 -08:00

68 lines
2.1 KiB
C

#ifndef PACK_REVINDEX_H
#define PACK_REVINDEX_H
/**
* A revindex allows converting efficiently between three properties
* of an object within a pack:
*
* - index position: the numeric position within the list of sorted object ids
* found in the .idx file
*
* - pack position: the numeric position within the list of objects in their
* order within the actual .pack file (i.e., 0 is the first object in the
* .pack, 1 is the second, and so on)
*
* - offset: the byte offset within the .pack file at which the object contents
* can be found
*/
struct packed_git;
struct revindex_entry {
off_t offset;
unsigned int nr;
};
/*
* load_pack_revindex populates the revindex's internal data-structures for the
* given pack, returning zero on success and a negative value otherwise.
*/
int load_pack_revindex(struct packed_git *p);
/*
* offset_to_pack_pos converts an object offset to a pack position. This
* function returns zero on success, and a negative number otherwise. The
* parameter 'pos' is usable only on success.
*
* If the reverse index has not yet been loaded, this function loads it lazily,
* and returns an negative number if an error was encountered.
*
* This function runs in time O(log N) with the number of objects in the pack.
*/
int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos);
/*
* pack_pos_to_index converts the given pack-relative position 'pos' by
* returning an index-relative position.
*
* If the reverse index has not yet been loaded, or the position is out of
* bounds, this function aborts.
*
* This function runs in constant time.
*/
uint32_t pack_pos_to_index(struct packed_git *p, uint32_t pos);
/*
* pack_pos_to_offset converts the given pack-relative position 'pos' into a
* pack offset. For a pack with 'N' objects, asking for position 'N' will return
* the total size (in bytes) of the pack.
*
* If the reverse index has not yet been loaded, or the position is out of
* bounds, this function aborts.
*
* This function runs in constant time.
*/
off_t pack_pos_to_offset(struct packed_git *p, uint32_t pos);
#endif