mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-02 17:59:29 +00:00
refactor: remove Ctx field from git.Repository (#38500)
This commit is contained in:
@@ -333,7 +333,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
||||
return nil, fmt.Errorf("GetFullCommitID(%s) in %s: %w", prHeadRef, pr.BaseRepo.FullName(), err)
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
|
||||
gitRepo, err := gitrepo.OpenRepository(pr.BaseRepo)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%-v OpenRepository: %w", pr.BaseRepo, err)
|
||||
}
|
||||
@@ -360,7 +360,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
||||
// PR was maybe fast-forwarded, so just use last commit of PR
|
||||
mergeCommit = prHeadCommitID
|
||||
}
|
||||
commit, err := gitRepo.GetCommit(mergeCommit)
|
||||
commit, err := gitRepo.GetCommit(ctx, mergeCommit)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetMergeCommit[%s]: %w", mergeCommit, err)
|
||||
}
|
||||
|
||||
@@ -106,12 +106,12 @@ func CreatePushPullComment(ctx context.Context, pusher *user_model.User, pr *iss
|
||||
|
||||
oldCommitID := oldRef
|
||||
if !git.IsEmptyCommitID(oldRef) {
|
||||
oldCommitID, err = gitRepo.GetRefCommitID(oldRef)
|
||||
oldCommitID, err = gitRepo.GetRefCommitID(ctx, oldRef)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
}
|
||||
newCommitID, err := gitRepo.GetRefCommitID(newRef)
|
||||
newCommitID, err := gitRepo.GetRefCommitID(ctx, newRef)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
@@ -19,13 +19,14 @@ import (
|
||||
)
|
||||
|
||||
func TestCreatePushPullCommentForcePushDeletesOldComments(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
pusher := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
||||
require.NoError(t, pr.LoadIssue(t.Context()))
|
||||
require.NoError(t, pr.LoadBaseRepo(t.Context()))
|
||||
require.NoError(t, pr.LoadIssue(ctx))
|
||||
require.NoError(t, pr.LoadBaseRepo(ctx))
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), pr.BaseRepo)
|
||||
gitRepo, err := gitrepo.OpenRepository(pr.BaseRepo)
|
||||
require.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
@@ -65,7 +66,7 @@ func TestCreatePushPullCommentForcePushDeletesOldComments(t *testing.T) {
|
||||
insertCommitComment(t, issues_model.PushActionContent{})
|
||||
assertCommitCommentCount(t, 2, 0)
|
||||
|
||||
baseCommit, err := gitRepo.GetBranchCommit(pr.BaseBranch)
|
||||
baseCommit, err := gitRepo.GetBranchCommit(ctx, pr.BaseBranch)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// force push, the old push comments should be deleted, and one new force-push comment should be created.
|
||||
@@ -83,7 +84,7 @@ func TestCreatePushPullCommentForcePushDeletesOldComments(t *testing.T) {
|
||||
|
||||
t.Run("force-push-ignores-missing-old-commit", func(t *testing.T) {
|
||||
require.NoError(t, db.TruncateBeans(t.Context(), &issues_model.Comment{}))
|
||||
headCommit, err := gitRepo.GetBranchCommit(pr.HeadBranch)
|
||||
headCommit, err := gitRepo.GetBranchCommit(ctx, pr.HeadBranch)
|
||||
require.NoError(t, err)
|
||||
|
||||
commitIDZero := git.Sha1ObjectFormat.EmptyObjectID().String()
|
||||
@@ -110,9 +111,9 @@ func TestCreatePushPullCommentForcePushDeletesOldComments(t *testing.T) {
|
||||
insertCommitComment(t, issues_model.PushActionContent{})
|
||||
assertCommitCommentCount(t, 4, 0)
|
||||
|
||||
baseCommit, err := gitRepo.GetBranchCommit(pr.BaseBranch)
|
||||
baseCommit, err := gitRepo.GetBranchCommit(ctx, pr.BaseBranch)
|
||||
require.NoError(t, err)
|
||||
headCommit, err := gitRepo.GetBranchCommit(pr.HeadBranch)
|
||||
headCommit, err := gitRepo.GetBranchCommit(ctx, pr.HeadBranch)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = CreatePushPullComment(t.Context(), pusher, pr, baseCommit.ID.String(), headCommit.ID.String(), true)
|
||||
|
||||
@@ -127,9 +127,9 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullR
|
||||
|
||||
var sha string
|
||||
if pr.Flow == issues_model.PullRequestFlowGithub {
|
||||
sha, err = headGitRepo.GetBranchCommitID(pr.HeadBranch)
|
||||
sha, err = headGitRepo.GetBranchCommitID(ctx, pr.HeadBranch)
|
||||
} else {
|
||||
sha, err = headGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
sha, err = headGitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -68,7 +68,7 @@ func getMergeMessage(ctx context.Context, baseGitRepo *git.Repository, pr *issue
|
||||
|
||||
if mergeStyle != "" {
|
||||
templateFilepath := fmt.Sprintf(".gitea/default_merge_message/%s_TEMPLATE.md", strings.ToUpper(string(mergeStyle)))
|
||||
commit, err := baseGitRepo.GetBranchCommit(pr.BaseRepo.DefaultBranch)
|
||||
commit, err := baseGitRepo.GetBranchCommit(ctx, pr.BaseRepo.DefaultBranch)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
@@ -642,7 +642,7 @@ func MergedManually(ctx context.Context, pr *issues_model.PullRequest, doer *use
|
||||
return errors.New("Wrong commit ID")
|
||||
}
|
||||
|
||||
commit, err := baseGitRepo.GetCommit(commitID)
|
||||
commit, err := baseGitRepo.GetCommit(ctx, commitID)
|
||||
if err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
return errors.New("Wrong commit ID")
|
||||
@@ -651,7 +651,7 @@ func MergedManually(ctx context.Context, pr *issues_model.PullRequest, doer *use
|
||||
}
|
||||
commitID = commit.ID.String()
|
||||
|
||||
ok, err := baseGitRepo.IsCommitInBranch(commitID, pr.BaseBranch)
|
||||
ok, err := baseGitRepo.IsCommitInBranch(ctx, commitID, pr.BaseBranch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ func createTemporaryRepoForMerge(ctx context.Context, pr *issues_model.PullReque
|
||||
mergeCtx.sig = doer.NewGitSig()
|
||||
mergeCtx.committer = mergeCtx.sig
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx, mergeCtx.tmpBasePath)
|
||||
gitRepo, err := git.OpenRepository(mergeCtx.tmpBasePath)
|
||||
if err != nil {
|
||||
defer cancel()
|
||||
return nil, nil, fmt.Errorf("failed to open temp git repo for pr[%d]: %w", mergeCtx.pr.ID, err)
|
||||
|
||||
@@ -59,7 +59,7 @@ func doMergeRebaseFastForward(ctx *mergeContext) error {
|
||||
}
|
||||
|
||||
// Original repo to read template from.
|
||||
baseGitRepo, err := gitrepo.OpenRepository(ctx, ctx.pr.BaseRepo)
|
||||
baseGitRepo, err := gitrepo.OpenRepository(ctx.pr.BaseRepo)
|
||||
if err != nil {
|
||||
log.Error("Unable to get Git repo for rebase: %v", err)
|
||||
return err
|
||||
|
||||
@@ -25,14 +25,14 @@ func getAuthorSignatureSquash(ctx *mergeContext) (*git.Signature, error) {
|
||||
// Try to get a signature from the same user in one of the commits, as the
|
||||
// poster email might be private or commits might have a different signature
|
||||
// than the primary email address of the poster.
|
||||
gitRepo, err := git.OpenRepository(ctx, ctx.tmpBasePath)
|
||||
gitRepo, err := git.OpenRepository(ctx.tmpBasePath)
|
||||
if err != nil {
|
||||
log.Error("%-v Unable to open base repository: %v", ctx.pr, err)
|
||||
return nil, err
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
commits, err := gitRepo.CommitsBetween(git.RefNameFromBranch(tmpRepoTrackingBranch), git.RefNameHead, -1)
|
||||
commits, err := gitRepo.CommitsBetween(ctx, git.RefNameFromBranch(tmpRepoTrackingBranch), git.RefNameHead, -1)
|
||||
if err != nil {
|
||||
log.Error("%-v Unable to get commits between: head and tracking branch: %v", ctx.pr, err)
|
||||
return nil, err
|
||||
|
||||
@@ -55,7 +55,7 @@ func checkPullRequestMergeableByMergeTree(ctx context.Context, pr *issues_model.
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
headGitRepo, err := gitrepo.OpenRepository(ctx, pr.HeadRepo)
|
||||
headGitRepo, err := gitrepo.OpenRepository(pr.HeadRepo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenRepository: %w", err)
|
||||
}
|
||||
@@ -66,7 +66,7 @@ func checkPullRequestMergeableByMergeTree(ctx context.Context, pr *issues_model.
|
||||
if pr.IsSameRepo() {
|
||||
baseGitRepo = headGitRepo
|
||||
} else {
|
||||
baseGitRepo, err = gitrepo.OpenRepository(ctx, pr.BaseRepo)
|
||||
baseGitRepo, err = gitrepo.OpenRepository(pr.BaseRepo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenRepository: %w", err)
|
||||
}
|
||||
@@ -75,13 +75,13 @@ func checkPullRequestMergeableByMergeTree(ctx context.Context, pr *issues_model.
|
||||
|
||||
// 3. Get head commit id
|
||||
if pr.Flow == issues_model.PullRequestFlowGithub {
|
||||
pr.HeadCommitID, err = headGitRepo.GetRefCommitID(git.BranchPrefix + pr.HeadBranch)
|
||||
pr.HeadCommitID, err = headGitRepo.GetRefCommitID(ctx, git.BranchPrefix+pr.HeadBranch)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetBranchCommitID: can't find commit ID for head: %w", err)
|
||||
}
|
||||
} else {
|
||||
if pr.ID > 0 {
|
||||
pr.HeadCommitID, err = baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
pr.HeadCommitID, err = baseGitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRefCommitID: can't find commit ID for head: %w", err)
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func checkPullRequestMergeableByMergeTree(ctx context.Context, pr *issues_model.
|
||||
// 4. fetch head commit id into the current repository
|
||||
// it will be checked in 2 weeks by default from git if the pull request created failure.
|
||||
if !pr.IsSameRepo() {
|
||||
if !baseGitRepo.IsReferenceExist(pr.HeadCommitID) {
|
||||
if !baseGitRepo.IsReferenceExist(ctx, pr.HeadCommitID) {
|
||||
if err := gitrepo.FetchRemoteCommit(ctx, pr.BaseRepo, pr.HeadRepo, pr.HeadCommitID); err != nil {
|
||||
return fmt.Errorf("FetchRemoteCommit: %w", err)
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func checkPullRequestMergeableByMergeTree(ctx context.Context, pr *issues_model.
|
||||
}
|
||||
|
||||
// 5. update merge base
|
||||
baseCommitID, err := baseGitRepo.GetRefCommitID(git.BranchPrefix + pr.BaseBranch)
|
||||
baseCommitID, err := baseGitRepo.GetRefCommitID(ctx, git.BranchPrefix+pr.BaseBranch)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetBranchCommitID: can't find commit ID for base: %w", err)
|
||||
}
|
||||
|
||||
+14
-14
@@ -39,11 +39,11 @@ func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io
|
||||
compareArg := pr.MergeBase + "..." + pr.GetGitHeadRefName()
|
||||
switch {
|
||||
case patch:
|
||||
err = gitRepo.GetPatch(compareArg, w)
|
||||
err = gitRepo.GetPatch(ctx, compareArg, w)
|
||||
case binary:
|
||||
err = gitRepo.GetDiffBinary(compareArg, w)
|
||||
err = gitRepo.GetDiffBinary(ctx, compareArg, w)
|
||||
default:
|
||||
err = gitRepo.GetDiff(compareArg, w)
|
||||
err = gitRepo.GetDiff(ctx, compareArg, w)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -74,7 +74,7 @@ func checkPullRequestMergeableByTmpRepo(ctx context.Context, pr *issues_model.Pu
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx, prCtx.tmpBasePath)
|
||||
gitRepo, err := git.OpenRepository(prCtx.tmpBasePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenRepository: %w", err)
|
||||
}
|
||||
@@ -84,13 +84,13 @@ func checkPullRequestMergeableByTmpRepo(ctx context.Context, pr *issues_model.Pu
|
||||
pr.MergeBase, _, err = gitcmd.NewCommand("merge-base", "--", tmpRepoBaseBranch, tmpRepoTrackingBranch).WithDir(prCtx.tmpBasePath).RunStdString(ctx)
|
||||
if err != nil {
|
||||
var err2 error
|
||||
pr.MergeBase, err2 = gitRepo.GetRefCommitID(git.BranchPrefix + tmpRepoBaseBranch)
|
||||
pr.MergeBase, err2 = gitRepo.GetRefCommitID(ctx, git.BranchPrefix+tmpRepoBaseBranch)
|
||||
if err2 != nil {
|
||||
return fmt.Errorf("GetMergeBase: %v and can't find commit ID for base: %w", err, err2)
|
||||
}
|
||||
}
|
||||
pr.MergeBase = strings.TrimSpace(pr.MergeBase)
|
||||
if pr.HeadCommitID, err = gitRepo.GetRefCommitID(git.BranchPrefix + tmpRepoTrackingBranch); err != nil {
|
||||
if pr.HeadCommitID, err = gitRepo.GetRefCommitID(ctx, git.BranchPrefix+tmpRepoTrackingBranch); err != nil {
|
||||
return fmt.Errorf("GetBranchCommitID: can't find commit ID for head: %w", err)
|
||||
}
|
||||
|
||||
@@ -289,10 +289,10 @@ func AttemptThreeWayMerge(ctx context.Context, gitPath string, gitRepo *git.Repo
|
||||
}
|
||||
|
||||
// Add and remove files in one command, as this is slow with many files otherwise
|
||||
if err := gitRepo.RemoveFilesFromIndex(filesToRemove...); err != nil {
|
||||
if err := gitRepo.RemoveFilesFromIndex(ctx, filesToRemove...); err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
if err := gitRepo.AddObjectsToIndex(filesToAdd...); err != nil {
|
||||
if err := gitRepo.AddObjectsToIndex(ctx, filesToAdd...); err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ func checkConflictsByTmpRepo(ctx context.Context, pr *issues_model.PullRequest,
|
||||
return false, fmt.Errorf("unable to write unconflicted tree: %w\n`git ls-files -u`:\n%s", err, lsfiles)
|
||||
}
|
||||
treeHash = strings.TrimSpace(treeHash)
|
||||
baseTree, err := gitRepo.GetTree(tmpRepoBaseBranch)
|
||||
baseTree, err := gitRepo.GetTree(ctx, tmpRepoBaseBranch)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -366,11 +366,11 @@ func (err ErrFilePathProtected) Unwrap() error {
|
||||
}
|
||||
|
||||
// CheckFileProtection check file Protection
|
||||
func CheckFileProtection(repo *git.Repository, branchName, oldCommitID, newCommitID string, patterns []glob.Glob, limit int, env []string) ([]string, error) {
|
||||
func CheckFileProtection(ctx context.Context, repo *git.Repository, branchName, oldCommitID, newCommitID string, patterns []glob.Glob, limit int, env []string) ([]string, error) {
|
||||
if len(patterns) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
affectedFiles, err := git.GetAffectedFiles(repo, branchName, oldCommitID, newCommitID, env)
|
||||
affectedFiles, err := git.GetAffectedFiles(ctx, repo, branchName, oldCommitID, newCommitID, env)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -396,11 +396,11 @@ func CheckFileProtection(repo *git.Repository, branchName, oldCommitID, newCommi
|
||||
}
|
||||
|
||||
// CheckUnprotectedFiles check if the commit only touches unprotected files
|
||||
func CheckUnprotectedFiles(repo *git.Repository, branchName, oldCommitID, newCommitID string, patterns []glob.Glob, env []string) (bool, error) {
|
||||
func CheckUnprotectedFiles(ctx context.Context, repo *git.Repository, branchName, oldCommitID, newCommitID string, patterns []glob.Glob, env []string) (bool, error) {
|
||||
if len(patterns) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
affectedFiles, err := git.GetAffectedFiles(repo, branchName, oldCommitID, newCommitID, env)
|
||||
affectedFiles, err := git.GetAffectedFiles(ctx, repo, branchName, oldCommitID, newCommitID, env)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -437,7 +437,7 @@ func checkPullFilesProtection(ctx context.Context, pr *issues_model.PullRequest,
|
||||
return nil
|
||||
}
|
||||
|
||||
pr.ChangedProtectedFiles, err = CheckFileProtection(gitRepo, pr.HeadBranch, pr.MergeBase, headRef, pb.GetProtectedFilePatterns(), 10, os.Environ())
|
||||
pr.ChangedProtectedFiles, err = CheckFileProtection(ctx, gitRepo, pr.HeadBranch, pr.MergeBase, headRef, pb.GetProtectedFilePatterns(), 10, os.Environ())
|
||||
if err != nil && !IsErrFilePathProtected(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
+10
-10
@@ -365,7 +365,7 @@ func checkForInvalidation(ctx context.Context, requests issues_model.PullRequest
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepositoryByIDCtx: %w", err)
|
||||
}
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gitrepo.OpenRepository: %w", err)
|
||||
}
|
||||
@@ -803,7 +803,7 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequ
|
||||
if pr.Flow == issues_model.PullRequestFlowGithub {
|
||||
headCommitRef = git.RefNameFromBranch(pr.HeadBranch)
|
||||
} else {
|
||||
pr.HeadCommitID, err = gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
pr.HeadCommitID, err = gitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -814,7 +814,7 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequ
|
||||
|
||||
limit := setting.Repository.PullRequest.DefaultMergeMessageCommitsLimit
|
||||
|
||||
limitedCommits, err := gitRepo.CommitsBetween(headCommitRef, mergeBaseRef, limit)
|
||||
limitedCommits, err := gitRepo.CommitsBetween(ctx, headCommitRef, mergeBaseRef, limit)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -874,7 +874,7 @@ func collectSquashMergeCommitCoAuthors(ctx context.Context, gitRepo *git.Reposit
|
||||
skip := limitFirst
|
||||
batchLimit := 30
|
||||
for {
|
||||
commits, err := gitRepo.CommitsBetween(headCommitRef, mergeBaseRef, batchLimit, skip)
|
||||
commits, err := gitRepo.CommitsBetween(ctx, headCommitRef, mergeBaseRef, batchLimit, skip)
|
||||
if err != nil {
|
||||
log.Error("Unable to get commits between: %s %s Error: %v", pr.HeadBranch, pr.MergeBase, err)
|
||||
return authors
|
||||
@@ -960,7 +960,7 @@ func GetIssuesAllCommitStatus(ctx context.Context, issues issues_model.IssueList
|
||||
}
|
||||
gitRepo, ok := gitRepos[issue.RepoID]
|
||||
if !ok {
|
||||
gitRepo, err = gitrepo.OpenRepository(ctx, issue.Repo)
|
||||
gitRepo, err = gitrepo.OpenRepository(issue.Repo)
|
||||
if err != nil {
|
||||
log.Error("Cannot open git repository %-v for issue #%d[%d]. Error: %v", issue.Repo, issue.Index, issue.ID, err)
|
||||
continue
|
||||
@@ -981,7 +981,7 @@ func GetIssuesAllCommitStatus(ctx context.Context, issues issues_model.IssueList
|
||||
|
||||
// getAllCommitStatus get pr's commit statuses.
|
||||
func getAllCommitStatus(ctx context.Context, gitRepo *git.Repository, pr *issues_model.PullRequest) (statuses []*git_model.CommitStatus, lastStatus *git_model.CommitStatus, err error) {
|
||||
sha, shaErr := gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
sha, shaErr := gitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if shaErr != nil {
|
||||
return nil, nil, shaErr
|
||||
}
|
||||
@@ -1003,7 +1003,7 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br
|
||||
}
|
||||
defer closer.Close()
|
||||
|
||||
baseCommit, err := baseGitRepo.GetBranchCommit(branchName)
|
||||
baseCommit, err := baseGitRepo.GetBranchCommit(ctx, branchName)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -1026,16 +1026,16 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br
|
||||
|
||||
var headCommit *git.Commit
|
||||
if pr.Flow == issues_model.PullRequestFlowGithub {
|
||||
headCommit, err = headGitRepo.GetBranchCommit(pr.HeadBranch)
|
||||
headCommit, err = headGitRepo.GetBranchCommit(ctx, pr.HeadBranch)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
} else {
|
||||
pr.HeadCommitID, err = baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
pr.HeadCommitID, err = baseGitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if headCommit, err = baseGitRepo.GetCommit(pr.HeadCommitID); err != nil {
|
||||
if headCommit, err = baseGitRepo.GetCommit(ctx, pr.HeadCommitID); err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestPullRequest_GetDefaultMergeMessage_InternalTracker(t *testing.T) {
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
||||
|
||||
assert.NoError(t, pr.LoadBaseRepo(t.Context()))
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), pr.BaseRepo)
|
||||
gitRepo, err := gitrepo.OpenRepository(pr.BaseRepo)
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) {
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2, BaseRepo: baseRepo})
|
||||
|
||||
assert.NoError(t, pr.LoadBaseRepo(t.Context()))
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), pr.BaseRepo)
|
||||
gitRepo, err := gitrepo.OpenRepository(pr.BaseRepo)
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ func lineBlame(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Re
|
||||
}
|
||||
|
||||
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
|
||||
return gitRepo.GetCommit(sha[:objectFormat.FullLength()])
|
||||
return gitRepo.GetCommit(ctx, sha[:objectFormat.FullLength()])
|
||||
}
|
||||
|
||||
// checkInvalidation checks if the line of code comment got changed by another commit.
|
||||
@@ -266,7 +266,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
|
||||
|
||||
// Only fetch diff if comment is review comment
|
||||
if len(patch) == 0 && reviewID != 0 {
|
||||
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
headCommitID, err := gitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetRefCommitID[%s]: %w", pr.GetGitHeadRefName(), err)
|
||||
}
|
||||
@@ -274,7 +274,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
|
||||
commitID = headCommitID
|
||||
}
|
||||
|
||||
patch, err = git.GetFileDiffCutAroundLine(
|
||||
patch, err = git.GetFileDiffCutAroundLine(ctx,
|
||||
gitRepo, pr.MergeBase, headCommitID, treePath,
|
||||
int64((&issues_model.Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines,
|
||||
)
|
||||
@@ -322,7 +322,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
|
||||
return nil, nil, ErrSubmitReviewOnClosedPR
|
||||
}
|
||||
|
||||
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
headCommitID, err := gitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user