Documentation ¶
Overview ¶
Package core implement the core interfaces and structs used by go-git
Index ¶
- Variables
- func ForEachIterator(iter bareIterator, cb func(Object) error) error
- type Hash
- type Hasher
- type MemoryObject
- func (o *MemoryObject) Close() error
- func (o *MemoryObject) Hash() Hash
- func (o *MemoryObject) Reader() (ObjectReader, error)
- func (o *MemoryObject) SetSize(s int64)
- func (o *MemoryObject) SetType(t ObjectType)
- func (o *MemoryObject) Size() int64
- func (o *MemoryObject) Type() ObjectType
- func (o *MemoryObject) Write(p []byte) (n int, err error)
- func (o *MemoryObject) Writer() (ObjectWriter, error)
- type MultiObjectIter
- type Object
- type ObjectIter
- type ObjectLookupIter
- type ObjectReader
- type ObjectSliceIter
- type ObjectStorage
- type ObjectStorageWrite
- type ObjectType
- type ObjectWriter
- type PermanentError
- type Reference
- func (r *Reference) Hash() Hash
- func (r *Reference) IsBranch() bool
- func (r *Reference) IsNote() bool
- func (r *Reference) IsRemote() bool
- func (r *Reference) IsTag() bool
- func (r *Reference) Name() ReferenceName
- func (r *Reference) String() string
- func (r *Reference) Strings() [2]string
- func (r *Reference) Target() ReferenceName
- func (r *Reference) Type() ReferenceType
- type ReferenceIter
- type ReferenceName
- type ReferenceSliceIter
- type ReferenceStorage
- type ReferenceType
- type TxObjectStorage
- type UnexpectedError
Constants ¶
This section is empty.
Variables ¶
var ( ErrObjectNotFound = errors.New("object not found") // ErrInvalidType is returned when an invalid object type is provided. ErrInvalidType = errors.New("invalid object type") )
var ( ErrMaxResolveRecursion = errors.New("max. recursion level reached") ErrReferenceNotFound = errors.New("reference not found") )
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 ¶
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
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) 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 ¶
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 ¶
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) Name ¶
func (r *Reference) Name() ReferenceName
Name return the name of a reference
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