gitpack

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 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
)

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

This section is empty.

Types

type Object

type Object struct {
	Type Type
	Data []byte
}

type Pack

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

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

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