aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plumbing/difftree/difftree.go40
-rw-r--r--plumbing/object/tree.go11
2 files changed, 45 insertions, 6 deletions
diff --git a/plumbing/difftree/difftree.go b/plumbing/difftree/difftree.go
index d38ad2c..ff1ceaf 100644
--- a/plumbing/difftree/difftree.go
+++ b/plumbing/difftree/difftree.go
@@ -2,12 +2,15 @@ package difftree
import (
"bytes"
+ "os"
"srcd.works/go-git.v4/plumbing/object"
"srcd.works/go-git.v4/utils/merkletrie"
"srcd.works/go-git.v4/utils/merkletrie/noder"
)
+// DiffTree compares the content and mode of the blobs found via two
+// tree objects.
func DiffTree(a, b *object.Tree) ([]*Change, error) {
from := newTreeNoder(a)
to := newTreeNoder(b)
@@ -20,6 +23,41 @@ func DiffTree(a, b *object.Tree) ([]*Change, error) {
return newChanges(merkletrieChanges)
}
+// check if the hash of the contents is different, if not, check if
+// the permissions are different (but taking into account deprecated
+// file modes). On a treenoder, the hash of the contents is codified
+// in the first 20 bytes of the data returned by Hash() and the last
+// 4 bytes is the mode.
func hashEqual(a, b noder.Hasher) bool {
- return bytes.Equal(a.Hash(), b.Hash())
+ hashA, hashB := a.Hash(), b.Hash()
+ contentsA, contentsB := hashA[:20], hashB[:20]
+
+ sameContents := bytes.Equal(contentsA, contentsB)
+ if !sameContents {
+ return false
+ }
+
+ modeA, modeB := hashA[20:], hashB[20:]
+
+ return equivalentMode(modeA, modeB)
+}
+
+func equivalentMode(a, b []byte) bool {
+ if isFilish(a) && isFilish(b) {
+ return true
+ }
+ return bytes.Equal(a, b)
+}
+
+var (
+ file = modeToBytes(object.FileMode)
+ fileDeprecated = modeToBytes(object.FileModeDeprecated)
+ // remove this by fixing plumbing.Object mode ASAP
+ fileGoGit = modeToBytes(os.FileMode(0644))
+)
+
+func isFilish(b []byte) bool {
+ return bytes.Equal(b, file) ||
+ bytes.Equal(b, fileDeprecated) ||
+ bytes.Equal(b, fileGoGit)
}
diff --git a/plumbing/object/tree.go b/plumbing/object/tree.go
index 27d8578..436ac32 100644
--- a/plumbing/object/tree.go
+++ b/plumbing/object/tree.go
@@ -19,11 +19,12 @@ const (
maxTreeDepth = 1024
startingStackSize = 8
- FileMode os.FileMode = 0100644
- ExecutableMode os.FileMode = 0100755
- SubmoduleMode os.FileMode = 0160000
- SymlinkMode os.FileMode = 0120000
- TreeMode os.FileMode = 0040000
+ FileMode os.FileMode = 0100644
+ FileModeDeprecated os.FileMode = 0100664
+ ExecutableMode os.FileMode = 0100755
+ SubmoduleMode os.FileMode = 0160000
+ SymlinkMode os.FileMode = 0120000
+ TreeMode os.FileMode = 0040000
)
// New errors defined by this package.