aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_status.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-04-12 03:46:28 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-04-12 03:46:28 +0200
commit63f234847bf613b621b3a714d77fc077d88717e6 (patch)
tree610c99bb6fe6c9cbc7b8666652352321726212ee /worktree_status.go
parente14ee7a2645b486d72f52a0c62714b3049077554 (diff)
downloadgo-git-63f234847bf613b621b3a714d77fc077d88717e6.tar.gz
worktree, reset implementation and status improvements
Diffstat (limited to 'worktree_status.go')
-rw-r--r--worktree_status.go44
1 files changed, 21 insertions, 23 deletions
diff --git a/worktree_status.go b/worktree_status.go
index d472fde..ae7518e 100644
--- a/worktree_status.go
+++ b/worktree_status.go
@@ -80,17 +80,9 @@ func (w *Worktree) diffStagingWithWorktree() (merkletrie.Changes, error) {
return nil, err
}
- from, err := index.NewRootNode(idx)
- if err != nil {
- return nil, err
- }
-
- to, err := filesystem.NewRootNode(w.fs)
- if err != nil {
- return nil, err
- }
-
- return merkletrie.DiffTree(from, to, IsEquals)
+ from := index.NewRootNode(idx)
+ to := filesystem.NewRootNode(w.fs)
+ return merkletrie.DiffTree(from, to, diffTreeIsEquals)
}
func (w *Worktree) diffCommitWithStaging(commit plumbing.Hash, reverse bool) (merkletrie.Changes, error) {
@@ -99,11 +91,6 @@ func (w *Worktree) diffCommitWithStaging(commit plumbing.Hash, reverse bool) (me
return nil, err
}
- to, err := index.NewRootNode(idx)
- if err != nil {
- return nil, err
- }
-
c, err := w.r.CommitObject(commit)
if err != nil {
return nil, err
@@ -114,20 +101,31 @@ func (w *Worktree) diffCommitWithStaging(commit plumbing.Hash, reverse bool) (me
return nil, err
}
+ to := index.NewRootNode(idx)
from := object.NewTreeRootNode(t)
+
if reverse {
- return merkletrie.DiffTree(to, from, IsEquals)
+ return merkletrie.DiffTree(to, from, diffTreeIsEquals)
}
- return merkletrie.DiffTree(from, to, IsEquals)
+ return merkletrie.DiffTree(from, to, diffTreeIsEquals)
}
-func IsEquals(a, b noder.Hasher) bool {
- pathA := a.(noder.Path)
- pathB := b.(noder.Path)
- if pathA[len(pathA)-1].IsDir() || pathB[len(pathB)-1].IsDir() {
+var emptyNoderHash = make([]byte, 24)
+
+// diffTreeIsEquals is a implementation of noder.Equals, used to compare
+// noder.Noder, it compare the content and the length of the hashes.
+//
+// Since some of the noder.Noder implementations doesn't compute a hash for
+// some directories, if any of the hashes is a 24-byte slice of zero values
+// the comparison is not done and the hashes are take as different.
+func diffTreeIsEquals(a, b noder.Hasher) bool {
+ hashA := a.Hash()
+ hashB := b.Hash()
+
+ if bytes.Equal(hashA, emptyNoderHash) || bytes.Equal(hashB, emptyNoderHash) {
return false
}
- return bytes.Equal(a.Hash(), b.Hash())
+ return bytes.Equal(hashA, hashB)
}