diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-02-24 11:26:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-24 11:26:08 +0100 |
commit | 39f43b52a2bdfbc73703e2d09b575d49cd70ede8 (patch) | |
tree | 81d9845f9ba1c16975c24084e9023492e9e7ee33 /plumbing/difftree/difftree.go | |
parent | f93e5712a86b96370673a02fa7ffbe5e0aec0c66 (diff) | |
parent | cb51ef358e081b5214e3884bd618d1d3fedf8eb1 (diff) | |
download | go-git-39f43b52a2bdfbc73703e2d09b575d49cd70ede8.tar.gz |
Merge pull request #284 from ajnavarro/improvement/move-difftree-to-object
plumbing/object: move difftree to object package
Diffstat (limited to 'plumbing/difftree/difftree.go')
-rw-r--r-- | plumbing/difftree/difftree.go | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/plumbing/difftree/difftree.go b/plumbing/difftree/difftree.go deleted file mode 100644 index ff1ceaf..0000000 --- a/plumbing/difftree/difftree.go +++ /dev/null @@ -1,63 +0,0 @@ -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) - - merkletrieChanges, err := merkletrie.DiffTree(from, to, hashEqual) - if err != nil { - return nil, err - } - - 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 { - 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) -} |