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

Commit 58c7314

Browse files
committed
Move Commit() to CommitNode API
Signed-off-by: Filip Navara <filip.navara@gmail.com>
1 parent 9eb627f commit 58c7314

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

plumbing/object/commitnode.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,29 @@ import (
1313
// CommitNode is generic interface encapsulating either Commit object or
1414
// graphCommitNode object
1515
type CommitNode interface {
16+
// ID returns the Commit object id referenced by the commit graph node.
1617
ID() plumbing.Hash
18+
// Tree returns the Tree referenced by the commit graph node.
1719
Tree() (*Tree, error)
20+
// CommitTime returns the Commiter.When time of the Commit referenced by the commit graph node.
1821
CommitTime() time.Time
22+
// NumParents returns the number of parents in a commit.
1923
NumParents() int
24+
// ParentNodes return a CommitNodeIter for parents of specified node.
2025
ParentNodes() CommitNodeIter
26+
// ParentNode returns the ith parent of a commit.
2127
ParentNode(i int) (CommitNode, error)
28+
// ParentHashes returns hashes of the parent commits for a specified node
2229
ParentHashes() []plumbing.Hash
30+
// Commit returns the full commit object from the node
31+
Commit() (*Commit, error)
2332
}
2433

2534
// CommitNodeIndex is generic interface encapsulating an index of CommitNode objects
2635
// and accessor methods for walking it as a directed graph
2736
type CommitNodeIndex interface {
2837
// Get returns a commit node from a commit hash
2938
Get(hash plumbing.Hash) (CommitNode, error)
30-
// Commit returns the full commit object from the node
31-
Commit(node CommitNode) (*Commit, error)
3239
}
3340

3441
// CommitNodeIter is a generic closable interface for iterating over commit nodes.
@@ -127,6 +134,11 @@ func (c *graphCommitNode) ParentHashes() []plumbing.Hash {
127134
return c.node.ParentHashes
128135
}
129136

137+
// Commit returns the full Commit object representing the commit graph node.
138+
func (c *graphCommitNode) Commit() (*Commit, error) {
139+
return GetCommit(c.gci.s, c.hash)
140+
}
141+
130142
func (c *graphCommitNode) String() string {
131143
return fmt.Sprintf(
132144
"%s %s\nDate: %s",
@@ -169,15 +181,6 @@ func (gci *graphCommitNodeIndex) Get(hash plumbing.Hash) (CommitNode, error) {
169181
}, nil
170182
}
171183

172-
// Commit returns the full Commit object representing the commit graph node.
173-
func (gci *graphCommitNodeIndex) Commit(node CommitNode) (*Commit, error) {
174-
if cgn, ok := node.(*graphCommitNode); ok {
175-
return GetCommit(gci.s, cgn.ID())
176-
}
177-
co := node.(*objectCommitNode)
178-
return co.commit, nil
179-
}
180-
181184
// CommitTime returns the time when the commit was performed.
182185
func (c *objectCommitNode) CommitTime() time.Time {
183186
return c.commit.Committer.When
@@ -217,6 +220,11 @@ func (c *objectCommitNode) ParentHashes() []plumbing.Hash {
217220
return c.commit.ParentHashes
218221
}
219222

223+
// Commit returns the full Commit object representing the commit graph node.
224+
func (c *objectCommitNode) Commit() (*Commit, error) {
225+
return c.commit, nil
226+
}
227+
220228
func NewObjectCommitNodeIndex(s storer.EncodedObjectStorer) CommitNodeIndex {
221229
return &objectCommitNodeIndex{s}
222230
}

0 commit comments

Comments
 (0)