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.

repo_tree_gogit.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2019 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. //go:build gogit
  6. // +build gogit
  7. package git
  8. func (repo *Repository) getTree(id SHA1) (*Tree, error) {
  9. gogitTree, err := repo.gogitRepo.TreeObject(id)
  10. if err != nil {
  11. return nil, err
  12. }
  13. tree := NewTree(repo, id)
  14. tree.gogitTree = gogitTree
  15. return tree, nil
  16. }
  17. // GetTree find the tree object in the repository.
  18. func (repo *Repository) GetTree(idStr string) (*Tree, error) {
  19. if len(idStr) != 40 {
  20. res, err := NewCommand("rev-parse", "--verify", idStr).RunInDir(repo.Path)
  21. if err != nil {
  22. return nil, err
  23. }
  24. if len(res) > 0 {
  25. idStr = res[:len(res)-1]
  26. }
  27. }
  28. id, err := NewIDFromString(idStr)
  29. if err != nil {
  30. return nil, err
  31. }
  32. resolvedID := id
  33. commitObject, err := repo.gogitRepo.CommitObject(id)
  34. if err == nil {
  35. id = SHA1(commitObject.TreeHash)
  36. }
  37. treeObject, err := repo.getTree(id)
  38. if err != nil {
  39. return nil, err
  40. }
  41. treeObject.ResolvedID = resolvedID
  42. return treeObject, nil
  43. }