Documentation ¶
Overview ¶
Package object contains implementations of all Git objects and utility functions to work with them.
Index ¶
- Constants
- Variables
- func NewTreeRootNode(t *Tree) noder.Noder
- type Blob
- type BlobIter
- type Change
- type ChangeEntry
- type Changes
- type Commit
- func (c *Commit) Decode(o plumbing.EncodedObject) (err error)
- func (b *Commit) Encode(o plumbing.EncodedObject) error
- func (c *Commit) File(path string) (*File, error)
- func (c *Commit) Files() (*FileIter, error)
- func (c *Commit) ID() plumbing.Hash
- func (c *Commit) NumParents() int
- func (c *Commit) Parents() CommitIter
- func (c *Commit) Patch(to *Commit) (*Patch, error)
- func (c *Commit) String() string
- func (c *Commit) Tree() (*Tree, error)
- func (c *Commit) Type() plumbing.ObjectType
- type CommitIter
- type File
- type FileIter
- type Hash
- type Object
- type ObjectIter
- type Patch
- type Signature
- type Tag
- func (t *Tag) Blob() (*Blob, error)
- func (t *Tag) Commit() (*Commit, error)
- func (t *Tag) Decode(o plumbing.EncodedObject) (err error)
- func (t *Tag) Encode(o plumbing.EncodedObject) error
- func (t *Tag) ID() plumbing.Hash
- func (t *Tag) Object() (Object, error)
- func (t *Tag) String() string
- func (t *Tag) Tree() (*Tree, error)
- func (t *Tag) Type() plumbing.ObjectType
- type TagIter
- type Tree
- func (t *Tree) Decode(o plumbing.EncodedObject) (err error)
- func (from *Tree) Diff(to *Tree) (Changes, error)
- func (t *Tree) Encode(o plumbing.EncodedObject) error
- func (t *Tree) File(path string) (*File, error)
- func (t *Tree) Files() *FileIter
- func (t *Tree) FindEntry(path string) (*TreeEntry, error)
- func (t *Tree) ID() plumbing.Hash
- func (from *Tree) Patch(to *Tree) (*Patch, error)
- func (t *Tree) Tree(path string) (*Tree, error)
- func (t *Tree) TreeEntryFile(e *TreeEntry) (*File, error)
- func (t *Tree) Type() plumbing.ObjectType
- type TreeEntry
- type TreeIter
- type TreeWalker
Constants ¶
const DateFormat = "Mon Jan 02 15:04:05 2006 -0700"
DateFormat is the format being used in the original git implementation
Variables ¶
var ( ErrMaxTreeDepth = errors.New("maximum tree depth exceeded") ErrFileNotFound = errors.New("file not found") ErrDirectoryNotFound = errors.New("directory not found") )
New errors defined by this package.
var ErrUnsupportedObject = errors.New("unsupported object type")
ErrUnsupportedObject trigger when a non-supported object is being decoded.
Functions ¶
func NewTreeRootNode ¶
NewTreeRootNode returns the root node of a Tree
Types ¶
type Blob ¶
type Blob struct { // Hash of the blob. Hash plumbing.Hash // Size of the (uncompressed) blob. Size int64 // contains filtered or unexported fields }
Blob is used to store arbitrary data - it is generally a file.
func DecodeBlob ¶
func DecodeBlob(o plumbing.EncodedObject) (*Blob, error)
DecodeObject decodes an encoded object into a *Blob.
func (*Blob) Decode ¶
func (b *Blob) Decode(o plumbing.EncodedObject) error
Decode transforms a plumbing.EncodedObject into a Blob struct.
func (*Blob) Encode ¶
func (b *Blob) Encode(o plumbing.EncodedObject) error
Encode transforms a Blob into a plumbing.EncodedObject.
func (*Blob) ID ¶
ID returns the object ID of the blob. The returned value will always match the current value of Blob.Hash.
ID is present to fulfill the Object interface.
func (*Blob) Reader ¶
func (b *Blob) Reader() (io.ReadCloser, error)
Reader returns a reader allow the access to the content of the blob
func (*Blob) Type ¶
func (b *Blob) Type() plumbing.ObjectType
Type returns the type of object. It always returns plumbing.BlobObject.
Type is present to fulfill the Object interface.
type BlobIter ¶
type BlobIter struct { storer.EncodedObjectIter // contains filtered or unexported fields }
BlobIter provides an iterator for a set of blobs.
func NewBlobIter ¶
func NewBlobIter(s storer.EncodedObjectStorer, iter storer.EncodedObjectIter) *BlobIter
NewBlobIter takes a storer.EncodedObjectStorer and a storer.EncodedObjectIter and returns a *BlobIter that iterates over all blobs contained in the storer.EncodedObjectIter.
Any non-blob object returned by the storer.EncodedObjectIter is skipped.
type Change ¶
type Change struct { From ChangeEntry To ChangeEntry }
Change values represent a detected change between two git trees. For modifications, From is the original status of the node and To is its final status. For insertions, From is the zero value and for deletions To is the zero value.
func (*Change) Action ¶
func (c *Change) Action() (merkletrie.Action, error)
Action returns the kind of action represented by the change, an insertion, a deletion or a modification.
func (*Change) Files ¶
Files return the files before and after a change. For insertions from will be nil. For deletions to will be nil.
type ChangeEntry ¶
type ChangeEntry struct { // Full path of the node using "/" as separator. Name string // Parent tree of the node that has changed. Tree *Tree // The entry of the node. TreeEntry TreeEntry }
ChangeEntry values represent a node that has suffered a change.
type Changes ¶
type Changes []*Change
Changes represents a collection of changes between two git trees. Implements sort.Interface lexicographically over the path of the changed files.
type Commit ¶
type Commit struct { // Hash of the commit object. Hash plumbing.Hash // Author is the original author of the commit. Author Signature // Committer is the one performing the commit, might be different from // Author. Committer Signature // Message is the commit message, contains arbitrary text. Message string // TreeHash is the hash of the root tree of the commit. TreeHash plumbing.Hash // ParentHashes are the hashes of the parent commits of the commit. ParentHashes []plumbing.Hash // contains filtered or unexported fields }
Commit points to a single tree, marking it as what the project looked like at a certain point in time. It contains meta-information about that point in time, such as a timestamp, the author of the changes since the last commit, a pointer to the previous commit(s), etc. http://schacon.github.io/gitbook/1_the_git_object_model.html
func DecodeCommit ¶
func DecodeCommit(s storer.EncodedObjectStorer, o plumbing.EncodedObject) (*Commit, error)
DecodeCommit decodes an encoded object into a *Commit and associates it to the given object storer.
func (*Commit) Decode ¶
func (c *Commit) Decode(o plumbing.EncodedObject) (err error)
Decode transforms a plumbing.EncodedObject into a Commit struct.
func (*Commit) Encode ¶
func (b *Commit) Encode(o plumbing.EncodedObject) error
Encode transforms a Commit into a plumbing.EncodedObject.
func (*Commit) File ¶
File returns the file with the specified "path" in the commit and a nil error if the file exists. If the file does not exist, it returns a nil file and the ErrFileNotFound error.
func (*Commit) ID ¶
ID returns the object ID of the commit. The returned value will always match the current value of Commit.Hash.
ID is present to fulfill the Object interface.
func (*Commit) NumParents ¶
NumParents returns the number of parents in a commit.
func (*Commit) Parents ¶
func (c *Commit) Parents() CommitIter
Parents return a CommitIter to the parent Commits.
func (*Commit) Type ¶
func (c *Commit) Type() plumbing.ObjectType
Type returns the type of object. It always returns plumbing.CommitObject.
Type is present to fulfill the Object interface.
type CommitIter ¶
CommitIter is a generic closable interface for iterating over commits.
func NewCommitIter ¶
func NewCommitIter(s storer.EncodedObjectStorer, iter storer.EncodedObjectIter) CommitIter
NewCommitIter takes a storer.EncodedObjectStorer and a storer.EncodedObjectIter and returns a CommitIter that iterates over all commits contained in the storer.EncodedObjectIter.
Any non-commit object returned by the storer.EncodedObjectIter is skipped.
func NewCommitPostorderIter ¶
func NewCommitPostorderIter(c *Commit, ignore []plumbing.Hash) CommitIter
NewCommitPostorderIter returns a CommitIter that walks the commit history like WalkCommitHistory but in post-order. This means that after walking a merge commit, the merged commit will be walked before the base it was merged on. This can be useful if you wish to see the history in chronological order. Ignore allows to skip some commits from being iterated.
func NewCommitPreorderIter ¶
func NewCommitPreorderIter(c *Commit, ignore []plumbing.Hash) CommitIter
NewCommitPreorderIter returns a CommitIter that walks the commit history, starting at the given commit and visiting its parents in pre-order. The given callback will be called for each visited commit. Each commit will be visited only once. If the callback returns an error, walking will stop and will return the error. Other errors might be returned if the history cannot be traversed (e.g. missing objects). Ignore allows to skip some commits from being iterated.
type File ¶
type File struct { // Name is the path of the file. It might be relative to a tree, // depending of the function that generates it. Name string // Mode is the file mode. Mode filemode.FileMode // Blob with the contents of the file. Blob }
File represents git file objects.
type FileIter ¶
type FileIter struct {
// contains filtered or unexported fields
}
FileIter provides an iterator for the files in a tree.
func NewFileIter ¶
func NewFileIter(s storer.EncodedObjectStorer, t *Tree) *FileIter
NewFileIter takes a storer.EncodedObjectStorer and a Tree and returns a *FileIter that iterates over all files contained in the tree, recursively.
type Object ¶
type Object interface { ID() plumbing.Hash Type() plumbing.ObjectType Decode(plumbing.EncodedObject) error Encode(plumbing.EncodedObject) error }
Object is a generic representation of any git object. It is implemented by Commit, Tree, Blob, and Tag, and includes the functions that are common to them.
Object is returned when an object can be of any type. It is frequently used with a type cast to acquire the specific type of object:
func process(obj Object) { switch o := obj.(type) { case *Commit: // o is a Commit case *Tree: // o is a Tree case *Blob: // o is a Blob case *Tag: // o is a Tag } }
This interface is intentionally different from plumbing.EncodedObject, which is a lower level interface used by storage implementations to read and write objects in its encoded form.
func DecodeObject ¶
func DecodeObject(s storer.EncodedObjectStorer, o plumbing.EncodedObject) (Object, error)
DecodeObject decodes an encoded object into an Object and associates it to the given object storer.
type ObjectIter ¶
type ObjectIter struct { storer.EncodedObjectIter // contains filtered or unexported fields }
ObjectIter provides an iterator for a set of objects.
func NewObjectIter ¶
func NewObjectIter(s storer.EncodedObjectStorer, iter storer.EncodedObjectIter) *ObjectIter
NewObjectIter takes a storer.EncodedObjectStorer and a storer.EncodedObjectIter and returns an *ObjectIter that iterates over all objects contained in the storer.EncodedObjectIter.
func (*ObjectIter) ForEach ¶
func (iter *ObjectIter) ForEach(cb func(Object) error) error
ForEach call the cb function for each object contained on this iter until an error happens 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 (*ObjectIter) Next ¶
func (iter *ObjectIter) Next() (Object, error)
Next moves the iterator to the next object and returns a pointer to it. If there are no more objects, it returns io.EOF.
type Patch ¶
type Patch struct {
// contains filtered or unexported fields
}
textPatch is an implementation of fdiff.Patch interface
func (*Patch) FilePatches ¶
type Signature ¶
type Signature struct { // Name represents a person name. It is an arbitrary string. Name string // Email is an email, but it cannot be assumed to be well-formed. Email string // When is the timestamp of the signature. When time.Time }
Signature is used to identify who and when created a commit or tag.
type Tag ¶
type Tag struct { // Hash of the tag. Hash plumbing.Hash // Name of the tag. Name string // Tagger is the one who created the tag. Tagger Signature // Message is an arbitrary text message. Message string // TargetType is the object type of the target. TargetType plumbing.ObjectType // Target is the hash of the target object. Target plumbing.Hash // contains filtered or unexported fields }
Tag represents an annotated tag object. It points to a single git object of any type, but tags typically are applied to commit or blob objects. It provides a reference that associates the target with a tag name. It also contains meta-information about the tag, including the tagger, tag date and message.
Note that this is not used for lightweight tags.
https://git-scm.com/book/en/v2/Git-Internals-Git-References#Tags
func DecodeTag ¶
func DecodeTag(s storer.EncodedObjectStorer, o plumbing.EncodedObject) (*Tag, error)
DecodeTag decodes an encoded object into a *Commit and associates it to the given object storer.
func (*Tag) Blob ¶
Blob returns the blob pointed to by the tag. If the tag points to a different type of object ErrUnsupportedObject will be returned.
func (*Tag) Commit ¶
Commit returns the commit pointed to by the tag. If the tag points to a different type of object ErrUnsupportedObject will be returned.
func (*Tag) Decode ¶
func (t *Tag) Decode(o plumbing.EncodedObject) (err error)
Decode transforms a plumbing.EncodedObject into a Tag struct.
func (*Tag) Encode ¶
func (t *Tag) Encode(o plumbing.EncodedObject) error
Encode transforms a Tag into a plumbing.EncodedObject.
func (*Tag) ID ¶
ID returns the object ID of the tag, not the object that the tag references. The returned value will always match the current value of Tag.Hash.
ID is present to fulfill the Object interface.
func (*Tag) String ¶
String returns the meta information contained in the tag as a formatted string.
func (*Tag) Tree ¶
Tree returns the tree pointed to by the tag. If the tag points to a commit object the tree of that commit will be returned. If the tag does not point to a commit or tree object ErrUnsupportedObject will be returned.
func (*Tag) Type ¶
func (t *Tag) Type() plumbing.ObjectType
Type returns the type of object. It always returns plumbing.TagObject.
Type is present to fulfill the Object interface.
type TagIter ¶
type TagIter struct { storer.EncodedObjectIter // contains filtered or unexported fields }
TagIter provides an iterator for a set of tags.
func NewTagIter ¶
func NewTagIter(s storer.EncodedObjectStorer, iter storer.EncodedObjectIter) *TagIter
NewTagIter takes a storer.EncodedObjectStorer and a storer.EncodedObjectIter and returns a *TagIter that iterates over all tags contained in the storer.EncodedObjectIter.
Any non-tag object returned by the storer.EncodedObjectIter is skipped.
type Tree ¶
type Tree struct { Entries []TreeEntry Hash plumbing.Hash // contains filtered or unexported fields }
Tree is basically like a directory - it references a bunch of other trees and/or blobs (i.e. files and sub-directories)
func DecodeTree ¶
func DecodeTree(s storer.EncodedObjectStorer, o plumbing.EncodedObject) (*Tree, error)
DecodeTree decodes an encoded object into a *Tree and associates it to the given object storer.
func (*Tree) Decode ¶
func (t *Tree) Decode(o plumbing.EncodedObject) (err error)
Decode transform an plumbing.EncodedObject into a Tree struct
func (*Tree) Encode ¶
func (t *Tree) Encode(o plumbing.EncodedObject) error
Encode transforms a Tree into a plumbing.EncodedObject.
func (*Tree) File ¶
File returns the hash of the file identified by the `path` argument. The path is interpreted as relative to the tree receiver.
func (*Tree) ID ¶
ID returns the object ID of the tree. The returned value will always match the current value of Tree.Hash.
ID is present to fulfill the Object interface.
func (*Tree) Patch ¶
Patch returns a slice of Patch objects with all the changes between trees in chunks. This representation can be used to create several diff outputs.
func (*Tree) Tree ¶
Tree returns the tree identified by the `path` argument. The path is interpreted as relative to the tree receiver.
func (*Tree) TreeEntryFile ¶
TreeEntryFile returns the *File for a given *TreeEntry.
func (*Tree) Type ¶
func (t *Tree) Type() plumbing.ObjectType
Type returns the type of object. It always returns plumbing.TreeObject.
type TreeIter ¶
type TreeIter struct { storer.EncodedObjectIter // contains filtered or unexported fields }
TreeIter provides an iterator for a set of trees.
func NewTreeIter ¶
func NewTreeIter(s storer.EncodedObjectStorer, iter storer.EncodedObjectIter) *TreeIter
NewTreeIter takes a storer.EncodedObjectStorer and a storer.EncodedObjectIter and returns a *TreeIter that iterates over all tree contained in the storer.EncodedObjectIter.
Any non-tree object returned by the storer.EncodedObjectIter is skipped.
type TreeWalker ¶
type TreeWalker struct {
// contains filtered or unexported fields
}
TreeWalker provides a means of walking through all of the entries in a Tree.
func NewTreeWalker ¶
func NewTreeWalker(t *Tree, recursive bool) *TreeWalker
NewTreeWalker returns a new TreeWalker for the given tree.
It is the caller's responsibility to call Close() when finished with the tree walker.
func (*TreeWalker) Close ¶
func (w *TreeWalker) Close()
Close releases any resources used by the TreeWalker.
func (*TreeWalker) Next ¶
func (w *TreeWalker) Next() (name string, entry TreeEntry, err error)
Next returns the next object from the tree. Objects are returned in order and subtrees are included. After the last object has been returned further calls to Next() will return io.EOF.
In the current implementation any objects which cannot be found in the underlying repository will be skipped automatically. It is possible that this may change in future versions.
func (*TreeWalker) Tree ¶
func (w *TreeWalker) Tree() *Tree
Tree returns the tree that the tree walker most recently operated on.