Fast implementation of Git in pure Go
at master 43 lines 971 B view raw
1package commitquery 2 3import ( 4 "math" 5 6 "codeberg.org/lindenii/furgit/objectid" 7) 8 9// EffectiveGeneration returns one node's generation value. 10func (query *Query) effectiveGeneration(idx nodeIndex) uint64 { 11 if !query.nodes[idx].hasGeneration { 12 return generationInfinity 13 } 14 15 return query.nodes[idx].generation 16} 17 18const ( 19 generationInfinity = uint64(math.MaxUint64) 20) 21 22func compareByGeneration(query *Query) func(nodeIndex, nodeIndex) int { 23 return func(left, right nodeIndex) int { 24 leftGeneration := query.effectiveGeneration(left) 25 rightGeneration := query.effectiveGeneration(right) 26 27 switch { 28 case leftGeneration < rightGeneration: 29 return -1 30 case leftGeneration > rightGeneration: 31 return 1 32 } 33 34 switch { 35 case query.nodes[left].commitTime < query.nodes[right].commitTime: 36 return -1 37 case query.nodes[left].commitTime > query.nodes[right].commitTime: 38 return 1 39 } 40 41 return objectid.Compare(query.nodes[left].id, query.nodes[right].id) 42 } 43}