git/odb/pack: introduce '*Index' type #2420
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces the
*Index
type, and creates a new packagegit/odb/pack
to hold it.The goal of this new package is twofold:
This pull request is the first in a series of four aimed at accomplishing the first goal. Contained in this pull request is the scaffolding necessary to get us going for parsing actual index files. That means:
*Index
type, which will eventually get aEntry([]byte) uint64, error)
method to resolve object names to their offsets in a packfile.IndexVersion
type, which will learn how to parse index entries in later pull requests in this series.DecodeIndex()
function, which will learn how to use the aboveIndexVersion
instances to parse the index header, and eventually find objects in the index.To address a point raised in #2415:
This is the implementation that I pursued in this series. The idea is that, in order to save memory (and to avoid parsing objects that wont be searched for) we delay parsing index entires until they are asked for.
The next two pull requests in the series will introduce implementations of
IndexVersion.Search()
which have the following signature:Or, in other words: given an index, an object to search for, and a location to search in, return either an entry (match), a comparison value (no match), or an error otherwise.
We can use this comparison value (see:
bytes.Compare()
) in order to direct the next window of our binary search through the index file in order to produce an entry inO(log(n))
time./cc @git-lfs/core
/cc #2415