From 07b8edee398163db2e61430414957df73aec7e20 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Fri, 4 Nov 2016 16:12:01 +0100 Subject: add Blobs, Trees and Objects iters. (#114) * Now every object type as an iterator in Repository. * old TreeIter is TreeWalker again, TreeIter now matches the same behaviour as other iterators. --- repository.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'repository.go') diff --git a/repository.go b/repository.go index cd94159..553703a 100644 --- a/repository.go +++ b/repository.go @@ -259,6 +259,16 @@ func (r *Repository) Tree(h core.Hash) (*Tree, error) { return tree.(*Tree), nil } +// Trees decodes the objects into trees +func (r *Repository) Trees() (*TreeIter, error) { + iter, err := r.s.ObjectStorage().Iter(core.TreeObject) + if err != nil { + return nil, err + } + + return NewTreeIter(r, iter), nil +} + // Blob returns the blob with the given hash func (r *Repository) Blob(h core.Hash) (*Blob, error) { blob, err := r.Object(core.BlobObject, h) @@ -269,6 +279,16 @@ func (r *Repository) Blob(h core.Hash) (*Blob, error) { return blob.(*Blob), nil } +// Blobs decodes the objects into blobs +func (r *Repository) Blobs() (*BlobIter, error) { + iter, err := r.s.ObjectStorage().Iter(core.BlobObject) + if err != nil { + return nil, err + } + + return NewBlobIter(r, iter), nil +} + // Tag returns a tag with the given hash. func (r *Repository) Tag(h core.Hash) (*Tag, error) { tag, err := r.Object(core.TagObject, h) @@ -318,6 +338,17 @@ func (r *Repository) Object(t core.ObjectType, h core.Hash) (Object, error) { } } +// Objects returns an ObjectIter that can step through all of the annotated tags +// in the repository. +func (r *Repository) Objects() (*ObjectIter, error) { + iter, err := r.s.ObjectStorage().Iter(core.AnyObject) + if err != nil { + return nil, err + } + + return NewObjectIter(r, iter), nil +} + // Head returns the reference where HEAD is pointing func (r *Repository) Head() (*core.Reference, error) { return core.ResolveReference(r.s.ReferenceStorage(), core.HEAD) -- cgit