aboutsummaryrefslogtreecommitdiffstats
path: root/utils/merkletrie/filesystem/node.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-04-15 23:13:45 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-04-15 23:13:45 +0200
commit4b0fc1eb6937b6e5f8569794e8b669443e2c7584 (patch)
tree9f2fdb086be2b96ff9c2169fdb93e19e5a298490 /utils/merkletrie/filesystem/node.go
parent601c85a8834cd78e317f1ba435475fa18162053a (diff)
downloadgo-git-4b0fc1eb6937b6e5f8569794e8b669443e2c7584.tar.gz
worktree: reset and checkout support for submodules
Diffstat (limited to 'utils/merkletrie/filesystem/node.go')
-rw-r--r--utils/merkletrie/filesystem/node.go32
1 files changed, 25 insertions, 7 deletions
diff --git a/utils/merkletrie/filesystem/node.go b/utils/merkletrie/filesystem/node.go
index 6c09d29..fc8f191 100644
--- a/utils/merkletrie/filesystem/node.go
+++ b/utils/merkletrie/filesystem/node.go
@@ -21,7 +21,8 @@ var ignore = map[string]bool{
// This implementation implements a "standard" hash method being able to be
// compared with any other noder.Noder implementation inside of go-git.
type node struct {
- fs billy.Filesystem
+ fs billy.Filesystem
+ submodules map[string]plumbing.Hash
path string
hash []byte
@@ -29,9 +30,16 @@ type node struct {
isDir bool
}
-// NewRootNode returns the root node based on a given billy.Filesystem
-func NewRootNode(fs billy.Filesystem) noder.Noder {
- return &node{fs: fs, isDir: true}
+// NewRootNode returns the root node based on a given billy.Filesystem.
+//
+// In order to provide the submodule hash status, a map[string]plumbing.Hash
+// should be provided where the key is the path of the submodule and the commit
+// of the submodule HEAD
+func NewRootNode(
+ fs billy.Filesystem,
+ submodules map[string]plumbing.Hash,
+) noder.Noder {
+ return &node{fs: fs, submodules: submodules, isDir: true}
}
// Hash the hash of a filesystem is the result of concatenating the computed
@@ -100,17 +108,27 @@ func (n *node) calculateChildren() error {
func (n *node) newChildNode(file billy.FileInfo) (*node, error) {
path := filepath.Join(n.path, file.Name())
+
hash, err := n.calculateHash(path, file)
if err != nil {
return nil, err
}
- return &node{
- fs: n.fs,
+ node := &node{
+ fs: n.fs,
+ submodules: n.submodules,
+
path: path,
hash: hash,
isDir: file.IsDir(),
- }, nil
+ }
+
+ if hash, isSubmodule := n.submodules[path]; isSubmodule {
+ node.hash = append(hash[:], filemode.Submodule.Bytes()...)
+ node.isDir = false
+ }
+
+ return node, nil
}
func (n *node) calculateHash(path string, file billy.FileInfo) ([]byte, error) {