1package v2
2
3import (
4 "io"
5 "math"
6 "time"
7
8 "github.com/go-git/go-git/v5/plumbing"
9)
10
11// CommitData is a reduced representation of Commit as presented in the commit graph
12// file. It is merely useful as an optimization for walking the commit graphs.
13type CommitData struct {
14 // TreeHash is the hash of the root tree of the commit.
15 TreeHash plumbing.Hash
16 // ParentIndexes are the indexes of the parent commits of the commit.
17 ParentIndexes []uint32
18 // ParentHashes are the hashes of the parent commits of the commit.
19 ParentHashes []plumbing.Hash
20 // Generation number is the pre-computed generation in the commit graph
21 // or zero if not available.
22 Generation uint64
23 // GenerationV2 stores the corrected commit date for the commits
24 // It combines the contents of the GDA2 and GDO2 sections of the commit-graph
25 // with the commit time portion of the CDAT section.
26 GenerationV2 uint64
27 // When is the timestamp of the commit.
28 When time.Time
29}
30
31// GenerationV2Data returns the corrected commit date for the commits
32func (c *CommitData) GenerationV2Data() uint64 {
33 if c.GenerationV2 == 0 || c.GenerationV2 == math.MaxUint64 {
34 return 0
35 }
36 return c.GenerationV2 - uint64(c.When.Unix())
37}
38
39// Index represents a representation of commit graph that allows indexed
40// access to the nodes using commit object hash
41type Index interface {
42 // GetIndexByHash gets the index in the commit graph from commit hash, if available
43 GetIndexByHash(h plumbing.Hash) (uint32, error)
44 // GetHashByIndex gets the hash given an index in the commit graph
45 GetHashByIndex(i uint32) (plumbing.Hash, error)
46 // GetNodeByIndex gets the commit node from the commit graph using index
47 // obtained from child node, if available
48 GetCommitDataByIndex(i uint32) (*CommitData, error)
49 // Hashes returns all the hashes that are available in the index
50 Hashes() []plumbing.Hash
51 // HasGenerationV2 returns true if the commit graph has the corrected commit date data
52 HasGenerationV2() bool
53 // MaximumNumberOfHashes returns the maximum number of hashes within the index
54 MaximumNumberOfHashes() uint32
55
56 io.Closer
57}