A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
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.

76 lines
1.9 KiB

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>
2 years ago
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2017 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. // +build gogit
  6. package git
  7. import (
  8. "errors"
  9. "path/filepath"
  10. gitealog "code.gitea.io/gitea/modules/log"
  11. "github.com/go-git/go-billy/v5/osfs"
  12. gogit "github.com/go-git/go-git/v5"
  13. "github.com/go-git/go-git/v5/plumbing/cache"
  14. "github.com/go-git/go-git/v5/storage/filesystem"
  15. )
  16. // Repository represents a Git repository.
  17. type Repository struct {
  18. Path string
  19. tagCache *ObjectCache
  20. gogitRepo *gogit.Repository
  21. gogitStorage *filesystem.Storage
  22. gpgSettings *GPGSettings
  23. }
  24. // OpenRepository opens the repository at the given path.
  25. func OpenRepository(repoPath string) (*Repository, error) {
  26. repoPath, err := filepath.Abs(repoPath)
  27. if err != nil {
  28. return nil, err
  29. } else if !isDir(repoPath) {
  30. return nil, errors.New("no such file or directory")
  31. }
  32. fs := osfs.New(repoPath)
  33. _, err = fs.Stat(".git")
  34. if err == nil {
  35. fs, err = fs.Chroot(".git")
  36. if err != nil {
  37. return nil, err
  38. }
  39. }
  40. storage := filesystem.NewStorageWithOptions(fs, cache.NewObjectLRUDefault(), filesystem.Options{KeepDescriptors: true})
  41. gogitRepo, err := gogit.Open(storage, fs)
  42. if err != nil {
  43. return nil, err
  44. }
  45. return &Repository{
  46. Path: repoPath,
  47. gogitRepo: gogitRepo,
  48. gogitStorage: storage,
  49. tagCache: newObjectCache(),
  50. }, nil
  51. }
  52. // Close this repository, in particular close the underlying gogitStorage if this is not nil
  53. func (repo *Repository) Close() {
  54. if repo == nil || repo.gogitStorage == nil {
  55. return
  56. }
  57. if err := repo.gogitStorage.Close(); err != nil {
  58. gitealog.Error("Error closing storage: %v", err)
  59. }
  60. }
  61. // GoGitRepo gets the go-git repo representation
  62. func (repo *Repository) GoGitRepo() *gogit.Repository {
  63. return repo.gogitRepo
  64. }