aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/treenoder.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-04-12 15:18:41 +0200
committerGitHub <noreply@github.com>2017-04-12 15:18:41 +0200
commit932ced9f55f556de02610425cfa161c35c6a758b (patch)
tree9b5dd9ad1665fad8424dfbdc5bd93b531f714b09 /plumbing/object/treenoder.go
parent9b45f468c61a0756dd19d09b64c2b1a88cc99ec5 (diff)
parent5bcf802213e801c4d52102612f007defa5d0397f (diff)
downloadgo-git-932ced9f55f556de02610425cfa161c35c6a758b.tar.gz
Merge pull request #339 from mcuadros/status
worktree, status and reset implementation based on merkletrie
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()...)