go-git.v4: gopkg.in/src-d/go-git.v4/plumbing/format/packfile Index | Files

package packfile

import "gopkg.in/src-d/go-git.v4/plumbing/format/packfile"

Package packfile implements encoding and decoding of packfile format.

== pack-*.pack files have the following format:

  - A header appears at the beginning and consists of the following:

    4-byte signature:
        The signature is: {'P', 'A', 'C', 'K'}

    4-byte version number (network byte order):
        GIT currently accepts version number 2 or 3 but
        generates version 2 only.

    4-byte number of objects contained in the pack (network byte order)

    Observation: we cannot have more than 4G versions ;-) and
    more than 4G objects in a pack.

  - The header is followed by number of object entries, each of
    which looks like this:

    (undeltified representation)
    n-byte type and length (3-bit type, (n-1)*7+4-bit length)
    compressed data

    (deltified representation)
    n-byte type and length (3-bit type, (n-1)*7+4-bit length)
    20-byte base object name
    compressed delta data

    Observation: length of each object is encoded in a variable
    length format and is not constrained to 32-bit or anything.

 - The trailer records 20-byte SHA1 checksum of all of the above.

Source: https://www.kernel.org/pub/software/scm/git/docs/v1.7.5/technical/pack-protocol.txt

Index

Package Files

common.go delta_index.go delta_selector.go diff_delta.go doc.go encoder.go error.go fsobject.go object_pack.go packfile.go parser.go patch_delta.go scanner.go

Constants

const (
    // VersionSupported is the packfile version supported by this package
    VersionSupported uint32 = 2
)

Variables

var (
    // ErrInvalidObject is returned by Decode when an invalid object is
    // found in the packfile.
    ErrInvalidObject = NewError("invalid git object")
    // ErrZLib is returned by Decode when there was an error unzipping
    // the packfile contents.
    ErrZLib = NewError("zlib reading error")
)
var (
    // ErrReferenceDeltaNotFound is returned when the reference delta is not
    // found.
    ErrReferenceDeltaNotFound = errors.New("reference delta not found")

    // ErrNotSeekableSource is returned when the source for the parser is not
    // seekable and a storage was not provided, so it can't be parsed.
    ErrNotSeekableSource = errors.New("parser source is not seekable and storage was not provided")

    // ErrDeltaNotCached is returned when the delta could not be found in cache.
    ErrDeltaNotCached = errors.New("delta could not be found in cache")
)
var (
    ErrInvalidDelta = errors.New("invalid delta")
    ErrDeltaCmd     = errors.New("wrong delta command")
)
var (
    // ErrEmptyPackfile is returned by ReadHeader when no data is found in the packfile
    ErrEmptyPackfile = NewError("empty packfile")
    // ErrBadSignature is returned by ReadHeader when the signature in the packfile is incorrect.
    ErrBadSignature = NewError("malformed pack file signature")
    // ErrUnsupportedVersion is returned by ReadHeader when the packfile version is
    // different than VersionSupported.
    ErrUnsupportedVersion = NewError("unsupported packfile version")
    // ErrSeekNotSupported returned if seek is not support
    ErrSeekNotSupported = NewError("not seek support")
)
var T = []uint32{ /* 256 elements not displayed */

}

func ApplyDelta Uses

func ApplyDelta(target, base plumbing.EncodedObject, delta []byte) error

ApplyDelta writes to target the result of applying the modification deltas in delta to base.

func DiffDelta Uses

func DiffDelta(src, tgt []byte) []byte

DiffDelta returns the delta that transforms src into tgt.

func GetDelta Uses

func GetDelta(base, target plumbing.EncodedObject) (plumbing.EncodedObject, error)

GetDelta returns an EncodedObject of type OFSDeltaObject. Base and Target object, will be loaded into memory to be able to create the delta object. To generate target again, you will need the obtained object and "base" one. Error will be returned if base or target object cannot be read.

func PatchDelta Uses

func PatchDelta(src, delta []byte) ([]byte, error)

PatchDelta returns the result of applying the modification deltas in delta to src. An error will be returned if delta is corrupted (ErrDeltaLen) or an action command is not copy from source or copy from delta (ErrDeltaCmd).

func UpdateObjectStorage Uses

func UpdateObjectStorage(s storer.Storer, packfile io.Reader) error

UpdateObjectStorage updates the storer with the objects in the given packfile.

func WritePackfileToObjectStorage Uses

func WritePackfileToObjectStorage(
    sw storer.PackfileWriter,
    packfile io.Reader,
) (err error)

WritePackfileToObjectStorage writes all the packfile objects into the given object storage.

type Encoder Uses

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

Encoder gets the data from the storage and write it into the writer in PACK format

func NewEncoder Uses

func NewEncoder(w io.Writer, s storer.EncodedObjectStorer, useRefDeltas bool) *Encoder

NewEncoder creates a new packfile encoder using a specific Writer and EncodedObjectStorer. By default deltas used to generate the packfile will be OFSDeltaObject. To use Reference deltas, set useRefDeltas to true.

func (*Encoder) Encode Uses

func (e *Encoder) Encode(
    hashes []plumbing.Hash,
    packWindow uint,
) (plumbing.Hash, error)

Encode creates a packfile containing all the objects referenced in hashes and writes it to the writer in the Encoder. `packWindow` specifies the size of the sliding window used to compare objects for delta compression; 0 turns off delta compression entirely.

type Error Uses

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

Error specifies errors returned during packfile parsing.

func NewError Uses

func NewError(reason string) *Error

NewError returns a new error.

func (*Error) AddDetails Uses

func (e *Error) AddDetails(format string, args ...interface{}) *Error

AddDetails adds details to an error, with additional text.

func (*Error) Error Uses

func (e *Error) Error() string

Error returns a text representation of the error.

type FSObject Uses

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

FSObject is an object from the packfile on the filesystem.

func NewFSObject Uses

func NewFSObject(
    hash plumbing.Hash,
    finalType plumbing.ObjectType,
    offset int64,
    contentSize int64,
    index idxfile.Index,
    fs billy.Filesystem,
    path string,
    cache cache.Object,
) *FSObject

NewFSObject creates a new filesystem object.

func (*FSObject) Hash Uses

func (o *FSObject) Hash() plumbing.Hash

Hash implements the plumbing.EncodedObject interface.

func (*FSObject) Reader Uses

func (o *FSObject) Reader() (io.ReadCloser, error)

Reader implements the plumbing.EncodedObject interface.

func (*FSObject) SetSize Uses

func (o *FSObject) SetSize(int64)

SetSize implements the plumbing.EncodedObject interface. This method is a noop.

func (*FSObject) SetType Uses

func (o *FSObject) SetType(plumbing.ObjectType)

SetType implements the plumbing.EncodedObject interface. This method is a noop.

func (*FSObject) Size Uses

func (o *FSObject) Size() int64

Size implements the plumbing.EncodedObject interface.

func (*FSObject) Type Uses

func (o *FSObject) Type() plumbing.ObjectType

Type implements the plumbing.EncodedObject interface.

func (*FSObject) Writer Uses

func (o *FSObject) Writer() (io.WriteCloser, error)

Writer implements the plumbing.EncodedObject interface. This method always returns a nil writer.

type ObjectHeader Uses

type ObjectHeader struct {
    Type            plumbing.ObjectType
    Offset          int64
    Length          int64
    Reference       plumbing.Hash
    OffsetReference int64
}

ObjectHeader contains the information related to the object, this information is collected from the previous bytes to the content of the object.

type ObjectToPack Uses

type ObjectToPack struct {
    // The main object to pack, it could be any object, including deltas
    Object plumbing.EncodedObject
    // Base is the object that a delta is based on (it could be also another delta).
    // If the main object is not a delta, Base will be null
    Base *ObjectToPack
    // Original is the object that we can generate applying the delta to
    // Base, or the same object as Object in the case of a non-delta
    // object.
    Original plumbing.EncodedObject
    // Depth is the amount of deltas needed to resolve to obtain Original
    // (delta based on delta based on ...)
    Depth int

    // offset in pack when object has been already written, or 0 if it
    // has not been written yet
    Offset int64
    // contains filtered or unexported fields
}

ObjectToPack is a representation of an object that is going to be into a pack file.

func (*ObjectToPack) BackToOriginal Uses

func (o *ObjectToPack) BackToOriginal()

BackToOriginal converts that ObjectToPack to a non-deltified object if it was one

func (*ObjectToPack) CleanOriginal Uses

func (o *ObjectToPack) CleanOriginal()

CleanOriginal sets Original to nil

func (*ObjectToPack) Hash Uses

func (o *ObjectToPack) Hash() plumbing.Hash

func (*ObjectToPack) IsDelta Uses

func (o *ObjectToPack) IsDelta() bool

func (*ObjectToPack) IsWritten Uses

func (o *ObjectToPack) IsWritten() bool

IsWritten returns if that ObjectToPack was already written into the packfile or not

func (*ObjectToPack) MarkWantWrite Uses

func (o *ObjectToPack) MarkWantWrite()

MarkWantWrite marks this ObjectToPack as WantWrite to avoid delta chain loops

func (*ObjectToPack) SaveOriginalMetadata Uses

func (o *ObjectToPack) SaveOriginalMetadata()

SaveOriginalMetadata saves size, type and hash of Original object

func (*ObjectToPack) SetDelta Uses

func (o *ObjectToPack) SetDelta(base *ObjectToPack, delta plumbing.EncodedObject)

func (*ObjectToPack) SetOriginal Uses

func (o *ObjectToPack) SetOriginal(obj plumbing.EncodedObject)

SetOriginal sets both Original and saves size, type and hash. If object is nil Original is set but previous resolved values are kept

func (*ObjectToPack) Size Uses

func (o *ObjectToPack) Size() int64

func (*ObjectToPack) Type Uses

func (o *ObjectToPack) Type() plumbing.ObjectType

func (*ObjectToPack) WantWrite Uses

func (o *ObjectToPack) WantWrite() bool

WantWrite checks if this ObjectToPack was marked as WantWrite before

type Observer Uses

type Observer interface {
    // OnHeader is called when a new packfile is opened.
    OnHeader(count uint32) error
    // OnInflatedObjectHeader is called for each object header read.
    OnInflatedObjectHeader(t plumbing.ObjectType, objSize int64, pos int64) error
    // OnInflatedObjectContent is called for each decoded object.
    OnInflatedObjectContent(h plumbing.Hash, pos int64, crc uint32, content []byte) error
    // OnFooter is called when decoding is done.
    OnFooter(h plumbing.Hash) error
}

Observer interface is implemented by index encoders.

type Packfile Uses

type Packfile struct {
    idxfile.Index
    // contains filtered or unexported fields
}

Packfile allows retrieving information from inside a packfile.

func NewPackfile Uses

func NewPackfile(index idxfile.Index, fs billy.Filesystem, file billy.File) *Packfile

NewPackfile returns a packfile representation for the given packfile file and packfile idx. If the filesystem is provided, the packfile will return FSObjects, otherwise it will return MemoryObjects.

func NewPackfileWithCache Uses

func NewPackfileWithCache(
    index idxfile.Index,
    fs billy.Filesystem,
    file billy.File,
    cache cache.Object,
) *Packfile

NewPackfileWithCache creates a new Packfile with the given object cache. If the filesystem is provided, the packfile will return FSObjects, otherwise it will return MemoryObjects.

func (*Packfile) Close Uses

func (p *Packfile) Close() error

Close the packfile and its resources.

func (*Packfile) Get Uses

func (p *Packfile) Get(h plumbing.Hash) (plumbing.EncodedObject, error)

Get retrieves the encoded object in the packfile with the given hash.

func (*Packfile) GetAll Uses

func (p *Packfile) GetAll() (storer.EncodedObjectIter, error)

GetAll returns an iterator with all encoded objects in the packfile. The iterator returned is not thread-safe, it should be used in the same thread as the Packfile instance.

func (*Packfile) GetByOffset Uses

func (p *Packfile) GetByOffset(o int64) (plumbing.EncodedObject, error)

GetByOffset retrieves the encoded object from the packfile at the given offset.

func (*Packfile) GetByType Uses

func (p *Packfile) GetByType(typ plumbing.ObjectType) (storer.EncodedObjectIter, error)

GetByType returns all the objects of the given type.

func (*Packfile) GetSizeByOffset Uses

func (p *Packfile) GetSizeByOffset(o int64) (size int64, err error)

GetSizeByOffset retrieves the size of the encoded object from the packfile with the given offset.

func (*Packfile) ID Uses

func (p *Packfile) ID() (plumbing.Hash, error)

ID returns the ID of the packfile, which is the checksum at the end of it.

func (*Packfile) Scanner Uses

func (p *Packfile) Scanner() *Scanner

Scanner returns the packfile's Scanner

type Parser Uses

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

Parser decodes a packfile and calls any observer associated to it. Is used to generate indexes.

func NewParser Uses

func NewParser(scanner *Scanner, ob ...Observer) (*Parser, error)

NewParser creates a new Parser. The Scanner source must be seekable. If it's not, NewParserWithStorage should be used instead.

func NewParserWithStorage Uses

func NewParserWithStorage(
    scanner *Scanner,
    storage storer.EncodedObjectStorer,
    ob ...Observer,
) (*Parser, error)

NewParserWithStorage creates a new Parser. The scanner source must either be seekable or a storage must be provided.

func (*Parser) Parse Uses

func (p *Parser) Parse() (plumbing.Hash, error)

Parse start decoding phase of the packfile.

type Scanner Uses

type Scanner struct {

    // lsSeekable says if this scanner can do Seek or not, to have a Scanner
    // seekable a r implementing io.Seeker is required
    IsSeekable bool
    // contains filtered or unexported fields
}

func NewScanner Uses

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new Scanner based on a reader, if the given reader implements io.ReadSeeker the Scanner will be also Seekable

func (*Scanner) Checksum Uses

func (s *Scanner) Checksum() (plumbing.Hash, error)

Checksum returns the checksum of the packfile

func (*Scanner) Close Uses

func (s *Scanner) Close() error

Close reads the reader until io.EOF

func (*Scanner) Flush Uses

func (s *Scanner) Flush() error

Flush is a no-op (deprecated)

func (*Scanner) Header Uses

func (s *Scanner) Header() (version, objects uint32, err error)

Header reads the whole packfile header (signature, version and object count). It returns the version and the object count and performs checks on the validity of the signature and the version fields.

func (*Scanner) NextObject Uses

func (s *Scanner) NextObject(w io.Writer) (written int64, crc32 uint32, err error)

NextObject writes the content of the next object into the reader, returns the number of bytes written, the CRC32 of the content and an error, if any

func (*Scanner) NextObjectHeader Uses

func (s *Scanner) NextObjectHeader() (*ObjectHeader, error)

NextObjectHeader returns the ObjectHeader for the next object in the reader

func (*Scanner) Reset Uses

func (s *Scanner) Reset(r io.Reader)

func (*Scanner) SeekFromStart Uses

func (s *Scanner) SeekFromStart(offset int64) (previous int64, err error)

SeekFromStart sets a new offset from start, returns the old position before the change.

func (*Scanner) SeekObjectHeader Uses

func (s *Scanner) SeekObjectHeader(offset int64) (*ObjectHeader, error)

SeekObjectHeader seeks to specified offset and returns the ObjectHeader for the next object in the reader

Package packfile imports 20 packages (graph) and is imported by 19 packages. Updated 2019-08-02. Refresh now. Tools for package owners.