diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-08-28 09:44:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-28 09:44:08 +0200 |
commit | 96286b0a0a051bd4f55d625c64ca239978908d5d (patch) | |
tree | 1fecddbe0c384ab077e5588321362a672f0e9fc4 /plumbing/object/tree.go | |
parent | 631a45f55b397090ad7d817a3c72041cfc3729f3 (diff) | |
parent | d68f45f8aaca461167907c07e8c161be14e87157 (diff) | |
download | go-git-96286b0a0a051bd4f55d625c64ca239978908d5d.tar.gz |
Merge pull request #564 from strib/tree-walker-use-seen-cache
plumbing: use `seen` map in tree walker
Diffstat (limited to 'plumbing/object/tree.go')
-rw-r--r-- | plumbing/object/tree.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/plumbing/object/tree.go b/plumbing/object/tree.go index 512db9f..44ac720 100644 --- a/plumbing/object/tree.go +++ b/plumbing/object/tree.go @@ -297,9 +297,10 @@ func (iter *treeEntryIter) Next() (TreeEntry, error) { // TreeWalker provides a means of walking through all of the entries in a Tree. type TreeWalker struct { - stack []treeEntryIter + stack []*treeEntryIter base string recursive bool + seen map[plumbing.Hash]bool s storer.EncodedObjectStorer t *Tree @@ -309,13 +310,14 @@ type TreeWalker struct { // // It is the caller's responsibility to call Close() when finished with the // tree walker. -func NewTreeWalker(t *Tree, recursive bool) *TreeWalker { - stack := make([]treeEntryIter, 0, startingStackSize) - stack = append(stack, treeEntryIter{t, 0}) +func NewTreeWalker(t *Tree, recursive bool, seen map[plumbing.Hash]bool) *TreeWalker { + stack := make([]*treeEntryIter, 0, startingStackSize) + stack = append(stack, &treeEntryIter{t, 0}) return &TreeWalker{ stack: stack, recursive: recursive, + seen: seen, s: t.s, t: t, @@ -358,6 +360,10 @@ func (w *TreeWalker) Next() (name string, entry TreeEntry, err error) { return } + if w.seen[entry.Hash] { + continue + } + if entry.Mode == filemode.Dir { obj, err = GetTree(w.s, entry.Hash) } @@ -377,7 +383,7 @@ func (w *TreeWalker) Next() (name string, entry TreeEntry, err error) { } if t, ok := obj.(*Tree); ok { - w.stack = append(w.stack, treeEntryIter{t, 0}) + w.stack = append(w.stack, &treeEntryIter{t, 0}) w.base = path.Join(w.base, entry.Name) } |