MCPcopy Index your code
hub / github.com/go-git/go-git / addReference

Function addReference

plumbing/object/commit_walker.go:237–290  ·  view source on GitHub ↗
(
	repoStorer storage.Storer,
	commitIterFunc func(*Commit) CommitIter,
	ref *plumbing.Reference,
	commitsPath *list.List,
	commitsLookup map[plumbing.Hash]*list.Element)

Source from the content-addressed store, hash-verified

235}
236
237func 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
292func (it *commitAllIterator) Next() (*Commit, error) {
293 if it.currCommit == nil {

Callers 1

NewCommitAllIterFunction · 0.85

Calls 5

GetCommitFunction · 0.85
commitIterFuncFunction · 0.85
HashMethod · 0.65
NextMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…