aboutsummaryrefslogblamecommitdiffstats
path: root/plumbing/difftree/difftree.go
blob: d38ad2cd6741fa409b6682ade8ef24ec382c1b4b (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                


               
 
                                              

                                                     

 
                                                     

                               
 
                                                                          
                       
                               

         
                                            
 



                                              
package difftree

import (
	"bytes"

	"srcd.works/go-git.v4/plumbing/object"
	"srcd.works/go-git.v4/utils/merkletrie"
	"srcd.works/go-git.v4/utils/merkletrie/noder"
)

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)
}

func hashEqual(a, b noder.Hasher) bool {
	return bytes.Equal(a.Hash(), b.Hash())
}