diff options
author | Santiago M. Mola <santi@mola.io> | 2016-11-04 16:12:01 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-11-04 16:12:01 +0100 |
commit | 07b8edee398163db2e61430414957df73aec7e20 (patch) | |
tree | 367dce24eb535374f2acd5466c9795cc000f3e68 /repository.go | |
parent | 03c4b83d745ecc86a2e3b795a72dfdef1218bab8 (diff) | |
download | go-git-07b8edee398163db2e61430414957df73aec7e20.tar.gz |
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.
Diffstat (limited to 'repository.go')
-rw-r--r-- | repository.go | 31 |
1 files changed, 31 insertions, 0 deletions
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) |