( repoStorer storage.Storer, commitIterFunc func(*Commit) CommitIter, ref *plumbing.Reference, commitsPath *list.List, commitsLookup map[plumbing.Hash]*list.Element)
| 235 | } |
| 236 | |
| 237 | func addReference( |
| 238 | repoStorer storage.Storer, |
| 239 | commitIterFunc func(*Commit) CommitIter, |
| 240 | ref *plumbing.Reference, |
| 241 | commitsPath *list.List, |
| 242 | commitsLookup map[plumbing.Hash]*list.Element) error { |
| 243 | |
| 244 | _, exists := commitsLookup[ref.Hash()] |
| 245 | if exists { |
| 246 | // we already have it - skip the reference. |
| 247 | return nil |
| 248 | } |
| 249 | |
| 250 | refCommit, _ := GetCommit(repoStorer, ref.Hash()) |
| 251 | if refCommit == nil { |
| 252 | // if it's not a commit - skip it. |
| 253 | return nil |
| 254 | } |
| 255 | |
| 256 | var ( |
| 257 | refCommits []*Commit |
| 258 | parent *list.Element |
| 259 | ) |
| 260 | // collect all ref commits to add |
| 261 | commitIter := commitIterFunc(refCommit) |
| 262 | for c, e := commitIter.Next(); e == nil; { |
| 263 | parent, exists = commitsLookup[c.Hash] |
| 264 | if exists { |
| 265 | break |
| 266 | } |
| 267 | refCommits = append(refCommits, c) |
| 268 | c, e = commitIter.Next() |
| 269 | } |
| 270 | commitIter.Close() |
| 271 | |
| 272 | if parent == nil { |
| 273 | // common parent - not found |
| 274 | // add all commits to the path from this ref (maybe it's a HEAD and we don't have anything, yet) |
| 275 | for _, c := range refCommits { |
| 276 | parent = commitsPath.PushBack(c) |
| 277 | commitsLookup[c.Hash] = parent |
| 278 | } |
| 279 | } else { |
| 280 | // add ref's commits to the path in reverse order (from the latest) |
| 281 | for i := len(refCommits) - 1; i >= 0; i-- { |
| 282 | c := refCommits[i] |
| 283 | // insert before found common parent |
| 284 | parent = commitsPath.InsertBefore(c, parent) |
| 285 | commitsLookup[c.Hash] = parent |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | return nil |
| 290 | } |
| 291 | |
| 292 | func (it *commitAllIterator) Next() (*Commit, error) { |
| 293 | if it.currCommit == nil { |
no test coverage detected
searching dependent graphs…