diff options
author | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-02-15 19:29:08 -0800 |
---|---|---|
committer | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-02-15 19:29:08 -0800 |
commit | 43a7081665d3b3754dd26f2b2cc8d0125ee74065 (patch) | |
tree | cff9c4630aa12aa7b0bc0d68ac0d7e69b0ff2dd5 | |
parent | f26d06d8b3dafae8b849bb0b812f2ce58df92423 (diff) | |
download | go-git-43a7081665d3b3754dd26f2b2cc8d0125ee74065.tar.gz |
Renamed ObjectStorage.IterType() to Iter() and improved documentation for object iterators
-rw-r--r-- | core/object.go | 19 | ||||
-rw-r--r-- | repository.go | 2 |
2 files changed, 15 insertions, 6 deletions
diff --git a/core/object.go b/core/object.go index 2c41245..9b6e56d 100644 --- a/core/object.go +++ b/core/object.go @@ -21,7 +21,7 @@ type ObjectStorage interface { New() Object Set(Object) Hash Get(Hash) (Object, bool) - IterType(ObjectType) ObjectIter + Iter(ObjectType) ObjectIter } // ObjectType internal object type's @@ -59,8 +59,13 @@ type ObjectIter interface { Close() } -// ObjectLookupIter yields a series of objects by retrieving each one from -// object storage. +// ObjectLookupIter implements ObjectIter. It iterates over a series of object +// hashes and yields their associated objects by retrieving each one from +// object storage. The retrievals are lazy and only occur when the iterator +// moves forward with a call to Next(). +// +// The ObjectLookupIter must be closed with a call to Close() when it is no +// longer needed. type ObjectLookupIter struct { storage ObjectStorage series []Hash @@ -99,7 +104,11 @@ func (iter *ObjectLookupIter) Close() { iter.pos = len(iter.series) } -// ObjectSliceIter yields a series of objects from a slice of objects. +// ObjectSliceIter implements ObjectIter. It iterates over a series of objects +// stored in a slice and yields each one in turn when Next() is called. +// +// The ObjectSliceIter must be closed with a call to Close() when it is no +// longer needed. type ObjectSliceIter struct { series []Object pos int @@ -189,7 +198,7 @@ func (o *RAWObjectStorage) Get(h Hash) (Object, bool) { return obj, ok } -func (o *RAWObjectStorage) IterType(t ObjectType) ObjectIter { +func (o *RAWObjectStorage) Iter(t ObjectType) ObjectIter { var series []Object switch t { case CommitObject: diff --git a/repository.go b/repository.go index 31e5fc7..d0bc103 100644 --- a/repository.go +++ b/repository.go @@ -100,7 +100,7 @@ func (r *Repository) Commit(h core.Hash) (*Commit, error) { // Commits decode the objects into commits func (r *Repository) Commits() *CommitIter { - return NewCommitIter(r, r.Storage.IterType(core.CommitObject)) + return NewCommitIter(r, r.Storage.Iter(core.CommitObject)) } // Tree return the tree with the given hash |