diff options
author | zeripath <art27@cantab.net> | 2022-01-19 23:26:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-19 23:26:57 +0000 |
commit | 5cb0c9aa0d7eed087055b1efca79628957207d36 (patch) | |
tree | d117a514e1f17e5f6bfcda1be273f6a971112663 /modules/doctor/mergebase.go | |
parent | 4563148a61ba892e8f2bb66342f00a950bcd5315 (diff) | |
download | gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.tar.gz gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.zip |
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>
Diffstat (limited to 'modules/doctor/mergebase.go')
-rw-r--r-- | modules/doctor/mergebase.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/modules/doctor/mergebase.go b/modules/doctor/mergebase.go index ef78cc49d1..e2ebc41aa5 100644 --- a/modules/doctor/mergebase.go +++ b/modules/doctor/mergebase.go @@ -5,6 +5,7 @@ package doctor import ( + "context" "fmt" "strings" @@ -28,7 +29,7 @@ func iteratePRs(repo *repo_model.Repository, each func(*repo_model.Repository, * ) } -func checkPRMergeBase(logger log.Logger, autofix bool) error { +func checkPRMergeBase(ctx context.Context, logger log.Logger, autofix bool) error { numRepos := 0 numPRs := 0 numPRsUpdated := 0 @@ -43,17 +44,17 @@ func checkPRMergeBase(logger log.Logger, autofix bool) error { if !pr.HasMerged { var err error - pr.MergeBase, err = git.NewCommand("merge-base", "--", pr.BaseBranch, pr.GetGitRefName()).RunInDir(repoPath) + pr.MergeBase, err = git.NewCommandContext(ctx, "merge-base", "--", pr.BaseBranch, pr.GetGitRefName()).RunInDir(repoPath) if err != nil { var err2 error - pr.MergeBase, err2 = git.NewCommand("rev-parse", git.BranchPrefix+pr.BaseBranch).RunInDir(repoPath) + pr.MergeBase, err2 = git.NewCommandContext(ctx, "rev-parse", git.BranchPrefix+pr.BaseBranch).RunInDir(repoPath) if err2 != nil { logger.Warn("Unable to get merge base for PR ID %d, #%d onto %s in %s/%s. Error: %v & %v", pr.ID, pr.Index, pr.BaseBranch, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, err, err2) return nil } } } else { - parentsString, err := git.NewCommand("rev-list", "--parents", "-n", "1", pr.MergedCommitID).RunInDir(repoPath) + parentsString, err := git.NewCommandContext(ctx, "rev-list", "--parents", "-n", "1", pr.MergedCommitID).RunInDir(repoPath) if err != nil { logger.Warn("Unable to get parents for merged PR ID %d, #%d onto %s in %s/%s. Error: %v", pr.ID, pr.Index, pr.BaseBranch, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, err) return nil @@ -66,7 +67,7 @@ func checkPRMergeBase(logger log.Logger, autofix bool) error { args := append([]string{"merge-base", "--"}, parents[1:]...) args = append(args, pr.GetGitRefName()) - pr.MergeBase, err = git.NewCommand(args...).RunInDir(repoPath) + pr.MergeBase, err = git.NewCommandContext(ctx, args...).RunInDir(repoPath) if err != nil { logger.Warn("Unable to get merge base for merged PR ID %d, #%d onto %s in %s/%s. Error: %v", pr.ID, pr.Index, pr.BaseBranch, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, err) return nil |