diff options
author | Joshua Sjoding <joshs@scjalliance.com> | 2016-01-23 00:50:29 -0800 |
---|---|---|
committer | Joshua Sjoding <joshs@scjalliance.com> | 2016-01-23 00:50:29 -0800 |
commit | 7ba1014b73e4d466320a29f7e3f47fcefe58695d (patch) | |
tree | be9ff334eaae5547651d2084021fcfd4b70a9db9 /commit.go | |
parent | 050fb78d77b30014acd0b6eefc88ec8a49c20371 (diff) | |
download | go-git-7ba1014b73e4d466320a29f7e3f47fcefe58695d.tar.gz |
Repository now works against the generic ObjectStore interface
Diffstat (limited to 'commit.go')
-rw-r--r-- | commit.go | 57 |
1 files changed, 10 insertions, 47 deletions
@@ -34,16 +34,7 @@ func (c *Commit) Tree() *Tree { } func (c *Commit) Parents() *CommitIter { - i := NewCommitIter(c.r) - go func() { - defer i.Close() - for _, hash := range c.parents { - obj, _ := c.r.Storage.Get(hash) - i.Add(obj) - } - }() - - return i + return NewCommitIter(c.r, core.NewObjectLookupIter(c.r.Storage, c.parents)) } // NumParents returns the number of parents in a commit. @@ -106,52 +97,24 @@ func (c *Commit) String() string { } type CommitIter struct { - iter + core.ObjectIter + r *Repository } -func NewCommitIter(r *Repository) *CommitIter { - return &CommitIter{newIter(r)} +func NewCommitIter(r *Repository, iter core.ObjectIter) *CommitIter { + return &CommitIter{iter, r} } -func (i *CommitIter) Next() (*Commit, error) { - obj := <-i.ch - if obj == nil { - return nil, io.EOF +func (iter *CommitIter) Next() (*Commit, error) { + obj, err := iter.ObjectIter.Next() + if err != nil { + return nil, err } - commit := &Commit{r: i.r} + commit := &Commit{r: iter.r} return commit, commit.Decode(obj) } -type iter struct { - ch chan core.Object - r *Repository - - IsClosed bool -} - -func newIter(r *Repository) iter { - ch := make(chan core.Object, 1) - return iter{ch: ch, r: r} -} - -func (i *iter) Add(o core.Object) { - if i.IsClosed { - return - } - - i.ch <- o -} - -func (i *iter) Close() { - if i.IsClosed { - return - } - - defer func() { i.IsClosed = true }() - close(i.ch) -} - type commitSorterer struct { l []*Commit } |