From e4246138cb9ffb819c052ba17a9fbdf915427291 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Mon, 29 Aug 2016 22:47:13 +0200 Subject: storage: Add object type hint parameter to ObjectStorage.Get. (#69) Some storage backends can optimize object lookup if they get the object type that is expected. So we the signature of the Get method is now Get(Hash, ObjectType). Added generic tests for storage backends. --- tree_walker.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'tree_walker.go') diff --git a/tree_walker.go b/tree_walker.go index 5568e1b..d4aa01a 100644 --- a/tree_walker.go +++ b/tree_walker.go @@ -9,6 +9,9 @@ const ( startingStackSize = 8 ) +const submoduleMode = 0160000 +const directoryMode = 0040000 + // TreeWalker provides a means of walking through all of the entries in a Tree. type TreeWalker struct { stack []treeEntryIter @@ -66,12 +69,14 @@ func (w *TreeWalker) Next() (name string, entry TreeEntry, obj Object, err error return } - obj, err = w.r.Object(entry.Hash) - if err == ErrObjectNotFound { - // FIXME: Avoid doing this here in case the caller actually cares about - // missing objects. + if entry.Mode == submoduleMode { err = nil - continue // ignore entries without hash (= submodule dirs) + continue + } + if entry.Mode.IsDir() { + obj, err = w.r.Tree(entry.Hash) + } else { + obj, err = w.r.Blob(entry.Hash) } name = path.Join(w.base, entry.Name) -- cgit