Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 5f53b23

Browse files
committed
Expose Generation property on CommitNode
Signed-off-by: Filip Navara <filip.navara@gmail.com>
1 parent a47126b commit 5f53b23

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

plumbing/object/commitnode.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ type CommitNode interface {
2525
ParentNode(i int) (CommitNode, error)
2626
// ParentHashes returns hashes of the parent commits for a specified node
2727
ParentHashes() []plumbing.Hash
28+
// Generation returns the generation of the commit for reachability analysis.
29+
// Objects with newer generation are not reachable from objects of older generation.
30+
Generation() uint64
2831
// Commit returns the full commit object from the node
2932
Commit() (*Commit, error)
3033
}

plumbing/object/commitnode_graph.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ func (c *graphCommitNode) ParentHashes() []plumbing.Hash {
110110
return c.commitData.ParentHashes
111111
}
112112

113+
func (c *graphCommitNode) Generation() uint64 {
114+
// If the commit-graph file was generated with older Git version that
115+
// set the generation to zero for every commit the generation assumption
116+
// is still valid. It is just less useful.
117+
return uint64(c.commitData.Generation)
118+
}
119+
113120
func (c *graphCommitNode) Commit() (*Commit, error) {
114121
return GetCommit(c.gci.s, c.hash)
115122
}

plumbing/object/commitnode_object.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package object
22

33
import (
4+
"math"
45
"time"
56

67
"gopkg.in/src-d/go-git.v4/plumbing"
@@ -76,6 +77,13 @@ func (c *objectCommitNode) ParentHashes() []plumbing.Hash {
7677
return c.commit.ParentHashes
7778
}
7879

80+
func (c *objectCommitNode) Generation() uint64 {
81+
// Commit nodes representing objects outside of the commit graph can never
82+
// be reached by objects from the commit-graph thus we return the highest
83+
// possible value.
84+
return math.MaxUint64
85+
}
86+
7987
func (c *objectCommitNode) Commit() (*Commit, error) {
8088
return c.commit, nil
8189
}

0 commit comments

Comments
 (0)