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.

tree_blob_gogit.go 1.4KB

Use native git variants by default with go-git variants as build tag (#13673) * Move last commit cache back into modules/git Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from the interface for last commit cache Signed-off-by: Andrew Thornton <art27@cantab.net> * move cacheref to last_commit_cache Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from routers/private/hook Signed-off-by: Andrew Thornton <art27@cantab.net> * Move FindLFSFiles to pipeline Signed-off-by: Andrew Thornton <art27@cantab.net> * Make no-go-git variants Signed-off-by: Andrew Thornton <art27@cantab.net> * Submodule RefID Signed-off-by: Andrew Thornton <art27@cantab.net> * fix issue with GetCommitsInfo Signed-off-by: Andrew Thornton <art27@cantab.net> * fix GetLastCommitForPaths Signed-off-by: Andrew Thornton <art27@cantab.net> * Improve efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * More efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * even faster Signed-off-by: Andrew Thornton <art27@cantab.net> * Reduce duplication * As per @lunny Signed-off-by: Andrew Thornton <art27@cantab.net> * attempt to fix drone Signed-off-by: Andrew Thornton <art27@cantab.net> * fix test-tags Signed-off-by: Andrew Thornton <art27@cantab.net> * default to use no-go-git variants and add gogit build tag Signed-off-by: Andrew Thornton <art27@cantab.net> * placate lint Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
3 years ago
Use native git variants by default with go-git variants as build tag (#13673) * Move last commit cache back into modules/git Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from the interface for last commit cache Signed-off-by: Andrew Thornton <art27@cantab.net> * move cacheref to last_commit_cache Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from routers/private/hook Signed-off-by: Andrew Thornton <art27@cantab.net> * Move FindLFSFiles to pipeline Signed-off-by: Andrew Thornton <art27@cantab.net> * Make no-go-git variants Signed-off-by: Andrew Thornton <art27@cantab.net> * Submodule RefID Signed-off-by: Andrew Thornton <art27@cantab.net> * fix issue with GetCommitsInfo Signed-off-by: Andrew Thornton <art27@cantab.net> * fix GetLastCommitForPaths Signed-off-by: Andrew Thornton <art27@cantab.net> * Improve efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * More efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * even faster Signed-off-by: Andrew Thornton <art27@cantab.net> * Reduce duplication * As per @lunny Signed-off-by: Andrew Thornton <art27@cantab.net> * attempt to fix drone Signed-off-by: Andrew Thornton <art27@cantab.net> * fix test-tags Signed-off-by: Andrew Thornton <art27@cantab.net> * default to use no-go-git variants and add gogit build tag Signed-off-by: Andrew Thornton <art27@cantab.net> * placate lint Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. import (
  9. "path"
  10. "strings"
  11. "github.com/go-git/go-git/v5/plumbing"
  12. "github.com/go-git/go-git/v5/plumbing/filemode"
  13. "github.com/go-git/go-git/v5/plumbing/object"
  14. )
  15. // GetTreeEntryByPath get the tree entries according the sub dir
  16. func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) {
  17. if len(relpath) == 0 {
  18. return &TreeEntry{
  19. ID: t.ID,
  20. //Type: ObjectTree,
  21. gogitTreeEntry: &object.TreeEntry{
  22. Name: "",
  23. Mode: filemode.Dir,
  24. Hash: t.ID,
  25. },
  26. }, nil
  27. }
  28. relpath = path.Clean(relpath)
  29. parts := strings.Split(relpath, "/")
  30. var err error
  31. tree := t
  32. for i, name := range parts {
  33. if i == len(parts)-1 {
  34. entries, err := tree.ListEntries()
  35. if err != nil {
  36. if err == plumbing.ErrObjectNotFound {
  37. return nil, ErrNotExist{
  38. RelPath: relpath,
  39. }
  40. }
  41. return nil, err
  42. }
  43. for _, v := range entries {
  44. if v.Name() == name {
  45. return v, nil
  46. }
  47. }
  48. } else {
  49. tree, err = tree.SubTree(name)
  50. if err != nil {
  51. if err == plumbing.ErrObjectNotFound {
  52. return nil, ErrNotExist{
  53. RelPath: relpath,
  54. }
  55. }
  56. return nil, err
  57. }
  58. }
  59. }
  60. return nil, ErrNotExist{"", relpath}
  61. }