pack

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const MaxHashSize = sha256.Size

Variables

View Source
var (
	// ErrShortFanout is an error representing situations where the entire
	// fanout table could not be read, and is thus too short.
	ErrShortFanout = fmt.Errorf("git/object/pack:: too short fanout table")
)

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns whether a given error represents a missing object in the index.

Types

type Chain

type Chain interface {
	// Unpack unpacks the data encoded in the delta-base chain up to and
	// including the receiving Chain implementation by applying the
	// delta-base chain successively to itself.
	//
	// If there was an error in the delta-base resolution, i.e., the chain
	// is malformed, has a bad instruction, or there was a file read error, this
	// function is expected to return that error.
	//
	// In the event that a non-nil error is returned, it is assumed that the
	// unpacked data this function returns is malformed, or otherwise
	// corrupt.
	Unpack() ([]byte, error)

	// Type returns the type of the receiving chain element.
	Type() PackedObjectType
}

Chain represents an element in the delta-base chain corresponding to a packed object.

type ChainBase

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

ChainBase represents the "base" component of a delta-base chain.

func (*ChainBase) Type

func (b *ChainBase) Type() PackedObjectType

ChainBase returns the type of the object it encodes.

func (*ChainBase) Unpack

func (b *ChainBase) Unpack() ([]byte, error)

Unpack inflates and returns the uncompressed data encoded in the base element.

If there was any error in reading the compressed data (invalid headers, etc.), it will be returned immediately.

type ChainDelta

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

ChainDelta represents a "delta" component of a delta-base chain.

func (*ChainDelta) Type

func (d *ChainDelta) Type() PackedObjectType

Type returns the type of the base of the delta-base chain.

func (*ChainDelta) Unpack

func (d *ChainDelta) Unpack() ([]byte, error)

Unpack applies the delta operation to the previous delta-base chain, "base".

If any of the delta-base instructions were invalid, an error will be returned.

type Index

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

Index stores information about the location of objects in a corresponding packfile.

func DecodeIndex

func DecodeIndex(r io.ReaderAt, hash hash.Hash) (*Index, error)

DecodeIndex decodes an index whose underlying data is supplied by "r".

DecodeIndex reads only the header and fanout table, and does not eagerly parse index entries.

If there was an error parsing, it will be returned immediately.

func (*Index) Close

func (i *Index) Close() error

Close closes the packfile index if the underlying data stream is closeable. If so, it returns any error involved in closing.

func (*Index) Count

func (i *Index) Count() int

Count returns the number of objects in the packfile.

func (*Index) Entry

func (i *Index) Entry(name []byte) (*IndexEntry, error)

Entry returns an entry containing the offset of a given SHA1 "name".

Entry operates in O(log(n))-time in the worst case, where "n" is the number of objects that begin with the first byte of "name".

If the entry cannot be found, (nil, ErrNotFound) will be returned. If there was an error searching for or parsing an entry, it will be returned as (nil, err).

Otherwise, (entry, nil) will be returned.

type IndexEntry

type IndexEntry struct {
	// PackOffset is the number of bytes before the associated object in a
	// packfile.
	PackOffset uint64
}

IndexEntry specifies data encoded into an entry in the pack index.

type IndexVersion

type IndexVersion interface {
	// Name returns the name of the object located at the given offset "at",
	// in the Index file "idx".
	//
	// It returns an error if the object at that location could not be
	// parsed.
	Name(idx *Index, at int64) ([]byte, error)

	// Entry parses and returns the full *IndexEntry located at the offset
	// "at" in the Index file "idx".
	//
	// If there was an error parsing the IndexEntry at that location, it
	// will be returned.
	Entry(idx *Index, at int64) (*IndexEntry, error)

	// Width returns the number of bytes occupied by the header of a
	// particular index version.
	Width() int64
}

type Object

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

Object is an encapsulation of an object found in a packfile, or a packed object.

func (*Object) Type

func (o *Object) Type() PackedObjectType

Type returns the underlying object's type. Rather than the type of the front-most delta-base component, it is the type of the object itself.

func (*Object) Unpack

func (o *Object) Unpack() ([]byte, error)

Unpack resolves the delta-base chain and returns an uncompressed, unpacked, and full representation of the data encoded by this object.

If there was any error in unpacking this object, it is returned immediately, and the object's data can be assumed to be corrupt.

type OffsetReaderAt

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

OffsetReaderAt transforms an io.ReaderAt into an io.Reader by beginning and advancing all reads at the given offset.

func (*OffsetReaderAt) Read

func (r *OffsetReaderAt) Read(p []byte) (n int, err error)

Read implements io.Reader.Read by reading into the given []byte, "p" from the last known offset provided to the OffsetReaderAt.

It returns any error encountered from the underlying data stream, and advances the reader forward by "n", the number of bytes read from the underlying data stream.

type PackedObjectType

type PackedObjectType uint8

PackedObjectType is a constant type that is defined for all valid object types that a packed object can represent.

const (
	// TypeNone is the zero-value for PackedObjectType, and represents the
	// absence of a type.
	TypeNone PackedObjectType = iota
	// TypeCommit is the PackedObjectType for commit objects.
	TypeCommit
	// TypeTree is the PackedObjectType for tree objects.
	TypeTree
	// Typeblob is the PackedObjectType for blob objects.
	TypeBlob
	// TypeTag is the PackedObjectType for tag objects.
	TypeTag

	// TypeObjectOffsetDelta is the type for OBJ_OFS_DELTA-typed objects.
	TypeObjectOffsetDelta PackedObjectType = 6
	// TypeObjectReferenceDelta is the type for OBJ_REF_DELTA-typed objects.
	TypeObjectReferenceDelta PackedObjectType = 7
)

func (PackedObjectType) String

func (t PackedObjectType) String() string

String implements fmt.Stringer and returns an encoding of the type valid for use in the loose object format protocol (see: package 'object' for more).

If the receiving instance is not defined, String() will panic().

type Packfile

type Packfile struct {
	// Version is the version of the packfile.
	Version uint32
	// Objects is the total number of objects in the packfile.
	Objects uint32
	// contains filtered or unexported fields
}

Packfile encapsulates the behavior of accessing an unpacked representation of all of the objects encoded in a single packfile.

func DecodePackfile

func DecodePackfile(r io.ReaderAt, hash hash.Hash) (*Packfile, error)

DecodePackfile opens the packfile given by the io.ReaderAt "r" for reading. It does not apply any delta-base chains, nor does it do reading otherwise beyond the header.

If the header is malformed, or otherwise cannot be read, an error will be returned without a corresponding packfile.

func (*Packfile) Close

func (p *Packfile) Close() error

Close closes the packfile if the underlying data stream is closeable. If so, it returns any error involved in closing.

func (*Packfile) Object

func (p *Packfile) Object(name []byte) (*Object, error)

Object returns a reference to an object packed in the receiving *Packfile. It does not attempt to unpack the packfile, rather, that is accomplished by calling Unpack() on the returned *Object.

If there was an error loading or buffering the base, it will be returned without an object.

If the object given by the SHA-1 name, "name", could not be found, (nil, errNotFound) will be returned.

If the object was able to be loaded successfully, it will be returned without any error.

type Set

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

Set allows access of objects stored across a set of packfiles.

func NewSet

func NewSet(db string, algo hash.Hash) (*Set, error)

NewSet creates a new *Set of all packfiles found in a given object database's root (i.e., "/path/to/repo/.git/objects").

It finds all packfiles in the "pack" subdirectory, and instantiates a *Set containing them. If there was an error parsing the packfiles in that directory, or the directory was otherwise unable to be observed, NewSet returns that error.

func NewSetPacks

func NewSetPacks(packs ...*Packfile) *Set

NewSetPacks creates a new *Set from the given packfiles.

func (*Set) Close

func (s *Set) Close() error

Close closes all open packfiles, returning an error if one was encountered.

func (*Set) Object

func (s *Set) Object(name []byte) (*Object, error)

Object opens (but does not unpack, or, apply the delta-base chain) a given object in the first packfile that matches it.

Object searches packfiles contained in the set in order of how many objects they have that begin with the first by of the given SHA-1 "name", in descending order.

If the object was unable to be found in any of the packfiles, (nil, ErrNotFound) will be returned.

If there was otherwise an error opening the object for reading from any of the packfiles, it will be returned, and no other packfiles will be searched.

Otherwise, the object will be returned without error.

type Storage

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

Storage implements the storage.Storage interface.

func NewStorage

func NewStorage(root string, algo hash.Hash) (*Storage, error)

NewStorage returns a new storage object based on a pack set.

func (*Storage) Close

func (f *Storage) Close() error

Open implements the storage.Storage.Open interface.

func (*Storage) IsCompressed

func (f *Storage) IsCompressed() bool

IsCompressed returns false, because data returned is already decompressed.

func (*Storage) Open

func (f *Storage) Open(oid []byte) (r io.ReadCloser, err error)

Open implements the storage.Storage.Open interface.

type UnsupportedVersionErr

type UnsupportedVersionErr struct {
	// Got is the unsupported version that was detected.
	Got uint32
}

UnsupportedVersionErr is a type implementing 'error' which indicates a the presence of an unsupported packfile version.

func (*UnsupportedVersionErr) Error

func (u *UnsupportedVersionErr) Error() string

Error implements 'error.Error()'.

type V1

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

V1 implements IndexVersion for v1 packfiles.

func (*V1) Entry

func (v *V1) Entry(idx *Index, at int64) (*IndexEntry, error)

Entry implements IndexVersion.Entry for v1 packfiles by parsing and returning the IndexEntry specified at the offset "at" in the given index file.

func (*V1) Name

func (v *V1) Name(idx *Index, at int64) ([]byte, error)

Name implements IndexVersion.Name by returning the 20 byte SHA-1 object name for the given entry at offset "at" in the v1 index file "idx".

func (*V1) Width

func (v *V1) Width() int64

Width implements IndexVersion.Width() by returning the number of bytes that v1 packfile index header occupy.

type V2

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

V2 implements IndexVersion for v2 packfiles.

func (*V2) Entry

func (v *V2) Entry(idx *Index, at int64) (*IndexEntry, error)

Entry implements IndexVersion.Entry for v2 packfiles by parsing and returning the IndexEntry specified at the offset "at" in the given index file.

func (*V2) Name

func (v *V2) Name(idx *Index, at int64) ([]byte, error)

Name implements IndexVersion.Name by returning the 20 byte SHA-1 object name for the given entry at offset "at" in the v2 index file "idx".

func (*V2) Width

func (v *V2) Width() int64

Width implements IndexVersion.Width() by returning the number of bytes that v2 packfile index header occupy.

Jump to

Keyboard shortcuts

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