diff options
Diffstat (limited to 'plumbing/storer')
-rw-r--r-- | plumbing/storer/object.go | 6 | ||||
-rw-r--r-- | plumbing/storer/reference.go | 7 | ||||
-rw-r--r-- | plumbing/storer/reference_test.go | 24 |
3 files changed, 13 insertions, 24 deletions
diff --git a/plumbing/storer/object.go b/plumbing/storer/object.go index 3f41468..e793211 100644 --- a/plumbing/storer/object.go +++ b/plumbing/storer/object.go @@ -123,7 +123,7 @@ func (iter *EncodedObjectLookupIter) Next() (plumbing.EncodedObject, error) { } // ForEach call the cb function for each object contained on this iter until -// an error happends or the end of the iter is reached. If ErrStop is sent +// an error happens or the end of the iter is reached. If ErrStop is sent // the iteration is stop but no error is returned. The iterator is closed. func (iter *EncodedObjectLookupIter) ForEach(cb func(plumbing.EncodedObject) error) error { return ForEachIterator(iter, cb) @@ -168,7 +168,7 @@ func (iter *EncodedObjectSliceIter) Next() (plumbing.EncodedObject, error) { } // ForEach call the cb function for each object contained on this iter until -// an error happends or the end of the iter is reached. If ErrStop is sent +// an error happens or the end of the iter is reached. If ErrStop is sent // the iteration is stop but no error is returned. The iterator is closed. func (iter *EncodedObjectSliceIter) ForEach(cb func(plumbing.EncodedObject) error) error { return ForEachIterator(iter, cb) @@ -213,7 +213,7 @@ func (iter *MultiEncodedObjectIter) Next() (plumbing.EncodedObject, error) { } // ForEach call the cb function for each object contained on this iter until -// an error happends or the end of the iter is reached. If ErrStop is sent +// an error happens or the end of the iter is reached. If ErrStop is sent // the iteration is stop but no error is returned. The iterator is closed. func (iter *MultiEncodedObjectIter) ForEach(cb func(plumbing.EncodedObject) error) error { return ForEachIterator(iter, cb) diff --git a/plumbing/storer/reference.go b/plumbing/storer/reference.go index 988c784..ae80a39 100644 --- a/plumbing/storer/reference.go +++ b/plumbing/storer/reference.go @@ -16,6 +16,11 @@ var ErrMaxResolveRecursion = errors.New("max. recursion level reached") // ReferenceStorer is a generic storage of references. type ReferenceStorer interface { SetReference(*plumbing.Reference) error + // CheckAndSetReference sets the reference `new`, but if `old` is + // not `nil`, it first checks that the current stored value for + // `old.Name()` matches the given reference value in `old`. If + // not, it returns an error and doesn't update `new`. + CheckAndSetReference(new, old *plumbing.Reference) error Reference(plumbing.ReferenceName) (*plumbing.Reference, error) IterReferences() (ReferenceIter, error) RemoveReference(plumbing.ReferenceName) error @@ -121,7 +126,7 @@ func (iter *ReferenceSliceIter) Next() (*plumbing.Reference, error) { } // ForEach call the cb function for each reference contained on this iter until -// an error happends or the end of the iter is reached. If ErrStop is sent +// an error happens or the end of the iter is reached. If ErrStop is sent // the iteration is stop but no error is returned. The iterator is closed. func (iter *ReferenceSliceIter) ForEach(cb func(*plumbing.Reference) error) error { defer iter.Close() diff --git a/plumbing/storer/reference_test.go b/plumbing/storer/reference_test.go index 5738eef..490ec95 100644 --- a/plumbing/storer/reference_test.go +++ b/plumbing/storer/reference_test.go @@ -97,11 +97,7 @@ func (s *ReferenceSuite) TestReferenceFilteredIterNext(c *C) { } i := NewReferenceFilteredIter(func(r *plumbing.Reference) bool { - if r.Name() == "bar" { - return true - } - - return false + return r.Name() == "bar" }, NewReferenceSliceIter(slice)) foo, err := i.Next() c.Assert(err, IsNil) @@ -120,11 +116,7 @@ func (s *ReferenceSuite) TestReferenceFilteredIterForEach(c *C) { } i := NewReferenceFilteredIter(func(r *plumbing.Reference) bool { - if r.Name() == "bar" { - return true - } - - return false + return r.Name() == "bar" }, NewReferenceSliceIter(slice)) var count int i.ForEach(func(r *plumbing.Reference) error { @@ -143,11 +135,7 @@ func (s *ReferenceSuite) TestReferenceFilteredIterError(c *C) { } i := NewReferenceFilteredIter(func(r *plumbing.Reference) bool { - if r.Name() == "bar" { - return true - } - - return false + return r.Name() == "bar" }, NewReferenceSliceIter(slice)) var count int exampleErr := errors.New("SOME ERROR") @@ -172,11 +160,7 @@ func (s *ReferenceSuite) TestReferenceFilteredIterForEachStop(c *C) { } i := NewReferenceFilteredIter(func(r *plumbing.Reference) bool { - if r.Name() == "bar" { - return true - } - - return false + return r.Name() == "bar" }, NewReferenceSliceIter(slice)) var count int |