aboutsummaryrefslogtreecommitdiffstats
path: root/utils/merkletrie
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-02-21 16:03:39 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2017-02-21 16:03:39 +0100
commited288b30de1ac3dcb3ce675c4b9af89eb4e6fcba (patch)
tree6eb908b839d6c225d95691d91e3d5ef5220f54c1 /utils/merkletrie
parentd6a6decd1be0515faf36256ce06c58c7d662bbd0 (diff)
downloadgo-git-ed288b30de1ac3dcb3ce675c4b9af89eb4e6fcba.tar.gz
documentation and API improvements
Diffstat (limited to 'utils/merkletrie')
-rw-r--r--utils/merkletrie/doc.go22
-rw-r--r--utils/merkletrie/internal/frame/frame_test.go11
-rw-r--r--utils/merkletrie/iter_test.go14
3 files changed, 16 insertions, 31 deletions
diff --git a/utils/merkletrie/doc.go b/utils/merkletrie/doc.go
index 28ece3e..5204024 100644
--- a/utils/merkletrie/doc.go
+++ b/utils/merkletrie/doc.go
@@ -1,20 +1,11 @@
/*
Package merkletrie provides support for n-ary trees that are at the same
-time Merkle trees and Radix trees (tries), and provides an efficient
-tree comparison algorithm for them.
+time Merkle trees and Radix trees (tries).
Git trees are Radix n-ary trees in virtue of the names of their
tree entries. At the same time, git trees are Merkle trees thanks to
their hashes.
-When comparing git trees, the simple approach of alphabetically sorting
-their elements and comparing the resulting lists is too slow as it
-depends linearly on the number of files in the trees: When a directory
-has lots of files but none of them has been modified, this approach is
-very expensive. We can do better by prunning whole directories that
-have not change, just by looking at their hashes. This package provides
-the tools to do exactly that.
-
This package defines Merkle tries as nodes that should have:
- a hash: the Merkle part of the Merkle trie
@@ -28,5 +19,16 @@ their children, which is good for testing purposes.
Nodes in the Merkle trie are abstracted by the Noder interface. The
intended use is that git trees implements this interface, either
directly or using a simple wrapper.
+
+This package provides an iterator for merkletries that can skip whole
+directory-like noders and an efficient merkletrie comparison algorithm.
+
+When comparing git trees, the simple approach of alphabetically sorting
+their elements and comparing the resulting lists is too slow as it
+depends linearly on the number of files in the trees: When a directory
+has lots of files but none of them has been modified, this approach is
+very expensive. We can do better by prunning whole directories that
+have not change, just by looking at their hashes. This package provides
+the tools to do exactly that.
*/
package merkletrie
diff --git a/utils/merkletrie/internal/frame/frame_test.go b/utils/merkletrie/internal/frame/frame_test.go
index 9cc0994..516d78b 100644
--- a/utils/merkletrie/internal/frame/frame_test.go
+++ b/utils/merkletrie/internal/frame/frame_test.go
@@ -89,20 +89,13 @@ func checkFirstAndDrop(c *C, f *Frame, expectedNodeName string, expectedOK bool)
}
// a mock noder that returns error when Children() is called
-type errorNoder struct{}
+type errorNoder struct{ noder.Noder }
-func (e *errorNoder) Hash() []byte { return nil }
-func (e *errorNoder) Name() string { return "" }
-func (e *errorNoder) String() string { return "" }
-func (e *errorNoder) IsDir() bool { return true }
func (e *errorNoder) Children() ([]noder.Noder, error) {
return nil, fmt.Errorf("mock error")
}
-func (e *errorNoder) NumChildren() (int, error) {
- return 0, fmt.Errorf("mock error")
-}
func (s *FrameSuite) TestNewFrameErrors(c *C) {
_, err := New(&errorNoder{})
- c.Assert(err, Not(IsNil))
+ c.Assert(err, ErrorMatches, "mock error")
}
diff --git a/utils/merkletrie/iter_test.go b/utils/merkletrie/iter_test.go
index 52d567a..fa7c5f5 100644
--- a/utils/merkletrie/iter_test.go
+++ b/utils/merkletrie/iter_test.go
@@ -4,7 +4,6 @@ import (
"fmt"
"io"
"strings"
- "testing"
"srcd.works/go-git.v4/utils/merkletrie"
"srcd.works/go-git.v4/utils/merkletrie/internal/fsnoder"
@@ -13,8 +12,6 @@ import (
. "gopkg.in/check.v1"
)
-func Test(t *testing.T) { TestingT(t) }
-
type IterSuite struct{}
var _ = Suite(&IterSuite{})
@@ -443,20 +440,13 @@ func find(c *C, tree noder.Noder, name string) noder.Path {
}
}
-type errorNoder struct{}
+type errorNoder struct{ noder.Noder }
-func (e *errorNoder) Name() string { return "" }
-func (e *errorNoder) String() string { return "" }
-func (e *errorNoder) Hash() []byte { return nil }
-func (e *errorNoder) IsDir() bool { return true }
func (e *errorNoder) Children() ([]noder.Noder, error) {
return nil, fmt.Errorf("mock error")
}
-func (e *errorNoder) NumChildren() (int, error) {
- return 0, fmt.Errorf("mock error")
-}
func (s *IterSuite) TestNewIterFailsOnChildrenErrors(c *C) {
_, err := merkletrie.NewIter(&errorNoder{})
- c.Assert(err, Not(IsNil))
+ c.Assert(err, ErrorMatches, "mock error")
}