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

Commit a661bca

Browse files
committed
Move CommitNode/CommitNodeIndex into separate object/commitgraph package
Signed-off-by: Filip Navara <filip.navara@gmail.com>
1 parent 79262fc commit a661bca

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

plumbing/object/commitnode.go renamed to plumbing/object/commitgraph/commitnode.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package object
1+
package commitgraph
22

33
import (
44
"io"
55
"time"
66

77
"gopkg.in/src-d/go-git.v4/plumbing"
8+
"gopkg.in/src-d/go-git.v4/plumbing/object"
89
"gopkg.in/src-d/go-git.v4/plumbing/storer"
910
)
1011

@@ -14,7 +15,7 @@ type CommitNode interface {
1415
// ID returns the Commit object id referenced by the commit graph node.
1516
ID() plumbing.Hash
1617
// Tree returns the Tree referenced by the commit graph node.
17-
Tree() (*Tree, error)
18+
Tree() (*object.Tree, error)
1819
// CommitTime returns the Commiter.When time of the Commit referenced by the commit graph node.
1920
CommitTime() time.Time
2021
// NumParents returns the number of parents in a commit.
@@ -29,7 +30,7 @@ type CommitNode interface {
2930
// Objects with newer generation are not reachable from objects of older generation.
3031
Generation() uint64
3132
// Commit returns the full commit object from the node
32-
Commit() (*Commit, error)
33+
Commit() (*object.Commit, error)
3334
}
3435

3536
// CommitNodeIndex is generic interface encapsulating an index of CommitNode objects
@@ -59,7 +60,7 @@ func newParentgraphCommitNodeIter(node CommitNode) CommitNodeIter {
5960
// there are no more commits, it returns io.EOF.
6061
func (iter *parentCommitNodeIter) Next() (CommitNode, error) {
6162
obj, err := iter.node.ParentNode(iter.i)
62-
if err == ErrParentNotFound {
63+
if err == object.ErrParentNotFound {
6364
return nil, io.EOF
6465
}
6566
if err == nil {

plumbing/object/commitnode_graph.go renamed to plumbing/object/commitgraph/commitnode_graph.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
package object
1+
package commitgraph
22

33
import (
44
"fmt"
55
"time"
66

77
"gopkg.in/src-d/go-git.v4/plumbing"
88
"gopkg.in/src-d/go-git.v4/plumbing/format/commitgraph"
9+
"gopkg.in/src-d/go-git.v4/plumbing/object"
910
"gopkg.in/src-d/go-git.v4/plumbing/storer"
1011
)
1112

@@ -57,7 +58,7 @@ func (gci *graphCommitNodeIndex) Get(hash plumbing.Hash) (CommitNode, error) {
5758
}
5859

5960
// Fallback to loading full commit object
60-
commit, err := GetCommit(gci.s, hash)
61+
commit, err := object.GetCommit(gci.s, hash)
6162
if err != nil {
6263
return nil, err
6364
}
@@ -72,8 +73,8 @@ func (c *graphCommitNode) ID() plumbing.Hash {
7273
return c.hash
7374
}
7475

75-
func (c *graphCommitNode) Tree() (*Tree, error) {
76-
return GetTree(c.gci.s, c.commitData.TreeHash)
76+
func (c *graphCommitNode) Tree() (*object.Tree, error) {
77+
return object.GetTree(c.gci.s, c.commitData.TreeHash)
7778
}
7879

7980
func (c *graphCommitNode) CommitTime() time.Time {
@@ -90,7 +91,7 @@ func (c *graphCommitNode) ParentNodes() CommitNodeIter {
9091

9192
func (c *graphCommitNode) ParentNode(i int) (CommitNode, error) {
9293
if i < 0 || i >= len(c.commitData.ParentIndexes) {
93-
return nil, ErrParentNotFound
94+
return nil, object.ErrParentNotFound
9495
}
9596

9697
parent, err := c.gci.commitGraph.GetCommitDataByIndex(c.commitData.ParentIndexes[i])
@@ -117,14 +118,14 @@ func (c *graphCommitNode) Generation() uint64 {
117118
return uint64(c.commitData.Generation)
118119
}
119120

120-
func (c *graphCommitNode) Commit() (*Commit, error) {
121-
return GetCommit(c.gci.s, c.hash)
121+
func (c *graphCommitNode) Commit() (*object.Commit, error) {
122+
return object.GetCommit(c.gci.s, c.hash)
122123
}
123124

124125
func (c *graphCommitNode) String() string {
125126
return fmt.Sprintf(
126127
"%s %s\nDate: %s",
127128
plumbing.CommitObject, c.ID(),
128-
c.CommitTime().Format(DateFormat),
129+
c.CommitTime().Format(object.DateFormat),
129130
)
130131
}

plumbing/object/commitnode_object.go renamed to plumbing/object/commitgraph/commitnode_object.go

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

33
import (
44
"math"
55
"time"
66

77
"gopkg.in/src-d/go-git.v4/plumbing"
8+
"gopkg.in/src-d/go-git.v4/plumbing/object"
89
"gopkg.in/src-d/go-git.v4/plumbing/storer"
910
)
1011

@@ -13,7 +14,7 @@ import (
1314
// objectCommitNode implements the CommitNode interface.
1415
type objectCommitNode struct {
1516
nodeIndex CommitNodeIndex
16-
commit *Commit
17+
commit *object.Commit
1718
}
1819

1920
// NewObjectCommitNodeIndex returns CommitNodeIndex implementation that uses
@@ -23,7 +24,7 @@ func NewObjectCommitNodeIndex(s storer.EncodedObjectStorer) CommitNodeIndex {
2324
}
2425

2526
func (oci *objectCommitNodeIndex) Get(hash plumbing.Hash) (CommitNode, error) {
26-
commit, err := GetCommit(oci.s, hash)
27+
commit, err := object.GetCommit(oci.s, hash)
2728
if err != nil {
2829
return nil, err
2930
}
@@ -50,7 +51,7 @@ func (c *objectCommitNode) ID() plumbing.Hash {
5051
return c.commit.ID()
5152
}
5253

53-
func (c *objectCommitNode) Tree() (*Tree, error) {
54+
func (c *objectCommitNode) Tree() (*object.Tree, error) {
5455
return c.commit.Tree()
5556
}
5657

@@ -64,7 +65,7 @@ func (c *objectCommitNode) ParentNodes() CommitNodeIter {
6465

6566
func (c *objectCommitNode) ParentNode(i int) (CommitNode, error) {
6667
if i < 0 || i >= len(c.commit.ParentHashes) {
67-
return nil, ErrParentNotFound
68+
return nil, object.ErrParentNotFound
6869
}
6970

7071
// Note: It's necessary to go through CommitNodeIndex here to ensure
@@ -84,6 +85,6 @@ func (c *objectCommitNode) Generation() uint64 {
8485
return math.MaxUint64
8586
}
8687

87-
func (c *objectCommitNode) Commit() (*Commit, error) {
88+
func (c *objectCommitNode) Commit() (*object.Commit, error) {
8889
return c.commit, nil
8990
}

plumbing/object/commitnode_test.go renamed to plumbing/object/commitgraph/commitnode_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package object
1+
package commitgraph
22

33
import (
44
"path"

plumbing/object/commitnode_walker_ctime.go renamed to plumbing/object/commitgraph/commitnode_walker_ctime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package object
1+
package commitgraph
22

33
import (
44
"io"

0 commit comments

Comments
 (0)