core

package
v4.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2016 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package core implement the core interfaces and structs used by go-git

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrObjectNotFound = errors.New("object not found")
	// ErrInvalidType is returned when an invalid object type is provided.
	ErrInvalidType = errors.New("invalid object type")
)
View Source
var (
	ErrMaxResolveRecursion = errors.New("max. recursion level reached")
	ErrReferenceNotFound   = errors.New("reference not found")
)
View Source
var (
	//ErrStop is used to stop a ForEach function in an Iter
	ErrStop           = errors.New("stop iter")
	ErrNotImplemented = errors.New("method not-implemented")
)

Functions

func ForEachIterator

func ForEachIterator(iter bareIterator, cb func(Object) error) error

ForEachIterator is a helper function to build iterators without need to rewrite the same ForEach function each time.

Types

type Hash

type Hash [20]byte

Hash SHA1 hased content

var ZeroHash Hash

ZeroHash is Hash with value zero

func ComputeHash

func ComputeHash(t ObjectType, content []byte) Hash

ComputeHash compute the hash for a given ObjectType and content

func NewHash

func NewHash(s string) Hash

NewHash return a new Hash from a hexadecimal hash representation

func (Hash) IsZero

func (h Hash) IsZero() bool

func (Hash) String

func (h Hash) String() string

type Hasher

type Hasher struct {
	hash.Hash
}

func NewHasher

func NewHasher(t ObjectType, size int64) Hasher

func (Hasher) Sum

func (h Hasher) Sum() (hash Hash)

type MemoryObject

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

MemoryObject on memory Object implementation

func (*MemoryObject) Close

func (o *MemoryObject) Close() error

Close releases any resources consumed by the object when it is acting as a ObjectWriter.

func (*MemoryObject) Hash

func (o *MemoryObject) Hash() Hash

Hash return the object Hash, the hash is calculated on-the-fly the first time is called, the subsequent calls the same Hash is returned even if the type or the content has changed. The Hash is only generated if the size of the content is exactly the Object.Size

func (*MemoryObject) Reader

func (o *MemoryObject) Reader() (ObjectReader, error)

Reader returns a ObjectReader used to read the object's content.

func (*MemoryObject) SetSize

func (o *MemoryObject) SetSize(s int64)

SetSize set the object size, a content of the given size should be written afterwards

func (*MemoryObject) SetType

func (o *MemoryObject) SetType(t ObjectType)

SetType sets the ObjectType

func (*MemoryObject) Size

func (o *MemoryObject) Size() int64

Size return the size of the object

func (*MemoryObject) Type

func (o *MemoryObject) Type() ObjectType

Type return the ObjectType

func (*MemoryObject) Write

func (o *MemoryObject) Write(p []byte) (n int, err error)

func (*MemoryObject) Writer

func (o *MemoryObject) Writer() (ObjectWriter, error)

Writer returns a ObjectWriter used to write the object's content.

type MultiObjectIter

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

MultiObjectIter implements ObjectIter. It iterates over several ObjectIter,

The MultiObjectIter must be closed with a call to Close() when it is no longer needed.

func (*MultiObjectIter) Close

func (iter *MultiObjectIter) Close()

Close releases any resources used by the iterator.

func (*MultiObjectIter) ForEach

func (iter *MultiObjectIter) ForEach(cb func(Object) error) error

ForEach call the cb function for each object contained on this iter until an error happends or the end of the iter is reached. If ErrStop is sent the iteration is stop but no error is returned. The iterator is closed.

func (*MultiObjectIter) Next

func (iter *MultiObjectIter) Next() (Object, error)

Next returns the next object from the iterator, if one iterator reach io.EOF is removed and the next one is used.

type Object

type Object interface {
	Hash() Hash
	Type() ObjectType
	SetType(ObjectType)
	Size() int64
	SetSize(int64)
	Reader() (ObjectReader, error)
	Writer() (ObjectWriter, error)
}

Object is a generic representation of any git object

type ObjectIter

type ObjectIter interface {
	Next() (Object, error)
	ForEach(func(Object) error) error
	Close()
}

ObjectIter is a generic closable interface for iterating over objects.

func NewMultiObjectIter

func NewMultiObjectIter(iters []ObjectIter) ObjectIter

NewMultiObjectIter returns an object iterator for the given slice of objects.

type ObjectLookupIter

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

ObjectLookupIter implements ObjectIter. It iterates over a series of object hashes and yields their associated objects by retrieving each one from object storage. The retrievals are lazy and only occur when the iterator moves forward with a call to Next().

The ObjectLookupIter must be closed with a call to Close() when it is no longer needed.

func NewObjectLookupIter

func NewObjectLookupIter(storage ObjectStorage, t ObjectType, series []Hash) *ObjectLookupIter

NewObjectLookupIter returns an object iterator given an object storage and a slice of object hashes.

func (*ObjectLookupIter) Close

func (iter *ObjectLookupIter) Close()

Close releases any resources used by the iterator.

func (*ObjectLookupIter) ForEach

func (iter *ObjectLookupIter) ForEach(cb func(Object) error) error

ForEach call the cb function for each object contained on this iter until an error happends or the end of the iter is reached. If ErrStop is sent the iteration is stop but no error is returned. The iterator is closed.

func (*ObjectLookupIter) Next

func (iter *ObjectLookupIter) Next() (Object, error)

Next returns the next object from the iterator. If the iterator has reached the end it will return io.EOF as an error. If the object can't be found in the object storage, it will return ErrObjectNotFound as an error. If the object is retreieved successfully error will be nil.

type ObjectReader

type ObjectReader io.ReadCloser

ObjectReader is a generic representation of an object reader.

ObjectReader implements io.ReadCloser. Close should be called when finished with it.

type ObjectSliceIter

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

ObjectSliceIter implements ObjectIter. It iterates over a series of objects stored in a slice and yields each one in turn when Next() is called.

The ObjectSliceIter must be closed with a call to Close() when it is no longer needed.

func NewObjectSliceIter

func NewObjectSliceIter(series []Object) *ObjectSliceIter

NewObjectSliceIter returns an object iterator for the given slice of objects.

func (*ObjectSliceIter) Close

func (iter *ObjectSliceIter) Close()

Close releases any resources used by the iterator.

func (*ObjectSliceIter) ForEach

func (iter *ObjectSliceIter) ForEach(cb func(Object) error) error

ForEach call the cb function for each object contained on this iter until an error happends or the end of the iter is reached. If ErrStop is sent the iteration is stop but no error is returned. The iterator is closed.

func (*ObjectSliceIter) Next

func (iter *ObjectSliceIter) Next() (Object, error)

Next returns the next object from the iterator. If the iterator has reached the end it will return io.EOF as an error. If the object is retreieved successfully error will be nil.

type ObjectStorage

type ObjectStorage interface {
	// NewObject returns a new Object, the real type of the object can be a
	// custom implementation or the defaul one, MemoryObject
	NewObject() Object
	// Set save an object into the storage, the object shuld be create with
	// the NewObject, method, and file if the type is not supported.
	Set(Object) (Hash, error)
	// Get an object by hash with the given ObjectType. Implementors should
	// return (nil, ErrObjectNotFound) if an object doesn't exist with both the
	// given hash and object type.
	//
	// Valid ObjectType values are CommitObject, BlobObject, TagObject,
	// TreeObject and AnyObject.
	//
	// If AnyObject is given, the object must be looked up regardless of its type.
	Get(ObjectType, Hash) (Object, error)
	// Iter returns a custom ObjectIter over all the object on the storage.
	//
	// Valid ObjectType values are CommitObject, BlobObject, TagObject,
	Iter(ObjectType) (ObjectIter, error)
	// Begin starts a transaction.
	Begin() TxObjectStorage
}

ObjectStorage generic storage of objects

type ObjectStorageWrite

type ObjectStorageWrite interface {
	// Writer retuns a writer for writing a packfile to the Storage, this method
	// is optional, if not implemented the ObjectStorage should return a
	// ErrNotImplemented error.
	//
	// If the implementation not implements Writer the objects should be written
	// using the Set method.
	Writer() (io.WriteCloser, error)
}

ObjectStorageWrite is a optional method for ObjectStorage, it enable direct write of packfile to the storage

type ObjectType

type ObjectType int8

ObjectType internal object type Integer values from 0 to 7 map to those exposed by git. AnyObject is used to represent any from 0 to 7.

const (
	InvalidObject ObjectType = 0
	CommitObject  ObjectType = 1
	TreeObject    ObjectType = 2
	BlobObject    ObjectType = 3
	TagObject     ObjectType = 4
	// 5 reserved for future expansion
	OFSDeltaObject ObjectType = 6
	REFDeltaObject ObjectType = 7

	AnyObject ObjectType = -127
)

func ParseObjectType

func ParseObjectType(value string) (typ ObjectType, err error)

ParseObjectType parses a string representation of ObjectType. It returns an error on parse failure.

func (ObjectType) Bytes

func (t ObjectType) Bytes() []byte

func (ObjectType) String

func (t ObjectType) String() string

func (ObjectType) Valid

func (t ObjectType) Valid() bool

Valid returns true if t is a valid ObjectType.

type ObjectWriter

type ObjectWriter io.WriteCloser

ObjectWriter is a generic representation of an object writer.

ObjectWriter implements io.WriterCloser. Close should be called when finished with it.

type PermanentError

type PermanentError struct {
	Err error
}

func NewPermanentError

func NewPermanentError(err error) *PermanentError

func (*PermanentError) Error

func (e *PermanentError) Error() string

type Reference

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

Reference is a representation of git reference

func NewHashReference

func NewHashReference(n ReferenceName, h Hash) *Reference

NewHashReference creates a new HashReference reference

func NewReferenceFromStrings

func NewReferenceFromStrings(name, target string) *Reference

NewReferenceFromStrings creates a reference from name and target as string, the resulting reference can be a SymbolicReference or a HashReference base on the target provided

func NewSymbolicReference

func NewSymbolicReference(n, target ReferenceName) *Reference

NewSymbolicReference creates a new SymbolicReference reference

func ResolveReference

func ResolveReference(s ReferenceStorage, n ReferenceName) (*Reference, error)

func (*Reference) Hash

func (r *Reference) Hash() Hash

Hash return the hash of a hash reference

func (*Reference) IsBranch

func (r *Reference) IsBranch() bool

IsBranch check if a reference is a branch

func (*Reference) IsNote

func (r *Reference) IsNote() bool

IsNote check if a reference is a note

func (*Reference) IsRemote

func (r *Reference) IsRemote() bool

IsRemote check if a reference is a remote

func (*Reference) IsTag

func (r *Reference) IsTag() bool

IsTag check if a reference is a tag

func (*Reference) Name

func (r *Reference) Name() ReferenceName

Name return the name of a reference

func (*Reference) String

func (r *Reference) String() string

func (*Reference) Strings

func (r *Reference) Strings() [2]string

Strings dump a reference as a [2]string

func (*Reference) Target

func (r *Reference) Target() ReferenceName

Target return the target of a symbolic reference

func (*Reference) Type

func (r *Reference) Type() ReferenceType

Type return the type of a reference

type ReferenceIter

type ReferenceIter interface {
	Next() (*Reference, error)
	ForEach(func(*Reference) error) error
	Close()
}

ReferenceIter is a generic closable interface for iterating over references

type ReferenceName

type ReferenceName string

ReferenceName reference name's

const (
	HEAD ReferenceName = "HEAD"
)

func (ReferenceName) Short

func (r ReferenceName) Short() string

Short returns the short name of a ReferenceName

func (ReferenceName) String

func (r ReferenceName) String() string

type ReferenceSliceIter

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

ReferenceSliceIter implements ReferenceIter. It iterates over a series of references stored in a slice and yields each one in turn when Next() is called.

The ReferenceSliceIter must be closed with a call to Close() when it is no longer needed.

func NewReferenceSliceIter

func NewReferenceSliceIter(series []*Reference) *ReferenceSliceIter

NewReferenceSliceIter returns a reference iterator for the given slice of objects.

func (*ReferenceSliceIter) Close

func (iter *ReferenceSliceIter) Close()

Close releases any resources used by the iterator.

func (*ReferenceSliceIter) ForEach

func (iter *ReferenceSliceIter) ForEach(cb func(*Reference) error) error

ForEach call the cb function for each reference contained on this iter until an error happends or the end of the iter is reached. If ErrStop is sent the iteration is stop but no error is returned. The iterator is closed.

func (*ReferenceSliceIter) Next

func (iter *ReferenceSliceIter) Next() (*Reference, error)

Next returns the next reference from the iterator. If the iterator has reached the end it will return io.EOF as an error.

type ReferenceStorage

type ReferenceStorage interface {
	Set(*Reference) error
	Get(ReferenceName) (*Reference, error)
	Iter() (ReferenceIter, error)
}

ReferenceStorage generic storage of references

type ReferenceType

type ReferenceType int8

ReferenceType reference type's

const (
	InvalidReference  ReferenceType = 0
	HashReference     ReferenceType = 1
	SymbolicReference ReferenceType = 2
)

type TxObjectStorage

type TxObjectStorage interface {
	Set(Object) (Hash, error)
	Get(ObjectType, Hash) (Object, error)
	Commit() error
	Rollback() error
}

TxObjectStorage is an in-progress storage transaction. A transaction must end with a call to Commit or Rollback.

type UnexpectedError

type UnexpectedError struct {
	Err error
}

func NewUnexpectedError

func NewUnexpectedError(err error) *UnexpectedError

func (*UnexpectedError) Error

func (e *UnexpectedError) Error() string

Jump to

Keyboard shortcuts

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