gitpack

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitpack reads git pack files and v2 pack indexes by ranged reads.

Index

Constants

View Source
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
)
View Source
const IdxHeadBytes = idxHead

IdxHeadBytes is the size of the header and the fanout table of a v2 index.

View Source
const MaxUnpackBytes = 64 << 20

MaxUnpackBytes bounds the inflated bytes that Unpack reads from entries and the bytes of the objects that it returns, each.

View Source
const MaxUnpackObjects = 100000

MaxUnpackObjects bounds the objects of one pack that Unpack reads.

Variables

View Source
var (
	ErrCorrupt  = errors.New("gitpack: corrupt pack or index")
	ErrTooLarge = errors.New("gitpack: object too large")
)
View Source
var ErrNotFound = errors.New("object not found")

Functions

func BuildIdx added in v0.10.0

func BuildIdx(entries []IdxEntry, packSum [20]byte) []byte

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

func BuildSize(objs []Object) int

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.

func IdxCount added in v0.10.0

func IdxCount(head []byte) (int, error)

IdxCount returns the number of objects of a v2 index from its first IdxHeadBytes bytes.

Types

type IdxEntry added in v0.10.0

type IdxEntry struct {
	Name SHA
	CRC  uint32
	Off  uint32
}

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.

func NewIdxIter added in v0.10.0

func NewIdxIter(ctx context.Context, n int, get func(ctx context.Context, off, n int64) ([]byte, error)) *IdxIter

NewIdxIter returns an iterator over the n entries of an index. get reads a range of the index, and the rest of it when n is negative.

func (*IdxIter) Next added in v0.10.0

func (it *IdxIter) Next() (SHA, int64, bool, error)

Next returns the next name and its offset in the pack, and false at the end.

type Object

type Object struct {
	Type Type
	Data []byte
}

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.

type Pack

type Pack struct {
	// contains filtered or unexported fields
}

func NewAt added in v0.10.0

func NewAt(pack ReaderAt) *Pack

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

func NewPack(idx []byte, pack ReaderAt) (*Pack, error)

NewPack checks the structure and the checksum of a v2 index before it trusts a byte of it.

func (*Pack) Bind

func (p *Pack) Bind(r ReaderAt) *Pack

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) Bytes

func (p *Pack) Bytes() int

Bytes is the size of the index that the pack keeps in memory.

func (*Pack) CachedBytes

func (p *Pack) CachedBytes() int

CachedBytes is the size of the resolved objects the pack holds.

func (*Pack) Count

func (p *Pack) Count() int

func (*Pack) Get

func (p *Pack) Get(s SHA) (Type, []byte, error)

func (*Pack) GetDepth

func (p *Pack) GetDepth(s SHA) (Type, []byte, int, error)

GetDepth is Get that also returns the length of the delta chain that produced the object; zero is a whole object.

func (*Pack) Has

func (p *Pack) Has(s SHA) bool

func (*Pack) Lookup added in v0.10.0

func (p *Pack) Lookup(s SHA) (int64, bool)

Lookup returns the offset of the object s in the pack.

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.

func (*Pack) Size

func (p *Pack) Size(s SHA) (int64, Type, error)

Size returns the object size and type without inflating the whole object.

func (*Pack) Verify

func (p *Pack) Verify(ctx context.Context, idx, pack []byte) error

Verify checks that pack is the pack that the index describes and that every object hashes to its name. It resolves the objects in pack order so that each delta chain is read once, and it stops at a budget of inflated bytes or when ctx ends.

func (*Pack) WithLookup added in v0.10.0

func (p *Pack) WithLookup(f func(SHA) (int64, bool)) *Pack

WithLookup returns a view of the pack that finds a name with f. The view shares the object cache.

type ReaderAt

type ReaderAt interface {
	io.ReaderAt
	Size() int64
}

ReaderAt is the ranged-read seam over the bytes of one pack.

type SHA

type SHA [20]byte

func Build

func Build(objs []Object) (pack, idx []byte, names []SHA)

Build writes objects as a pack without deltas, and its v2 index. The returned names are the object names in the order of objs. An object that repeats an earlier one is stored once.

func Hash

func Hash(t Type, data []byte) SHA

func ParseSHA

func ParseSHA(h string) (SHA, error)

func (SHA) String

func (s SHA) String() string

type Type

type Type uint8
const (
	Commit Type = 1
	Tree   Type = 2
	Blob   Type = 3
	Tag    Type = 4
)

func ParseType

func ParseType(name string) Type

ParseType maps a type name to a Type, or 0.

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL