From f42d82364c5d159f65a48e720433ad2bc97f0b7f Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Mon, 22 Aug 2016 00:18:02 +0200 Subject: Remote.Fetch multiple RefSpec support --- tree_walker.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tree_walker.go') diff --git a/tree_walker.go b/tree_walker.go index 5568e1b..1692c2f 100644 --- a/tree_walker.go +++ b/tree_walker.go @@ -3,6 +3,8 @@ package git import ( "io" "path" + + "gopkg.in/src-d/go-git.v4/core" ) const ( @@ -91,6 +93,27 @@ func (w *TreeWalker) Next() (name string, entry TreeEntry, obj Object, err error return } +func (w *TreeWalker) ForEach(cb func(fullpath string, e TreeEntry) error) error { + for { + path, e, _, err := w.Next() + if err != nil { + if err == io.EOF { + return nil + } + + return err + } + + if err := cb(path, e); err != nil { + if err == core.ErrStop { + return nil + } + + return err + } + } +} + // Tree returns the tree that the tree walker most recently operated on. func (w *TreeWalker) Tree() *Tree { current := len(w.stack) - 1 -- cgit