NewCommitAllIter returns a new commit iterator for all refs. repoStorer is a repo Storer used to get commits and references. commitIterFunc is a commit iterator function, used to iterate through ref commits in chosen order
(repoStorer storage.Storer, commitIterFunc func(*Commit) CommitIter)
| 194 | // repoStorer is a repo Storer used to get commits and references. |
| 195 | // commitIterFunc is a commit iterator function, used to iterate through ref commits in chosen order |
| 196 | func NewCommitAllIter(repoStorer storage.Storer, commitIterFunc func(*Commit) CommitIter) (CommitIter, error) { |
| 197 | commitsPath := list.New() |
| 198 | commitsLookup := make(map[plumbing.Hash]*list.Element) |
| 199 | head, err := storer.ResolveReference(repoStorer, plumbing.HEAD) |
| 200 | if err == nil { |
| 201 | err = addReference(repoStorer, commitIterFunc, head, commitsPath, commitsLookup) |
| 202 | } |
| 203 | |
| 204 | if err != nil && err != plumbing.ErrReferenceNotFound { |
| 205 | return nil, err |
| 206 | } |
| 207 | |
| 208 | // add all references along with the HEAD |
| 209 | refIter, err := repoStorer.IterReferences() |
| 210 | if err != nil { |
| 211 | return nil, err |
| 212 | } |
| 213 | defer refIter.Close() |
| 214 | |
| 215 | for { |
| 216 | ref, err := refIter.Next() |
| 217 | if err == io.EOF { |
| 218 | break |
| 219 | } |
| 220 | |
| 221 | if err == plumbing.ErrReferenceNotFound { |
| 222 | continue |
| 223 | } |
| 224 | |
| 225 | if err != nil { |
| 226 | return nil, err |
| 227 | } |
| 228 | |
| 229 | if err = addReference(repoStorer, commitIterFunc, ref, commitsPath, commitsLookup); err != nil { |
| 230 | return nil, err |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | return &commitAllIterator{commitsPath.Front()}, nil |
| 235 | } |
| 236 | |
| 237 | func addReference( |
| 238 | repoStorer storage.Storer, |
no test coverage detected
searching dependent graphs…