Documentation
¶
Overview ¶
Package gitpack reads git pack files and v2 pack indexes by ranged reads.
Index ¶
- Constants
- Variables
- func BuildIdx(entries []IdxEntry, packSum [20]byte) []byte
- func BuildSize(objs []Object) int
- func EncodeOfs(dist int64) []byte
- func IdxCount(head []byte) (int, error)
- type IdxEntry
- type IdxIter
- type Object
- type Pack
- func (p *Pack) Bind(r ReaderAt) *Pack
- func (p *Pack) Bytes() int
- func (p *Pack) CachedBytes() int
- func (p *Pack) Count() int
- func (p *Pack) Footprint(s SHA) (int64, error)
- func (p *Pack) Get(s SHA) (Type, []byte, error)
- func (p *Pack) GetDepth(s SHA) (Type, []byte, int, error)
- func (p *Pack) Has(s SHA) bool
- func (p *Pack) Lookup(s SHA) (int64, bool)
- func (p *Pack) OnCacheChange(f func())
- func (p *Pack) Size(s SHA) (int64, Type, error)
- func (p *Pack) Verify(ctx context.Context, idx, pack []byte) error
- func (p *Pack) WithLookup(f func(SHA) (int64, bool)) *Pack
- type ReaderAt
- type SHA
- type Span
- type Type
Constants ¶
const ( MaxObjectBytes = 16 << 20 // VerifyWorkBytes bounds the working memory of Verify: the base cache, the object kept past it, and the delta, its // base and its result while one object resolves. VerifyWorkBytes = verifyCacheBytes + 4*MaxObjectBytes )
const IdxHeadBytes = idxHead
IdxHeadBytes is the size of the header and the fanout table of a v2 index.
const MaxUnpackBytes = 64 << 20
MaxUnpackBytes bounds the inflated bytes that Unpack reads from entries and the bytes of the objects that it returns, each.
const MaxUnpackObjects = 100000
MaxUnpackObjects bounds the objects of one pack that Unpack reads.
Variables ¶
var ( ErrCorrupt = errors.New("gitpack: corrupt pack or index") ErrTooLarge = errors.New("gitpack: object too large") )
var ErrNotFound = errors.New("object not found")
Functions ¶
func BuildIdx ¶ added in v0.10.0
BuildIdx writes the v2 index of a pack from entries sorted by name. packSum is the trailer of the pack.
func BuildSize ¶ added in v0.5.0
BuildSize bounds the bytes of the pack body of objs: zlib stores an incompressible object with 5 bytes of overhead for each 64 KiB block, and each object adds a header and a zlib frame of at most 32 bytes.
Types ¶
type IdxEntry ¶ added in v0.10.0
IdxEntry is one object of a pack index: its name, the CRC-32 of its entry and its offset.
type IdxIter ¶ added in v0.10.0
type IdxIter struct {
// contains filtered or unexported fields
}
IdxIter reads the names and offsets of a v2 index in name order with ranged reads, so a caller can merge indexes of any size in bounded memory.
type Object ¶
func Unpack ¶ added in v0.6.0
func Unpack(ctx context.Context, pack []byte, external func(SHA) (Type, []byte, error)) ([]Object, error)
Unpack reads the whole pack and returns its objects with every delta resolved. The pack may be thin: external resolves the base of a ref delta that the pack does not hold.
func UnpackHeld ¶ added in v0.12.0
func UnpackHeld(ctx context.Context, pack []byte, external func(SHA) (Type, []byte, error), held func(int64) error) ([]Object, error)
UnpackHeld is Unpack that calls held with the inflated bytes that it holds, before it allocates them, each time that count grows. An error of held stops the unpack.
type Pack ¶
type Pack struct {
// contains filtered or unexported fields
}
func NewAt ¶ added in v0.10.0
NewAt returns a Pack that holds no index. It finds a name through the function that WithLookup sets, so a caller that indexes many packs in one structure reads each pack with no index of its own.
func NewPack ¶
NewPack checks the structure and the checksum of a v2 index before it trusts a byte of it.
func (*Pack) Bind ¶
Bind returns a view of the pack that reads through r and shares its index and object cache, so a request can bring its own context to the reads.
func (*Pack) CachedBytes ¶
CachedBytes is the size of the resolved objects the pack holds.
func (*Pack) Footprint ¶ added in v0.12.0
Footprint is the bytes that Get of s holds at most for its result: the size of an object that the pack stores whole, and MaxObjectBytes for a delta, because its base is inflated first and can be of any size.
func (*Pack) GetDepth ¶
GetDepth is Get that also returns the length of the delta chain that produced the object; zero is a whole object.
func (*Pack) OnCacheChange ¶
func (p *Pack) OnCacheChange(f func())
OnCacheChange sets f to run, with no lock held, after an object enters the cache. Call it before the pack is shared.
type SHA ¶
type SHA [20]byte
type Span ¶ added in v0.12.0
type Span struct {
Off, End int64
// SizeLen is the length of the type and size varint. HdrLen is the length of the whole header, which adds the
// base of a delta.
SizeLen, HdrLen int
// Delta is 0 for a whole entry, 6 for an offset delta and 7 for a reference delta.
Delta uint8
Type Type
BaseOff int64
BaseName SHA
}
Span is the extent of one entry of a pack and what its header says.