diff options
author | Paulo Gomes <pjbgf@linux.com> | 2023-10-13 23:06:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-13 23:06:19 +0100 |
commit | 72ce9961c676b73c9bdd0678b64af7b0a42253f8 (patch) | |
tree | 3e6c8e7b0706918455a2d85fe6629242acab163f /plumbing/object/commitgraph/commitnode_walker_date_order.go | |
parent | 24261e8288b2483628d69c751dd310ac79c38b2e (diff) | |
parent | 69b88d9bda44ebfe1d56a7624b956d9e20818c0e (diff) | |
download | go-git-72ce9961c676b73c9bdd0678b64af7b0a42253f8.tar.gz |
Merge pull request #869 from zeripath/graph-generation-2v5.10.0
plumbing: commitgraph, Add generation v2 support
Diffstat (limited to 'plumbing/object/commitgraph/commitnode_walker_date_order.go')
-rw-r--r-- | plumbing/object/commitgraph/commitnode_walker_date_order.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/plumbing/object/commitgraph/commitnode_walker_date_order.go b/plumbing/object/commitgraph/commitnode_walker_date_order.go new file mode 100644 index 0000000..659a4fa --- /dev/null +++ b/plumbing/object/commitgraph/commitnode_walker_date_order.go @@ -0,0 +1,41 @@ +package commitgraph + +import ( + "github.com/go-git/go-git/v5/plumbing" + + "github.com/emirpasic/gods/trees/binaryheap" +) + +// NewCommitNodeIterDateOrder returns a CommitNodeIter that walks the commit history, +// starting at the given commit and visiting its parents in Committer Time and Generation order, +// but with the constraint that no parent is emitted before its children are emitted. +// +// This matches `git log --date-order` +func NewCommitNodeIterDateOrder(c CommitNode, + seenExternal map[plumbing.Hash]bool, + ignore []plumbing.Hash, +) CommitNodeIter { + seen := make(map[plumbing.Hash]struct{}) + for _, h := range ignore { + seen[h] = struct{}{} + } + for h, ext := range seenExternal { + if ext { + seen[h] = struct{}{} + } + } + inCounts := make(map[plumbing.Hash]int) + + exploreHeap := &commitNodeHeap{binaryheap.NewWith(generationAndDateOrderComparator)} + exploreHeap.Push(c) + + visitHeap := &commitNodeHeap{binaryheap.NewWith(generationAndDateOrderComparator)} + visitHeap.Push(c) + + return &commitNodeIteratorTopological{ + exploreStack: exploreHeap, + visitStack: visitHeap, + inCounts: inCounts, + ignore: seen, + } +} |