aboutsummaryrefslogtreecommitdiff
path: root/commitquery/compare.go
blob: f64b5b3f347bc5d4509f244a0fd4d90c65364d87 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package commitquery

import "codeberg.org/lindenii/furgit/objectid"

// Compare compares two internal nodes using merge-base queue ordering.
func (query *Query) compare(left, right nodeIndex) int {
	leftGeneration := query.effectiveGeneration(left)
	rightGeneration := query.effectiveGeneration(right)

	switch {
	case leftGeneration < rightGeneration:
		return -1
	case leftGeneration > rightGeneration:
		return 1
	}

	switch {
	case query.nodes[left].commitTime < query.nodes[right].commitTime:
		return -1
	case query.nodes[left].commitTime > query.nodes[right].commitTime:
		return 1
	}

	return objectid.Compare(query.nodes[left].id, query.nodes[right].id)
}