diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-30 11:29:47 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-30 11:29:47 +0200 |
commit | 2c527d02ceac3879f82ab53645b6c7c03c0e5d71 (patch) | |
tree | ebdd08843d1f5c6df7dff366ad5de8b4b2977e8c /tree.go | |
parent | d47285fa6e39399f639d8a9c3209d7d9bfb63ce4 (diff) | |
download | go-git-2c527d02ceac3879f82ab53645b6c7c03c0e5d71.tar.gz |
TreeWalker optimization
Diffstat (limited to 'tree.go')
-rw-r--r-- | tree.go | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -269,12 +269,14 @@ func (iter *treeEntryIter) Next() (TreeEntry, error) { // TreeEntryIter facilitates iterating through the descendent subtrees of a // Tree. type TreeIter struct { + r *Repository w TreeWalker } // NewTreeIter returns a new TreeIter instance func NewTreeIter(r *Repository, t *Tree) *TreeIter { return &TreeIter{ + r: r, w: *NewTreeWalker(r, t), } } @@ -282,14 +284,16 @@ func NewTreeIter(r *Repository, t *Tree) *TreeIter { // Next returns the next Tree from the tree. func (iter *TreeIter) Next() (*Tree, error) { for { - _, _, obj, err := iter.w.Next() + _, entry, err := iter.w.Next() if err != nil { return nil, err } - if tree, ok := obj.(*Tree); ok { - return tree, nil + if !entry.Mode.IsDir() { + continue } + + return iter.r.Tree(entry.Hash) } } |