From 9e6a03b7956464ccd9d2fbacedd8e5cc23572d02 Mon Sep 17 00:00:00 2001 From: Joshua Sjoding Date: Thu, 3 Mar 2016 00:33:00 -0800 Subject: Added Object interface for Commit, Tree, Blob and Tag * New Object interface is distinct from core.Object * New Object interface is used in places where returned object could be of any type * Object is implemented by Commit, Tree, Blob, File and Tag * Added Repository.Object function for retrieving objects of any type * Tag.Object now returns Object instead of core.Object * Tag target hash is now publicly accessible * Renamed Tag.Type field to Tag.TargetType, making it distinct from Tag.Type function * Fixed infinite recursive loop in TagIter.Close * TreeWalker.Next now returns Object instead of core.Object * Removed some duplicate test setup code --- tree.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'tree.go') diff --git a/tree.go b/tree.go index c8bebd8..246bf8c 100644 --- a/tree.go +++ b/tree.go @@ -127,6 +127,19 @@ func (t *Tree) Files() *FileIter { return NewFileIter(t.r, t) } +// ID returns the object ID of the tree. The returned value will always match +// the current value of Tree.Hash. +// +// ID is present to fufill the Object interface. +func (t *Tree) ID() core.Hash { + return t.Hash +} + +// Type returns the type of object. It always returns core.TreeObject. +func (t *Tree) Type() core.ObjectType { + return core.TreeObject +} + // Decode transform an core.Object into a Tree struct func (t *Tree) Decode(o core.Object) (err error) { if o.Type() != core.TreeObject { @@ -229,12 +242,9 @@ func (iter *TreeIter) Next() (*Tree, error) { return nil, err } - if obj.Type() != core.TreeObject { - // Skip non-tree objects - continue + if tree, ok := obj.(*Tree); ok { + return tree, nil } - - return iter.w.Tree(), nil } } -- cgit