Skip to content

Commit

Permalink
Move CommitNode/CommitNodeIndex into separate object/commitgraph package
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Navara <[email protected]>
  • Loading branch information
filipnavara committed May 3, 2019
1 parent 79262fc commit a661bca
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package object
package commitgraph

import (
"io"
"time"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
)

Expand All @@ -14,7 +15,7 @@ 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)
Tree() (*object.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.
Expand All @@ -29,7 +30,7 @@ type CommitNode interface {
// 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)
Commit() (*object.Commit, error)
}

// CommitNodeIndex is generic interface encapsulating an index of CommitNode objects
Expand Down Expand Up @@ -59,7 +60,7 @@ func newParentgraphCommitNodeIter(node CommitNode) CommitNodeIter {
// there are no more commits, it returns io.EOF.
func (iter *parentCommitNodeIter) Next() (CommitNode, error) {
obj, err := iter.node.ParentNode(iter.i)
if err == ErrParentNotFound {
if err == object.ErrParentNotFound {
return nil, io.EOF
}
if err == nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package object
package commitgraph

import (
"fmt"
"time"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/format/commitgraph"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
)

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

// Fallback to loading full commit object
commit, err := GetCommit(gci.s, hash)
commit, err := object.GetCommit(gci.s, hash)
if err != nil {
return nil, err
}
Expand All @@ -72,8 +73,8 @@ func (c *graphCommitNode) ID() plumbing.Hash {
return c.hash
}

func (c *graphCommitNode) Tree() (*Tree, error) {
return GetTree(c.gci.s, c.commitData.TreeHash)
func (c *graphCommitNode) Tree() (*object.Tree, error) {
return object.GetTree(c.gci.s, c.commitData.TreeHash)
}

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

func (c *graphCommitNode) ParentNode(i int) (CommitNode, error) {
if i < 0 || i >= len(c.commitData.ParentIndexes) {
return nil, ErrParentNotFound
return nil, object.ErrParentNotFound
}

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

func (c *graphCommitNode) Commit() (*Commit, error) {
return GetCommit(c.gci.s, c.hash)
func (c *graphCommitNode) Commit() (*object.Commit, error) {
return object.GetCommit(c.gci.s, c.hash)
}

func (c *graphCommitNode) String() string {
return fmt.Sprintf(
"%s %s\nDate: %s",
plumbing.CommitObject, c.ID(),
c.CommitTime().Format(DateFormat),
c.CommitTime().Format(object.DateFormat),
)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package object
package commitgraph

import (
"math"
"time"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
)

Expand All @@ -13,7 +14,7 @@ import (
// objectCommitNode implements the CommitNode interface.
type objectCommitNode struct {
nodeIndex CommitNodeIndex
commit *Commit
commit *object.Commit
}

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

func (oci *objectCommitNodeIndex) Get(hash plumbing.Hash) (CommitNode, error) {
commit, err := GetCommit(oci.s, hash)
commit, err := object.GetCommit(oci.s, hash)
if err != nil {
return nil, err
}
Expand All @@ -50,7 +51,7 @@ func (c *objectCommitNode) ID() plumbing.Hash {
return c.commit.ID()
}

func (c *objectCommitNode) Tree() (*Tree, error) {
func (c *objectCommitNode) Tree() (*object.Tree, error) {
return c.commit.Tree()
}

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

func (c *objectCommitNode) ParentNode(i int) (CommitNode, error) {
if i < 0 || i >= len(c.commit.ParentHashes) {
return nil, ErrParentNotFound
return nil, object.ErrParentNotFound
}

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

func (c *objectCommitNode) Commit() (*Commit, error) {
func (c *objectCommitNode) Commit() (*object.Commit, error) {
return c.commit, nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package object
package commitgraph

import (
"path"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package object
package commitgraph

import (
"io"
Expand Down

0 comments on commit a661bca

Please sign in to comment.