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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. package git
  7. func (repo *Repository) getTree(id SHA1) (*Tree, error) {
  8. gogitTree, err := repo.gogitRepo.TreeObject(id)
  9. if err != nil {
  10. return nil, err
  11. }
  12. tree := NewTree(repo, id)
  13. tree.gogitTree = gogitTree
  14. return tree, nil
  15. }
  16. // GetTree find the tree object in the repository.
  17. func (repo *Repository) GetTree(idStr string) (*Tree, error) {
  18. if len(idStr) != 40 {
  19. res, _, err := NewCommand(repo.Ctx, "rev-parse", "--verify", idStr).RunStdString(&RunOpts{Dir: repo.Path})
  20. if err != nil {
  21. return nil, err
  22. }
  23. if len(res) > 0 {
  24. idStr = res[:len(res)-1]
  25. }
  26. }
  27. id, err := NewIDFromString(idStr)
  28. if err != nil {
  29. return nil, err
  30. }
  31. resolvedID := id
  32. commitObject, err := repo.gogitRepo.CommitObject(id)
  33. if err == nil {
  34. id = SHA1(commitObject.TreeHash)
  35. }
  36. treeObject, err := repo.getTree(id)
  37. if err != nil {
  38. return nil, err
  39. }
  40. treeObject.ResolvedID = resolvedID
  41. return treeObject, nil
  42. }