From 37707aada0157f255dbad920b917efb601184e12 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 29 Mar 2026 13:38:19 +0000 Subject: commitquery: Reorganize --- commitquery/node_generation.go | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 commitquery/node_generation.go (limited to 'commitquery/node_generation.go') diff --git a/commitquery/node_generation.go b/commitquery/node_generation.go new file mode 100644 index 00000000..b04f3762 --- /dev/null +++ b/commitquery/node_generation.go @@ -0,0 +1,43 @@ +package commitquery + +import ( + "math" + + objectid "codeberg.org/lindenii/furgit/object/id" +) + +// EffectiveGeneration returns one node's generation value. +func (query *query) effectiveGeneration(idx nodeIndex) uint64 { + if !query.nodes[idx].hasGeneration { + return generationInfinity + } + + return query.nodes[idx].generation +} + +const ( + generationInfinity = uint64(math.MaxUint64) +) + +func (query *query) compareByGeneration() func(nodeIndex, nodeIndex) int { + return func(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) + } +} -- cgit v1.3.1-10-gc9f91