aboutsummaryrefslogtreecommitdiffstats
path: root/tree.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-11-08 23:46:38 +0100
committerGitHub <noreply@github.com>2016-11-08 23:46:38 +0100
commitac095bb12c4d29722b60ba9f20590fa7cfa6bc7d (patch)
tree223f36f336ba3414b1e45cac8af6c4744a5d7ef6 /tree.go
parente523701393598f4fa241dd407af9ff8925507a1a (diff)
downloadgo-git-ac095bb12c4d29722b60ba9f20590fa7cfa6bc7d.tar.gz
new plumbing package (#118)
* plumbing: now core was renamed to core, and formats and clients moved inside
Diffstat (limited to 'tree.go')
-rw-r--r--tree.go43
1 files changed, 22 insertions, 21 deletions
diff --git a/tree.go b/tree.go
index 4d08396..753ed0c 100644
--- a/tree.go
+++ b/tree.go
@@ -10,7 +10,8 @@ import (
"strconv"
"strings"
- "gopkg.in/src-d/go-git.v4/core"
+ "gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/plumbing/storer"
)
const (
@@ -30,7 +31,7 @@ var (
// and/or blobs (i.e. files and sub-directories)
type Tree struct {
Entries []TreeEntry
- Hash core.Hash
+ Hash plumbing.Hash
r *Repository
m map[string]*TreeEntry
@@ -40,7 +41,7 @@ type Tree struct {
type TreeEntry struct {
Name string
Mode os.FileMode
- Hash core.Hash
+ Hash plumbing.Hash
}
// File returns the hash of the file identified by the `path` argument.
@@ -51,7 +52,7 @@ func (t *Tree) File(path string) (*File, error) {
return nil, ErrFileNotFound
}
- obj, err := t.r.s.Object(core.BlobObject, e.Hash)
+ obj, err := t.r.s.Object(plumbing.BlobObject, e.Hash)
if err != nil {
return nil, err
}
@@ -84,7 +85,7 @@ func (t *Tree) dir(baseName string) (*Tree, error) {
return nil, errDirNotFound
}
- obj, err := t.r.s.Object(core.TreeObject, entry.Hash)
+ obj, err := t.r.s.Object(plumbing.TreeObject, entry.Hash)
if err != nil {
return nil, err
}
@@ -118,18 +119,18 @@ func (t *Tree) Files() *FileIter {
// the current value of Tree.Hash.
//
// ID is present to fulfill the Object interface.
-func (t *Tree) ID() core.Hash {
+func (t *Tree) ID() plumbing.Hash {
return t.Hash
}
-// Type returns the type of object. It always returns core.TreeObject.
-func (t *Tree) Type() core.ObjectType {
- return core.TreeObject
+// Type returns the type of object. It always returns plumbing.TreeObject.
+func (t *Tree) Type() plumbing.ObjectType {
+ return plumbing.TreeObject
}
-// Decode transform an core.Object into a Tree struct
-func (t *Tree) Decode(o core.Object) (err error) {
- if o.Type() != core.TreeObject {
+// Decode transform an plumbing.Object into a Tree struct
+func (t *Tree) Decode(o plumbing.Object) (err error) {
+ if o.Type() != plumbing.TreeObject {
return ErrUnsupportedObject
}
@@ -168,7 +169,7 @@ func (t *Tree) Decode(o core.Object) (err error) {
return err
}
- var hash core.Hash
+ var hash plumbing.Hash
if _, err = io.ReadFull(r, hash[:]); err != nil {
return err
}
@@ -201,9 +202,9 @@ func (t *Tree) decodeFileMode(mode string) (os.FileMode, error) {
return m, nil
}
-// Encode transforms a Tree into a core.Object.
-func (t *Tree) Encode(o core.Object) error {
- o.SetType(core.TreeObject)
+// Encode transforms a Tree into a plumbing.Object.
+func (t *Tree) Encode(o plumbing.Object) error {
+ o.SetType(plumbing.TreeObject)
w, err := o.Writer()
if err != nil {
return err
@@ -371,7 +372,7 @@ func (w *TreeWalker) Close() {
// TreeIter provides an iterator for a set of trees.
type TreeIter struct {
- core.ObjectIter
+ storer.ObjectIter
r *Repository
}
@@ -379,7 +380,7 @@ type TreeIter struct {
// object iterator.
//
// The returned TreeIter will automatically skip over non-tree objects.
-func NewTreeIter(r *Repository, iter core.ObjectIter) *TreeIter {
+func NewTreeIter(r *Repository, iter storer.ObjectIter) *TreeIter {
return &TreeIter{iter, r}
}
@@ -392,7 +393,7 @@ func (iter *TreeIter) Next() (*Tree, error) {
return nil, err
}
- if obj.Type() != core.TreeObject {
+ if obj.Type() != plumbing.TreeObject {
continue
}
@@ -405,8 +406,8 @@ func (iter *TreeIter) Next() (*Tree, error) {
// an error happens or the end of the iter is reached. If ErrStop is sent
// the iteration is stop but no error is returned. The iterator is closed.
func (iter *TreeIter) ForEach(cb func(*Tree) error) error {
- return iter.ObjectIter.ForEach(func(obj core.Object) error {
- if obj.Type() != core.TreeObject {
+ return iter.ObjectIter.ForEach(func(obj plumbing.Object) error {
+ if obj.Type() != plumbing.TreeObject {
return nil
}