aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/treenoder.go
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/object/treenoder.go')
-rw-r--r--plumbing/object/treenoder.go26
1 files changed, 10 insertions, 16 deletions
diff --git a/plumbing/object/treenoder.go b/plumbing/object/treenoder.go
index 4da8298..bd65abc 100644
--- a/plumbing/object/treenoder.go
+++ b/plumbing/object/treenoder.go
@@ -1,13 +1,5 @@
package object
-// A treenoder is a helper type that wraps git trees into merkletrie
-// noders.
-//
-// As a merkletrie noder doesn't understand the concept of modes (e.g.
-// file permissions), the treenoder includes the mode of the git tree in
-// the hash, so changes in the modes will be detected as modifications
-// to the file contents by the merkletrie difftree algorithm. This is
-// consistent with how the "git diff-tree" command works.
import (
"io"
@@ -16,6 +8,14 @@ import (
"gopkg.in/src-d/go-git.v4/utils/merkletrie/noder"
)
+// A treenoder is a helper type that wraps git trees into merkletrie
+// noders.
+//
+// As a merkletrie noder doesn't understand the concept of modes (e.g.
+// file permissions), the treenoder includes the mode of the git tree in
+// the hash, so changes in the modes will be detected as modifications
+// to the file contents by the merkletrie difftree algorithm. This is
+// consistent with how the "git diff-tree" command works.
type treeNoder struct {
parent *Tree // the root node is its own parent
name string // empty string for the root node
@@ -24,7 +24,8 @@ type treeNoder struct {
children []noder.Noder // memoized
}
-func newTreeNoder(t *Tree) *treeNoder {
+// NewTreeRootNode returns the root node of a Tree
+func NewTreeRootNode(t *Tree) noder.Noder {
if t == nil {
return &treeNoder{}
}
@@ -45,13 +46,6 @@ func (t *treeNoder) String() string {
return "treeNoder <" + t.name + ">"
}
-// The hash of a treeNoder is the result of concatenating the hash of
-// its contents and its mode; that way the difftree algorithm will
-// detect changes in the contents of files and also in their mode.
-//
-// Files with Regular and Deprecated file modes are considered the same
-// for the purpose of difftree, so Regular will be used as the mode for
-// Deprecated files here.
func (t *treeNoder) Hash() []byte {
if t.mode == filemode.Deprecated {
return append(t.hash[:], filemode.Regular.Bytes()...)