diff options
author | Filip Navara <filip.navara@gmail.com> | 2019-04-24 11:31:59 +0200 |
---|---|---|
committer | Filip Navara <filip.navara@gmail.com> | 2019-04-24 11:31:59 +0200 |
commit | 58c731411944090126f86208bcf0419d6ba84122 (patch) | |
tree | 559c720e8b1af72d1ae5cad623eb49ee3411bf7f /plumbing/object | |
parent | 9eb627fb7b86b2941fb96020f152cb5fd2df2bd3 (diff) | |
download | go-git-58c731411944090126f86208bcf0419d6ba84122.tar.gz |
Move Commit() to CommitNode API
Signed-off-by: Filip Navara <filip.navara@gmail.com>
Diffstat (limited to 'plumbing/object')
-rw-r--r-- | plumbing/object/commitnode.go | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/plumbing/object/commitnode.go b/plumbing/object/commitnode.go index a7af4a9..0717a65 100644 --- a/plumbing/object/commitnode.go +++ b/plumbing/object/commitnode.go @@ -13,13 +13,22 @@ import ( // CommitNode is generic interface encapsulating either Commit object or
// graphCommitNode object
type CommitNode interface {
+ // ID returns the Commit object id referenced by the commit graph node.
ID() plumbing.Hash
+ // Tree returns the Tree referenced by the commit graph node.
Tree() (*Tree, error)
+ // CommitTime returns the Commiter.When time of the Commit referenced by the commit graph node.
CommitTime() time.Time
+ // NumParents returns the number of parents in a commit.
NumParents() int
+ // ParentNodes return a CommitNodeIter for parents of specified node.
ParentNodes() CommitNodeIter
+ // ParentNode returns the ith parent of a commit.
ParentNode(i int) (CommitNode, error)
+ // ParentHashes returns hashes of the parent commits for a specified node
ParentHashes() []plumbing.Hash
+ // Commit returns the full commit object from the node
+ Commit() (*Commit, error)
}
// CommitNodeIndex is generic interface encapsulating an index of CommitNode objects
@@ -27,8 +36,6 @@ type CommitNode interface { type CommitNodeIndex interface {
// Get returns a commit node from a commit hash
Get(hash plumbing.Hash) (CommitNode, error)
- // Commit returns the full commit object from the node
- Commit(node CommitNode) (*Commit, error)
}
// CommitNodeIter is a generic closable interface for iterating over commit nodes.
@@ -127,6 +134,11 @@ func (c *graphCommitNode) ParentHashes() []plumbing.Hash { return c.node.ParentHashes
}
+// Commit returns the full Commit object representing the commit graph node.
+func (c *graphCommitNode) Commit() (*Commit, error) {
+ return GetCommit(c.gci.s, c.hash)
+}
+
func (c *graphCommitNode) String() string {
return fmt.Sprintf(
"%s %s\nDate: %s",
@@ -169,15 +181,6 @@ func (gci *graphCommitNodeIndex) Get(hash plumbing.Hash) (CommitNode, error) { }, nil
}
-// Commit returns the full Commit object representing the commit graph node.
-func (gci *graphCommitNodeIndex) Commit(node CommitNode) (*Commit, error) {
- if cgn, ok := node.(*graphCommitNode); ok {
- return GetCommit(gci.s, cgn.ID())
- }
- co := node.(*objectCommitNode)
- return co.commit, nil
-}
-
// CommitTime returns the time when the commit was performed.
func (c *objectCommitNode) CommitTime() time.Time {
return c.commit.Committer.When
@@ -217,6 +220,11 @@ func (c *objectCommitNode) ParentHashes() []plumbing.Hash { return c.commit.ParentHashes
}
+// Commit returns the full Commit object representing the commit graph node.
+func (c *objectCommitNode) Commit() (*Commit, error) {
+ return c.commit, nil
+}
+
func NewObjectCommitNodeIndex(s storer.EncodedObjectStorer) CommitNodeIndex {
return &objectCommitNodeIndex{s}
}
|