object

package
v4.0.0-rc8+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2017 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileMode       os.FileMode = 0100644
	ExecutableMode os.FileMode = 0100755
	SubmoduleMode  os.FileMode = 0160000
	SymlinkMode    os.FileMode = 0120000
	TreeMode       os.FileMode = 0040000
)
View Source
const DateFormat = "Mon Jan 02 15:04:05 2006 -0700"

DateFormat is the format being used in the original git implementation

Variables

View Source
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.

View Source
var ErrUnsupportedObject = errors.New("unsupported object type")

ErrUnsupportedObject trigger when a non-supported object is being decoded.

Functions

func ReverseSortCommits

func ReverseSortCommits(l []*Commit)

ReverseSortCommits sorts a commit list by commit date, from newer to older.

func SortCommits

func SortCommits(l []*Commit)

SortCommits sorts a commit list by commit date, from older to newer.

func WalkCommitHistory

func WalkCommitHistory(c *Commit, cb func(*Commit) error) error

WalkCommitHistory walks the commit history

Types

type Blob

type Blob struct {
	Hash plumbing.Hash
	Size int64
	// contains filtered or unexported fields
}

Blob is used to store file data - it is generally a file.

func DecodeBlob

func DecodeBlob(o plumbing.EncodedObject) (*Blob, error)

func GetBlob

GetBlob gets a blob from an object storer and decodes it.

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

func (b *Blob) ID() plumbing.Hash

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

NewBlobIter returns a BlobIter for the given repository and underlying object iterator.

The returned BlobIter will automatically skip over non-blob objects.

func (*BlobIter) ForEach

func (iter *BlobIter) ForEach(cb func(*Blob) error) error

ForEach call the cb function for each blob 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 (*BlobIter) Next

func (iter *BlobIter) Next() (*Blob, error)

Next moves the iterator to the next blob and returns a pointer to it. If it has reached the end of the set it will return io.EOF.

type Commit

type Commit struct {
	Hash      plumbing.Hash
	Author    Signature
	Committer Signature
	Message   string
	// 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

DecodeCommit decodes an encoded object into a *Commit and associates it to the given object storer.

func GetCommit

func GetCommit(s storer.EncodedObjectStorer, h plumbing.Hash) (*Commit, error)

GetCommit gets a commit from an object storer and decodes it.

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

func (c *Commit) File(path string) (*File, error)

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) Files

func (c *Commit) Files() (*FileIter, error)

Files returns a FileIter allowing to iterate over the Tree

func (*Commit) History

func (c *Commit) History() ([]*Commit, error)

History return a slice with the previous commits in the history of this commit

func (*Commit) ID

func (c *Commit) ID() plumbing.Hash

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

func (c *Commit) NumParents() int

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) String

func (c *Commit) String() string

func (*Commit) Tree

func (c *Commit) Tree() (*Tree, error)

Tree returns the Tree from the commit

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

type CommitIter struct {
	storer.EncodedObjectIter
	// contains filtered or unexported fields
}

CommitIter provides an iterator for a set of commits.

func NewCommitIter

NewCommitIter returns a CommitIter for the given object storer and underlying object iterator.

The returned CommitIter will automatically skip over non-commit objects.

func (*CommitIter) ForEach

func (iter *CommitIter) ForEach(cb func(*Commit) error) error

ForEach call the cb function for each commit contained on this iter until an error appends 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 (*CommitIter) Next

func (iter *CommitIter) Next() (*Commit, error)

Next moves the iterator to the next commit and returns a pointer to it. If it has reached the end of the set it will return io.EOF.

type File

type File struct {
	Name string
	Mode os.FileMode
	Blob
}

File represents git file objects.

func NewFile

func NewFile(name string, m os.FileMode, b *Blob) *File

NewFile returns a File based on the given blob object

func (*File) Contents

func (f *File) Contents() (content string, err error)

Contents returns the contents of a file as a string.

func (*File) Lines

func (f *File) Lines() ([]string, error)

Lines returns a slice of lines from the contents of a file, stripping all end of line characters. If the last line is empty (does not end in an end of line), it is also stripped.

type FileIter

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

func NewFileIter

func NewFileIter(s storer.EncodedObjectStorer, t *Tree) *FileIter

func (*FileIter) Close

func (iter *FileIter) Close()

func (*FileIter) ForEach

func (iter *FileIter) ForEach(cb func(*File) error) error

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

func (*FileIter) Next

func (iter *FileIter) Next() (*File, error)

type Hash

type Hash plumbing.Hash

Hash represents the hash of an object

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.

func DecodeObject

DecodeObject decodes an encoded object into an Object and associates it to the given object storer.

func GetObject

GetObject gets an object from an object storer and decodes it.

type ObjectIter

type ObjectIter struct {
	storer.EncodedObjectIter
	// contains filtered or unexported fields
}

ObjectIter provides an iterator for a set of objects.

func NewObjectIter

NewObjectIter returns a ObjectIter for the given repository and underlying object iterator.

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 it has reached the end of the set it will return io.EOF.

type Signature

type Signature struct {
	Name  string
	Email string
	When  time.Time
}

Signature represents an action signed by a person

func (*Signature) Decode

func (s *Signature) Decode(b []byte)

Decode decodes a byte slice into a signature

func (*Signature) Encode

func (s *Signature) Encode(w io.Writer) error

Encode encodes a Signature into a writer.

func (*Signature) String

func (s *Signature) String() string

type Tag

type Tag struct {
	Hash       plumbing.Hash
	Name       string
	Tagger     Signature
	Message    string
	TargetType plumbing.ObjectType
	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.

https://git-scm.com/book/en/v2/Git-Internals-Git-References#Tags

func DecodeTag

DecodeTag decodes an encoded object into a *Commit and associates it to the given object storer.

func GetTag

GetTag gets a tag from an object storer and decodes it.

func (*Tag) Blob

func (t *Tag) Blob() (*Blob, error)

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

func (t *Tag) Commit() (*Commit, error)

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

func (t *Tag) ID() plumbing.Hash

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) Object

func (t *Tag) Object() (Object, error)

Object returns the object pointed to by the tag.

func (*Tag) String

func (t *Tag) String() string

String returns the meta information contained in the tag as a formatted string.

func (*Tag) Tree

func (t *Tag) Tree() (*Tree, error)

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

NewTagIter returns a TagIter for the given object storer and underlying object iterator.

The returned TagIter will automatically skip over non-tag objects.

func (*TagIter) ForEach

func (iter *TagIter) ForEach(cb func(*Tag) error) error

ForEach call the cb function for each tag 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 (*TagIter) Next

func (iter *TagIter) Next() (*Tag, error)

Next moves the iterator to the next tag and returns a pointer to it. If it has reached the end of the set it will return io.EOF.

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

DecodeTree decodes an encoded object into a *Tree and associates it to the given object storer.

func GetTree

GetTree gets a tree from an object storer and decodes it.

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

func (t *Tree) File(path string) (*File, error)

File returns the hash of the file identified by the `path` argument. The path is interpreted as relative to the tree receiver.

func (*Tree) Files

func (t *Tree) Files() *FileIter

Files returns a FileIter allowing to iterate over the Tree

func (*Tree) ID

func (t *Tree) ID() plumbing.Hash

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) Tree

func (t *Tree) Tree(path string) (*Tree, error)

Tree returns the tree identified by the `path` argument. The path is interpreted as relative to the tree receiver.

func (*Tree) TreeEntryFile

func (t *Tree) TreeEntryFile(e *TreeEntry) (*File, error)

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 TreeEntry

type TreeEntry struct {
	Name string
	Mode os.FileMode
	Hash plumbing.Hash
}

TreeEntry represents a file

type TreeIter

type TreeIter struct {
	storer.EncodedObjectIter
	// contains filtered or unexported fields
}

TreeIter provides an iterator for a set of trees.

func NewTreeIter

NewTreeIter returns a TreeIter for the given repository and underlying object iterator.

The returned TreeIter will automatically skip over non-tree objects.

func (*TreeIter) ForEach

func (iter *TreeIter) ForEach(cb func(*Tree) error) error

ForEach call the cb function for each tree 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 (*TreeIter) Next

func (iter *TreeIter) Next() (*Tree, error)

Next moves the iterator to the next tree and returns a pointer to it. If it has reached the end of the set it will return io.EOF.

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.

Jump to

Keyboard shortcuts

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