Debian Codegraph @

plumbing/object/commitgraph/commitnode_walker_date_order.go

raw
1 package commitgraph
2
3 import (
4 "github.com/go-git/go-git/v5/plumbing"
5
6 "github.com/emirpasic/gods/trees/binaryheap"
7 )
8
9 // NewCommitNodeIterDateOrder returns a CommitNodeIter that walks the commit history,
10 // starting at the given commit and visiting its parents in Committer Time and Generation order,
11 // but with the constraint that no parent is emitted before its children are emitted.
12 //
13 // This matches `git log --date-order`
14 func NewCommitNodeIterDateOrder(c CommitNode,
15 seenExternal map[plumbing.Hash]bool,
16 ignore []plumbing.Hash,
17 ) CommitNodeIter {
18 seen := make(map[plumbing.Hash]struct{})
19 for _, h := range ignore {
20 seen[h] = struct{}{}
21 }
22 for h, ext := range seenExternal {
23 if ext {
24 seen[h] = struct{}{}
25 }
26 }
27 inCounts := make(map[plumbing.Hash]int)
28
29 exploreHeap := &commitNodeHeap{binaryheap.NewWith(generationAndDateOrderComparator)}
30 exploreHeap.Push(c)
31
32 visitHeap := &commitNodeHeap{binaryheap.NewWith(generationAndDateOrderComparator)}
33 visitHeap.Push(c)
34
35 return &commitNodeIteratorTopological{
36 exploreStack: exploreHeap,
37 visitStack: visitHeap,
38 inCounts: inCounts,
39 ignore: seen,
40 }
41 }