git/odb/pack: implement *ChainBase for unpacking base components #2551
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 provides the first of two implementations of the
Chain
interface:*ChainBase
handles the first kind of component of the delta-base chains found in Git packfiles: the base. A base encodes some base object's data in a zlib-compressed format, to which delta operations can be applied (patched).Since the
*ChainBase
must handle zlib-compressed data, we run into the challenge of converting themmap(2)
'd*os.File
(given as anio.ReaderAt
) into anio.Reader
that packagecompress/zlib
can read from. This is done using the*OffsetReaderAt
type, which implements theio.Reader
interface by encoding an offset into anio.ReaderAt
, and updating the offset each time a read is performed.Because we cannot readily determine the length of the compressed object data in a packfile, we must take into account the greedy behavior from package
compress/zlib
. One approach to dealing with this is to find the next object, and limit reads from going beyond that. However, since we are not sharing*OffsetReaderAt
instances with more than oneChain
implementation, we can read past the end of the compressed data, andcompress/zlib
will simply ignore the extraneous bytes. Here is an example./cc @git-lfs/core @peff
/cc #2415