diff options
Diffstat (limited to 'plumbing/object')
-rw-r--r-- | plumbing/object/commitnode.go | 3 | ||||
-rw-r--r-- | plumbing/object/commitnode_graph.go | 7 | ||||
-rw-r--r-- | plumbing/object/commitnode_object.go | 8 |
3 files changed, 18 insertions, 0 deletions
diff --git a/plumbing/object/commitnode.go b/plumbing/object/commitnode.go index 22927f4..ce25487 100644 --- a/plumbing/object/commitnode.go +++ b/plumbing/object/commitnode.go @@ -25,6 +25,9 @@ type CommitNode interface { ParentNode(i int) (CommitNode, error)
// ParentHashes returns hashes of the parent commits for a specified node
ParentHashes() []plumbing.Hash
+ // Generation returns the generation of the commit for reachability analysis.
+ // Objects with newer generation are not reachable from objects of older generation.
+ Generation() uint64
// Commit returns the full commit object from the node
Commit() (*Commit, error)
}
diff --git a/plumbing/object/commitnode_graph.go b/plumbing/object/commitnode_graph.go index b2a6f57..ac790ab 100644 --- a/plumbing/object/commitnode_graph.go +++ b/plumbing/object/commitnode_graph.go @@ -110,6 +110,13 @@ func (c *graphCommitNode) ParentHashes() []plumbing.Hash { return c.commitData.ParentHashes
}
+func (c *graphCommitNode) Generation() uint64 {
+ // If the commit-graph file was generated with older Git version that
+ // set the generation to zero for every commit the generation assumption
+ // is still valid. It is just less useful.
+ return uint64(c.commitData.Generation)
+}
+
func (c *graphCommitNode) Commit() (*Commit, error) {
return GetCommit(c.gci.s, c.hash)
}
diff --git a/plumbing/object/commitnode_object.go b/plumbing/object/commitnode_object.go index 52316f8..9ac42d2 100644 --- a/plumbing/object/commitnode_object.go +++ b/plumbing/object/commitnode_object.go @@ -1,6 +1,7 @@ package object
import (
+ "math"
"time"
"gopkg.in/src-d/go-git.v4/plumbing"
@@ -76,6 +77,13 @@ func (c *objectCommitNode) ParentHashes() []plumbing.Hash { return c.commit.ParentHashes
}
+func (c *objectCommitNode) Generation() uint64 {
+ // Commit nodes representing objects outside of the commit graph can never
+ // be reached by objects from the commit-graph thus we return the highest
+ // possible value.
+ return math.MaxUint64
+}
+
func (c *objectCommitNode) Commit() (*Commit, error) {
return c.commit, nil
}
|