1
0
Fork 0
forked from forgejo/forgejo

Propagate context and ensure git commands run in request context (#17868)

This PR continues the work in #17125 by progressively ensuring that git
commands run within the request context.

This now means that the if there is a git repo already open in the context it will be used instead of reopening it.

Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
zeripath 2022-01-19 23:26:57 +00:00 committed by GitHub
parent 4563148a61
commit 5cb0c9aa0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
193 changed files with 1264 additions and 1154 deletions

View file

@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/queue"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
@ -115,11 +116,13 @@ func (aReq *ArchiveRequest) GetArchiveName() string {
}
func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) {
ctx, committer, err := db.TxContext()
txCtx, committer, err := db.TxContext()
if err != nil {
return nil, err
}
defer committer.Close()
ctx, _, finished := process.GetManager().AddContext(txCtx, fmt.Sprintf("ArchiveRequest[%d]: %s", r.RepoID, r.GetArchiveName()))
defer finished()
archiver, err := repo_model.GetRepoArchiver(ctx, r.RepoID, r.Type, r.CommitID)
if err != nil {
@ -175,7 +178,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) {
return nil, fmt.Errorf("archiver.LoadRepo failed: %v", err)
}
gitRepo, err := git.OpenRepository(repo.RepoPath())
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
if err != nil {
return nil, err
}
@ -190,13 +193,13 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) {
if archiver.Type == git.BUNDLE {
err = gitRepo.CreateBundle(
graceful.GetManager().ShutdownContext(),
ctx,
archiver.CommitID,
w,
)
} else {
err = gitRepo.CreateArchive(
graceful.GetManager().ShutdownContext(),
ctx,
archiver.Type,
w,
setting.Repository.PrefixArchiveFiles,