You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
942 B
38 lines
942 B
6 years ago
|
package object
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"context"
|
||
|
|
||
|
"gopkg.in/src-d/go-git.v4/utils/merkletrie"
|
||
|
"gopkg.in/src-d/go-git.v4/utils/merkletrie/noder"
|
||
|
)
|
||
|
|
||
|
// DiffTree compares the content and mode of the blobs found via two
|
||
|
// tree objects.
|
||
|
func DiffTree(a, b *Tree) (Changes, error) {
|
||
|
return DiffTreeContext(context.Background(), a, b)
|
||
|
}
|
||
|
|
||
|
// DiffTree compares the content and mode of the blobs found via two
|
||
|
// tree objects. Provided context must be non-nil.
|
||
|
// An error will be return if context expires
|
||
|
func DiffTreeContext(ctx context.Context, a, b *Tree) (Changes, error) {
|
||
|
from := NewTreeRootNode(a)
|
||
|
to := NewTreeRootNode(b)
|
||
|
|
||
|
hashEqual := func(a, b noder.Hasher) bool {
|
||
|
return bytes.Equal(a.Hash(), b.Hash())
|
||
|
}
|
||
|
|
||
|
merkletrieChanges, err := merkletrie.DiffTreeContext(ctx, from, to, hashEqual)
|
||
|
if err != nil {
|
||
|
if err == merkletrie.ErrCanceled {
|
||
|
return nil, ErrCanceled
|
||
|
}
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return newChanges(merkletrieChanges)
|
||
|
}
|