diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-01-28 04:09:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-27 21:09:51 +0100 |
commit | 5f82ead13cb7706d3f660271d94de6101cef4119 (patch) | |
tree | c10dc0ec9b98992629847f2b98554f3d1c3713ed /modules | |
parent | 60e4a98ab07dcf3bd86cf630c79e6433c3ef3e84 (diff) | |
download | gitea-5f82ead13cb7706d3f660271d94de6101cef4119.tar.gz gitea-5f82ead13cb7706d3f660271d94de6101cef4119.zip |
Simplify how git repositories are opened (#28937)
## Purpose
This is a refactor toward building an abstraction over managing git
repositories.
Afterwards, it does not matter anymore if they are stored on the local
disk or somewhere remote.
## What this PR changes
We used `git.OpenRepository` everywhere previously.
Now, we should split them into two distinct functions:
Firstly, there are temporary repositories which do not change:
```go
git.OpenRepository(ctx, diskPath)
```
Gitea managed repositories having a record in the database in the
`repository` table are moved into the new package `gitrepo`:
```go
gitrepo.OpenRepository(ctx, repo_model.Repo)
```
Why is `repo_model.Repository` the second parameter instead of file
path?
Because then we can easily adapt our repository storage strategy.
The repositories can be stored locally, however, they could just as well
be stored on a remote server.
## Further changes in other PRs
- A Git Command wrapper on package `gitrepo` could be created. i.e.
`NewCommand(ctx, repo_model.Repository, commands...)`. `git.RunOpts{Dir:
repo.RepoPath()}`, the directory should be empty before invoking this
method and it can be filled in the function only. #28940
- Remove the `RepoPath()`/`WikiPath()` functions to reduce the
possibility of mistakes.
---------
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/context/api.go | 9 | ||||
-rw-r--r-- | modules/context/context.go | 4 | ||||
-rw-r--r-- | modules/context/repo.go | 10 | ||||
-rw-r--r-- | modules/contexttest/context_tests.go | 6 | ||||
-rw-r--r-- | modules/git/repo_base.go | 44 | ||||
-rw-r--r-- | modules/git/repo_branch.go | 23 | ||||
-rw-r--r-- | modules/git/repo_branch_gogit.go | 29 | ||||
-rw-r--r-- | modules/git/repo_branch_nogogit.go | 13 | ||||
-rw-r--r-- | modules/gitrepo/branch.go | 32 | ||||
-rw-r--r-- | modules/gitrepo/gitrepo.go | 103 | ||||
-rw-r--r-- | modules/gitrepo/walk_gogit.go | 40 | ||||
-rw-r--r-- | modules/gitrepo/walk_nogogit.go | 17 | ||||
-rw-r--r-- | modules/indexer/stats/db.go | 3 | ||||
-rw-r--r-- | modules/repository/branch.go | 5 | ||||
-rw-r--r-- | modules/repository/generate.go | 3 | ||||
-rw-r--r-- | modules/repository/repo.go | 3 |
16 files changed, 219 insertions, 125 deletions
diff --git a/modules/context/api.go b/modules/context/api.go index f41228ad76..e226264a87 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -11,11 +11,11 @@ import ( "net/url" "strings" - repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" mc "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/httpcache" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -224,7 +224,7 @@ func APIContexter() func(http.Handler) http.Handler { defer baseCleanUp() ctx.Base.AppendContextValue(apiContextKey, ctx) - ctx.Base.AppendContextValueFunc(git.RepositoryContextKey, func() any { return ctx.Repo.GitRepo }) + ctx.Base.AppendContextValueFunc(gitrepo.RepositoryContextKey, func() any { return ctx.Repo.GitRepo }) // If request sends files, parse them here otherwise the Query() can't be parsed and the CsrfToken will be invalid. if ctx.Req.Method == "POST" && strings.Contains(ctx.Req.Header.Get("Content-Type"), "multipart/form-data") { @@ -278,10 +278,9 @@ func ReferencesGitRepo(allowEmpty ...bool) func(ctx *APIContext) (cancel context // For API calls. if ctx.Repo.GitRepo == nil { - repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) - gitRepo, err := git.OpenRepository(ctx, repoPath) + gitRepo, err := gitrepo.OpenRepository(ctx, ctx.Repo.Repository) if err != nil { - ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo "+repoPath, err) + ctx.Error(http.StatusInternalServerError, fmt.Sprintf("Open Repository %v failed", ctx.Repo.Repository.FullName()), err) return cancel } ctx.Repo.GitRepo = gitRepo diff --git a/modules/context/context.go b/modules/context/context.go index 8a94e958b5..d19c5d1198 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -17,7 +17,7 @@ import ( "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" mc "code.gitea.io/gitea/modules/cache" - "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/httpcache" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" @@ -163,7 +163,7 @@ func Contexter() func(next http.Handler) http.Handler { ctx.Data["PageData"] = ctx.PageData ctx.Base.AppendContextValue(WebContextKey, ctx) - ctx.Base.AppendContextValueFunc(git.RepositoryContextKey, func() any { return ctx.Repo.GitRepo }) + ctx.Base.AppendContextValueFunc(gitrepo.RepositoryContextKey, func() any { return ctx.Repo.GitRepo }) ctx.Csrf = PrepareCSRFProtector(csrfOpts, ctx) diff --git a/modules/context/repo.go b/modules/context/repo.go index 8d82be1990..75ebfec705 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -23,6 +23,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/gitrepo" code_indexer "code.gitea.io/gitea/modules/indexer/code" "code.gitea.io/gitea/modules/log" repo_module "code.gitea.io/gitea/modules/repository" @@ -633,7 +634,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc { return nil } - gitRepo, err := git.OpenRepository(ctx, repo_model.RepoPath(userName, repoName)) + gitRepo, err := gitrepo.OpenRepository(ctx, repo) if err != nil { if strings.Contains(err.Error(), "repository does not exist") || strings.Contains(err.Error(), "no such file or directory") { log.Error("Repository %-v has a broken repository on the file system: %s Error: %v", ctx.Repo.Repository, ctx.Repo.Repository.RepoPath(), err) @@ -645,7 +646,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc { } return nil } - ctx.ServerError("RepoAssignment Invalid repo "+repo_model.RepoPath(userName, repoName), err) + ctx.ServerError("RepoAssignment Invalid repo "+repo.FullName(), err) return nil } if ctx.Repo.GitRepo != nil { @@ -920,10 +921,9 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context ) if ctx.Repo.GitRepo == nil { - repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) - ctx.Repo.GitRepo, err = git.OpenRepository(ctx, repoPath) + ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository) if err != nil { - ctx.ServerError("RepoRef Invalid repo "+repoPath, err) + ctx.ServerError(fmt.Sprintf("Open Repository %v failed", ctx.Repo.Repository.FullName()), err) return nil } // We opened it, we should close it diff --git a/modules/contexttest/context_tests.go b/modules/contexttest/context_tests.go index 8994c1e451..9ca028bb6e 100644 --- a/modules/contexttest/context_tests.go +++ b/modules/contexttest/context_tests.go @@ -18,7 +18,7 @@ import ( "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/web/middleware" @@ -107,7 +107,7 @@ func LoadRepoCommit(t *testing.T, ctx gocontext.Context) { assert.FailNow(t, "context is not *context.Context or *context.APIContext") } - gitRepo, err := git.OpenRepository(ctx, repo.Repository.RepoPath()) + gitRepo, err := gitrepo.OpenRepository(ctx, repo.Repository) assert.NoError(t, err) defer gitRepo.Close() branch, err := gitRepo.GetHEADBranch() @@ -137,7 +137,7 @@ func LoadUser(t *testing.T, ctx gocontext.Context, userID int64) { func LoadGitRepo(t *testing.T, ctx *context.Context) { assert.NoError(t, ctx.Repo.Repository.LoadOwner(ctx)) var err error - ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) + ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository) assert.NoError(t, err) } diff --git a/modules/git/repo_base.go b/modules/git/repo_base.go index a9d91d2deb..6c148d9af5 100644 --- a/modules/git/repo_base.go +++ b/modules/git/repo_base.go @@ -3,48 +3,4 @@ package git -import ( - "context" - "io" -) - var isGogit bool - -// contextKey is a value for use with context.WithValue. -type contextKey struct { - name string -} - -// RepositoryContextKey is a context key. It is used with context.Value() to get the current Repository for the context -var RepositoryContextKey = &contextKey{"repository"} - -// RepositoryFromContext attempts to get the repository from the context -func RepositoryFromContext(ctx context.Context, path string) *Repository { - value := ctx.Value(RepositoryContextKey) - if value == nil { - return nil - } - - if repo, ok := value.(*Repository); ok && repo != nil { - if repo.Path == path { - return repo - } - } - - return nil -} - -type nopCloser func() - -func (nopCloser) Close() error { return nil } - -// RepositoryFromContextOrOpen attempts to get the repository from the context or just opens it -func RepositoryFromContextOrOpen(ctx context.Context, path string) (*Repository, io.Closer, error) { - gitRepo := RepositoryFromContext(ctx, path) - if gitRepo != nil { - return gitRepo, nopCloser(nil), nil - } - - gitRepo, err := OpenRepository(ctx, path) - return gitRepo, gitRepo, err -} diff --git a/modules/git/repo_branch.go b/modules/git/repo_branch.go index 5958093975..979c5dec91 100644 --- a/modules/git/repo_branch.go +++ b/modules/git/repo_branch.go @@ -86,29 +86,6 @@ func (repo *Repository) GetBranch(branch string) (*Branch, error) { }, nil } -// GetBranchesByPath returns a branch by it's path -// if limit = 0 it will not limit -func GetBranchesByPath(ctx context.Context, path string, skip, limit int) ([]*Branch, int, error) { - gitRepo, err := OpenRepository(ctx, path) - if err != nil { - return nil, 0, err - } - defer gitRepo.Close() - - return gitRepo.GetBranches(skip, limit) -} - -// GetBranchCommitID returns a branch commit ID by its name -func GetBranchCommitID(ctx context.Context, path, branch string) (string, error) { - gitRepo, err := OpenRepository(ctx, path) - if err != nil { - return "", err - } - defer gitRepo.Close() - - return gitRepo.GetBranchCommitID(branch) -} - // GetBranches returns a slice of *git.Branch func (repo *Repository) GetBranches(skip, limit int) ([]*Branch, int, error) { brs, countAll, err := repo.GetBranchNames(skip, limit) diff --git a/modules/git/repo_branch_gogit.go b/modules/git/repo_branch_gogit.go index 1c0d9a18aa..d1ec14d811 100644 --- a/modules/git/repo_branch_gogit.go +++ b/modules/git/repo_branch_gogit.go @@ -7,7 +7,6 @@ package git import ( - "context" "sort" "strings" @@ -96,34 +95,6 @@ func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) { } // WalkReferences walks all the references from the repository -// refType should be empty, ObjectTag or ObjectBranch. All other values are equivalent to empty. -func WalkReferences(ctx context.Context, repoPath string, walkfn func(sha1, refname string) error) (int, error) { - repo := RepositoryFromContext(ctx, repoPath) - if repo == nil { - var err error - repo, err = OpenRepository(ctx, repoPath) - if err != nil { - return 0, err - } - defer repo.Close() - } - - i := 0 - iter, err := repo.gogitRepo.References() - if err != nil { - return i, err - } - defer iter.Close() - - err = iter.ForEach(func(ref *plumbing.Reference) error { - err := walkfn(ref.Hash().String(), string(ref.Name())) - i++ - return err - }) - return i, err -} - -// WalkReferences walks all the references from the repository func (repo *Repository) WalkReferences(arg ObjectType, skip, limit int, walkfn func(sha1, refname string) error) (int, error) { i := 0 var iter storer.ReferenceIter diff --git a/modules/git/repo_branch_nogogit.go b/modules/git/repo_branch_nogogit.go index b1e7c8b73e..470faebe25 100644 --- a/modules/git/repo_branch_nogogit.go +++ b/modules/git/repo_branch_nogogit.go @@ -66,11 +66,6 @@ func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) { } // WalkReferences walks all the references from the repository -func WalkReferences(ctx context.Context, repoPath string, walkfn func(sha1, refname string) error) (int, error) { - return walkShowRef(ctx, repoPath, nil, 0, 0, walkfn) -} - -// WalkReferences walks all the references from the repository // refType should be empty, ObjectTag or ObjectBranch. All other values are equivalent to empty. func (repo *Repository) WalkReferences(refType ObjectType, skip, limit int, walkfn func(sha1, refname string) error) (int, error) { var args TrustedCmdArgs @@ -81,12 +76,12 @@ func (repo *Repository) WalkReferences(refType ObjectType, skip, limit int, walk args = TrustedCmdArgs{BranchPrefix, "--sort=-committerdate"} } - return walkShowRef(repo.Ctx, repo.Path, args, skip, limit, walkfn) + return WalkShowRef(repo.Ctx, repo.Path, args, skip, limit, walkfn) } // callShowRef return refs, if limit = 0 it will not limit func callShowRef(ctx context.Context, repoPath, trimPrefix string, extraArgs TrustedCmdArgs, skip, limit int) (branchNames []string, countAll int, err error) { - countAll, err = walkShowRef(ctx, repoPath, extraArgs, skip, limit, func(_, branchName string) error { + countAll, err = WalkShowRef(ctx, repoPath, extraArgs, skip, limit, func(_, branchName string) error { branchName = strings.TrimPrefix(branchName, trimPrefix) branchNames = append(branchNames, branchName) @@ -95,7 +90,7 @@ func callShowRef(ctx context.Context, repoPath, trimPrefix string, extraArgs Tru return branchNames, countAll, err } -func walkShowRef(ctx context.Context, repoPath string, extraArgs TrustedCmdArgs, skip, limit int, walkfn func(sha1, refname string) error) (countAll int, err error) { +func WalkShowRef(ctx context.Context, repoPath string, extraArgs TrustedCmdArgs, skip, limit int, walkfn func(sha1, refname string) error) (countAll int, err error) { stdoutReader, stdoutWriter := io.Pipe() defer func() { _ = stdoutReader.Close() @@ -189,7 +184,7 @@ func walkShowRef(ctx context.Context, repoPath string, extraArgs TrustedCmdArgs, // GetRefsBySha returns all references filtered with prefix that belong to a sha commit hash func (repo *Repository) GetRefsBySha(sha, prefix string) ([]string, error) { var revList []string - _, err := walkShowRef(repo.Ctx, repo.Path, nil, 0, 0, func(walkSha, refname string) error { + _, err := WalkShowRef(repo.Ctx, repo.Path, nil, 0, 0, func(walkSha, refname string) error { if walkSha == sha && strings.HasPrefix(refname, prefix) { revList = append(revList, refname) } diff --git a/modules/gitrepo/branch.go b/modules/gitrepo/branch.go new file mode 100644 index 0000000000..dcaf92668d --- /dev/null +++ b/modules/gitrepo/branch.go @@ -0,0 +1,32 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package gitrepo + +import ( + "context" + + "code.gitea.io/gitea/modules/git" +) + +// GetBranchesByPath returns a branch by its path +// if limit = 0 it will not limit +func GetBranchesByPath(ctx context.Context, repo Repository, skip, limit int) ([]*git.Branch, int, error) { + gitRepo, err := OpenRepository(ctx, repo) + if err != nil { + return nil, 0, err + } + defer gitRepo.Close() + + return gitRepo.GetBranches(skip, limit) +} + +func GetBranchCommitID(ctx context.Context, repo Repository, branch string) (string, error) { + gitRepo, err := OpenRepository(ctx, repo) + if err != nil { + return "", err + } + defer gitRepo.Close() + + return gitRepo.GetBranchCommitID(branch) +} diff --git a/modules/gitrepo/gitrepo.go b/modules/gitrepo/gitrepo.go new file mode 100644 index 0000000000..d89f8f9c0c --- /dev/null +++ b/modules/gitrepo/gitrepo.go @@ -0,0 +1,103 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package gitrepo + +import ( + "context" + "io" + "path/filepath" + "strings" + + "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/setting" +) + +type Repository interface { + GetName() string + GetOwnerName() string +} + +func repoPath(repo Repository) string { + return filepath.Join(setting.RepoRootPath, strings.ToLower(repo.GetOwnerName()), strings.ToLower(repo.GetName())+".git") +} + +func wikiPath(repo Repository) string { + return filepath.Join(setting.RepoRootPath, strings.ToLower(repo.GetOwnerName()), strings.ToLower(repo.GetName())+".wiki.git") +} + +// OpenRepository opens the repository at the given relative path with the provided context. +func OpenRepository(ctx context.Context, repo Repository) (*git.Repository, error) { + return git.OpenRepository(ctx, repoPath(repo)) +} + +func OpenWikiRepository(ctx context.Context, repo Repository) (*git.Repository, error) { + return git.OpenRepository(ctx, wikiPath(repo)) +} + +// contextKey is a value for use with context.WithValue. +type contextKey struct { + name string +} + +// RepositoryContextKey is a context key. It is used with context.Value() to get the current Repository for the context +var RepositoryContextKey = &contextKey{"repository"} + +// RepositoryFromContext attempts to get the repository from the context +func repositoryFromContext(ctx context.Context, repo Repository) *git.Repository { + value := ctx.Value(RepositoryContextKey) + if value == nil { + return nil + } + + if gitRepo, ok := value.(*git.Repository); ok && gitRepo != nil { + if gitRepo.Path == repoPath(repo) { + return gitRepo + } + } + + return nil +} + +type nopCloser func() + +func (nopCloser) Close() error { return nil } + +// RepositoryFromContextOrOpen attempts to get the repository from the context or just opens it +func RepositoryFromContextOrOpen(ctx context.Context, repo Repository) (*git.Repository, io.Closer, error) { + gitRepo := repositoryFromContext(ctx, repo) + if gitRepo != nil { + return gitRepo, nopCloser(nil), nil + } + + gitRepo, err := OpenRepository(ctx, repo) + return gitRepo, gitRepo, err +} + +// repositoryFromContextPath attempts to get the repository from the context +func repositoryFromContextPath(ctx context.Context, path string) *git.Repository { + value := ctx.Value(RepositoryContextKey) + if value == nil { + return nil + } + + if repo, ok := value.(*git.Repository); ok && repo != nil { + if repo.Path == path { + return repo + } + } + + return nil +} + +// RepositoryFromContextOrOpenPath attempts to get the repository from the context or just opens it +// Deprecated: Use RepositoryFromContextOrOpen instead +func RepositoryFromContextOrOpenPath(ctx context.Context, path string) (*git.Repository, io.Closer, error) { + gitRepo := repositoryFromContextPath(ctx, path) + if gitRepo != nil { + return gitRepo, nopCloser(nil), nil + } + + gitRepo, err := git.OpenRepository(ctx, path) + return gitRepo, gitRepo, err +} diff --git a/modules/gitrepo/walk_gogit.go b/modules/gitrepo/walk_gogit.go new file mode 100644 index 0000000000..6370faf08e --- /dev/null +++ b/modules/gitrepo/walk_gogit.go @@ -0,0 +1,40 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build gogit + +package gitrepo + +import ( + "context" + + "github.com/go-git/go-git/v5/plumbing" +) + +// WalkReferences walks all the references from the repository +// refname is empty, ObjectTag or ObjectBranch. All other values should be treated as equivalent to empty. +func WalkReferences(ctx context.Context, repo Repository, walkfn func(sha1, refname string) error) (int, error) { + gitRepo := repositoryFromContext(ctx, repo) + if gitRepo == nil { + var err error + gitRepo, err = OpenRepository(ctx, repo) + if err != nil { + return 0, err + } + defer gitRepo.Close() + } + + i := 0 + iter, err := gitRepo.GoGitRepo().References() + if err != nil { + return i, err + } + defer iter.Close() + + err = iter.ForEach(func(ref *plumbing.Reference) error { + err := walkfn(ref.Hash().String(), string(ref.Name())) + i++ + return err + }) + return i, err +} diff --git a/modules/gitrepo/walk_nogogit.go b/modules/gitrepo/walk_nogogit.go new file mode 100644 index 0000000000..ff9555996d --- /dev/null +++ b/modules/gitrepo/walk_nogogit.go @@ -0,0 +1,17 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build !gogit + +package gitrepo + +import ( + "context" + + "code.gitea.io/gitea/modules/git" +) + +// WalkReferences walks all the references from the repository +func WalkReferences(ctx context.Context, repo Repository, walkfn func(sha1, refname string) error) (int, error) { + return git.WalkShowRef(ctx, repoPath(repo), nil, 0, 0, walkfn) +} diff --git a/modules/indexer/stats/db.go b/modules/indexer/stats/db.go index 163843b47f..98a977c700 100644 --- a/modules/indexer/stats/db.go +++ b/modules/indexer/stats/db.go @@ -8,6 +8,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/process" @@ -35,7 +36,7 @@ func (db *DBIndexer) Index(id int64) error { return err } - gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) + gitRepo, err := gitrepo.OpenRepository(ctx, repo) if err != nil { if err.Error() == "no such file or directory" { return nil diff --git a/modules/repository/branch.go b/modules/repository/branch.go index cd45f16227..e448490f4a 100644 --- a/modules/repository/branch.go +++ b/modules/repository/branch.go @@ -11,6 +11,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" ) @@ -24,9 +25,9 @@ func SyncRepoBranches(ctx context.Context, repoID, doerID int64) (int64, error) log.Debug("SyncRepoBranches: in Repo[%d:%s]", repo.ID, repo.FullName()) - gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) + gitRepo, err := gitrepo.OpenRepository(ctx, repo) if err != nil { - log.Error("OpenRepository[%s]: %w", repo.RepoPath(), err) + log.Error("OpenRepository[%s]: %w", repo.FullName(), err) return 0, err } defer gitRepo.Close() diff --git a/modules/repository/generate.go b/modules/repository/generate.go index f8478b8c18..b32c4e058e 100644 --- a/modules/repository/generate.go +++ b/modules/repository/generate.go @@ -19,6 +19,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/util" @@ -271,7 +272,7 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r repo.DefaultBranch = templateRepo.DefaultBranch } - gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) + gitRepo, err := gitrepo.OpenRepository(ctx, repo) if err != nil { return fmt.Errorf("openRepository: %w", err) } diff --git a/modules/repository/repo.go b/modules/repository/repo.go index 5352da0378..fc3af04071 100644 --- a/modules/repository/repo.go +++ b/modules/repository/repo.go @@ -19,6 +19,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/migration" @@ -291,7 +292,7 @@ func SyncRepoTags(ctx context.Context, repoID int64) error { return err } - gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) + gitRepo, err := gitrepo.OpenRepository(ctx, repo) if err != nil { return err } |