本站源代码
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
942B

  1. package object
  2. import (
  3. "bytes"
  4. "context"
  5. "gopkg.in/src-d/go-git.v4/utils/merkletrie"
  6. "gopkg.in/src-d/go-git.v4/utils/merkletrie/noder"
  7. )
  8. // DiffTree compares the content and mode of the blobs found via two
  9. // tree objects.
  10. func DiffTree(a, b *Tree) (Changes, error) {
  11. return DiffTreeContext(context.Background(), a, b)
  12. }
  13. // DiffTree compares the content and mode of the blobs found via two
  14. // tree objects. Provided context must be non-nil.
  15. // An error will be return if context expires
  16. func DiffTreeContext(ctx context.Context, a, b *Tree) (Changes, error) {
  17. from := NewTreeRootNode(a)
  18. to := NewTreeRootNode(b)
  19. hashEqual := func(a, b noder.Hasher) bool {
  20. return bytes.Equal(a.Hash(), b.Hash())
  21. }
  22. merkletrieChanges, err := merkletrie.DiffTreeContext(ctx, from, to, hashEqual)
  23. if err != nil {
  24. if err == merkletrie.ErrCanceled {
  25. return nil, ErrCanceled
  26. }
  27. return nil, err
  28. }
  29. return newChanges(merkletrieChanges)
  30. }
上海开阖软件有限公司 沪ICP备12045867号-1