From 6b9a59be60de5b66aee14e9160ace80734008eca Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Mon, 15 Aug 2016 23:09:33 +0200 Subject: core: *Iter.ForEach method --- commit.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'commit.go') diff --git a/commit.go b/commit.go index 96b3147..5c9c113 100644 --- a/commit.go +++ b/commit.go @@ -154,6 +154,20 @@ func (iter *CommitIter) Next() (*Commit, error) { return commit, commit.Decode(obj) } +// ForEach call the cb function for each commit contained on this iter until +// an error happends or the end of the iter is reached. If ErrStop is sent +// the iteration is stop but no error is returned +func (iter *CommitIter) ForEach(cb func(*Commit) error) error { + return iter.ObjectIter.ForEach(func(obj core.Object) error { + commit := &Commit{r: iter.r} + if err := commit.Decode(obj); err != nil { + return err + } + + return cb(commit) + }) +} + type commitSorterer struct { l []*Commit } -- cgit