aboutsummaryrefslogtreecommitdiffstats
path: root/tree_walker.go
diff options
context:
space:
mode:
Diffstat (limited to 'tree_walker.go')
-rw-r--r--tree_walker.go23
1 files changed, 23 insertions, 0 deletions
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