aboutsummaryrefslogtreecommitdiffstats
path: root/utils/merkletrie
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-05-04 01:48:53 +0200
committerGitHub <noreply@github.com>2017-05-04 01:48:53 +0200
commite727d4d0cf4beff77c44bb143a5edb560c840aab (patch)
treef43a94ef85be1f3a36c5dfb1bb60eb0747c15902 /utils/merkletrie
parent727bf94da8e3cebd3ff467d30425b12d671fbca7 (diff)
parent75c5adffb8b1e80665753784129e2f16210514c1 (diff)
downloadgo-git-e727d4d0cf4beff77c44bb143a5edb560c840aab.tar.gz
Merge pull request #364 from mcuadros/index-pointer
plumbing: index, Entries converted in a slice of pointers
Diffstat (limited to 'utils/merkletrie')
-rw-r--r--utils/merkletrie/index/node.go6
-rw-r--r--utils/merkletrie/index/node_test.go16
2 files changed, 13 insertions, 9 deletions
diff --git a/utils/merkletrie/index/node.go b/utils/merkletrie/index/node.go
index 2c72f6d..859c097 100644
--- a/utils/merkletrie/index/node.go
+++ b/utils/merkletrie/index/node.go
@@ -16,7 +16,7 @@ import (
// compared with any other noder.Noder implementation inside of go-git
type node struct {
path string
- entry index.Entry
+ entry *index.Entry
children []noder.Noder
isDir bool
}
@@ -66,6 +66,10 @@ func (n *node) String() string {
// If the node is computed and not based on a index.Entry the hash is equals
// to a 24-bytes slices of zero values.
func (n *node) Hash() []byte {
+ if n.entry == nil {
+ return make([]byte, 24)
+ }
+
return append(n.entry.Hash[:], n.entry.Mode.Bytes()...)
}
diff --git a/utils/merkletrie/index/node_test.go b/utils/merkletrie/index/node_test.go
index 48aa35f..00da8da 100644
--- a/utils/merkletrie/index/node_test.go
+++ b/utils/merkletrie/index/node_test.go
@@ -19,7 +19,7 @@ var _ = Suite(&NoderSuite{})
func (s *NoderSuite) TestDiff(c *C) {
indexA := &index.Index{
- Entries: []index.Entry{
+ Entries: []*index.Entry{
{Name: "foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
{Name: "bar/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
{Name: "bar/qux", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
@@ -28,7 +28,7 @@ func (s *NoderSuite) TestDiff(c *C) {
}
indexB := &index.Index{
- Entries: []index.Entry{
+ Entries: []*index.Entry{
{Name: "foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
{Name: "bar/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
{Name: "bar/qux", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
@@ -43,13 +43,13 @@ func (s *NoderSuite) TestDiff(c *C) {
func (s *NoderSuite) TestDiffChange(c *C) {
indexA := &index.Index{
- Entries: []index.Entry{
+ Entries: []*index.Entry{
{Name: "bar/baz/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
},
}
indexB := &index.Index{
- Entries: []index.Entry{
+ Entries: []*index.Entry{
{Name: "bar/baz/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
},
}
@@ -61,13 +61,13 @@ func (s *NoderSuite) TestDiffChange(c *C) {
func (s *NoderSuite) TestDiffDir(c *C) {
indexA := &index.Index{
- Entries: []index.Entry{
+ Entries: []*index.Entry{
{Name: "foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
},
}
indexB := &index.Index{
- Entries: []index.Entry{
+ Entries: []*index.Entry{
{Name: "foo/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
},
}
@@ -79,14 +79,14 @@ func (s *NoderSuite) TestDiffDir(c *C) {
func (s *NoderSuite) TestDiffSameRoot(c *C) {
indexA := &index.Index{
- Entries: []index.Entry{
+ Entries: []*index.Entry{
{Name: "foo.go", Hash: plumbing.NewHash("aab686eafeb1f44702738c8b0f24f2567c36da6d")},
{Name: "foo/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
},
}
indexB := &index.Index{
- Entries: []index.Entry{
+ Entries: []*index.Entry{
{Name: "foo/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
{Name: "foo.go", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
},