aboutsummaryrefslogtreecommitdiffstats
path: root/tree.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-30 11:29:47 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-30 11:29:47 +0200
commit2c527d02ceac3879f82ab53645b6c7c03c0e5d71 (patch)
treeebdd08843d1f5c6df7dff366ad5de8b4b2977e8c /tree.go
parentd47285fa6e39399f639d8a9c3209d7d9bfb63ce4 (diff)
downloadgo-git-2c527d02ceac3879f82ab53645b6c7c03c0e5d71.tar.gz
TreeWalker optimization
Diffstat (limited to 'tree.go')
-rw-r--r--tree.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/tree.go b/tree.go
index 95fbcb5..eaa0c15 100644
--- a/tree.go
+++ b/tree.go
@@ -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)
}
}