diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-03-08 23:30:52 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-03-08 23:30:52 +0100 |
commit | b35fc295b4ac531adc72fc83f2af628c7c163c0e (patch) | |
tree | 0282f20de8279db354233d1d67e3743e08509020 /commit.go | |
parent | 9c9cdff966cc181296f400769d3c8596f17e743a (diff) | |
parent | 9e6a03b7956464ccd9d2fbacedd8e5cc23572d02 (diff) | |
download | go-git-b35fc295b4ac531adc72fc83f2af628c7c163c0e.tar.gz |
Merge pull request #39 from scjalliance/git-object-interface
Added Object interface for Commit, Tree, Blob and Tag
Diffstat (limited to 'commit.go')
-rw-r--r-- | commit.go | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -43,13 +43,28 @@ func (c *Commit) NumParents() int { } // File returns the file with the specified "path" in the commit and a -// nil error if the file exists. If the file does not exists, it returns +// nil error if the file exists. If the file does not exist, it returns // a nil file and the ErrFileNotFound error. func (c *Commit) File(path string) (file *File, err error) { return c.Tree().File(path) } -// Decode transform an core.Object into a Blob struct +// ID returns the object ID of the commit. The returned value will always match +// the current value of Commit.Hash. +// +// ID is present to fufill the Object interface. +func (c *Commit) ID() core.Hash { + return c.Hash +} + +// Type returns the type of object. It always returns core.CommitObject. +// +// Type is present to fufill the Object interface. +func (c *Commit) Type() core.ObjectType { + return core.CommitObject +} + +// Decode transforms a core.Object into a Commit struct. func (c *Commit) Decode(o core.Object) (err error) { if o.Type() != core.CommitObject { return ErrUnsupportedObject @@ -107,15 +122,22 @@ func (c *Commit) String() string { ) } +// CommitIter provides an iterator for a set of commits. type CommitIter struct { core.ObjectIter r *Repository } +// NewCommitIter returns a CommitIter for the given repository and underlying +// object iterator. +// +// The returned CommitIter will automatically skip over non-commit objects. func NewCommitIter(r *Repository, iter core.ObjectIter) *CommitIter { return &CommitIter{iter, r} } +// 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. func (iter *CommitIter) Next() (*Commit, error) { obj, err := iter.ObjectIter.Next() if err != nil { |