mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-26 05:19:44 +09:00
refactor: remove Ctx field from git.Repository (#38500)
This commit is contained in:
@@ -48,11 +48,11 @@ func TestCreateCommitStatus_Dedupe(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
require.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
commit, err := gitRepo.GetBranchCommit(repo.DefaultBranch)
|
||||
commit, err := gitRepo.GetBranchCommit(t.Context(), repo.DefaultBranch)
|
||||
require.NoError(t, err)
|
||||
|
||||
run := &actions_model.ActionRun{
|
||||
|
||||
@@ -148,7 +148,7 @@ func notify(ctx context.Context, input *notifyInput) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(context.Background(), input.Repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(input.Repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("git.OpenRepository: %w", err)
|
||||
}
|
||||
@@ -167,13 +167,13 @@ func notify(ctx context.Context, input *notifyInput) error {
|
||||
ref = git.RefNameFromBranch(input.Repo.DefaultBranch)
|
||||
}
|
||||
|
||||
commitID, err := gitRepo.GetRefCommitID(ref.String())
|
||||
commitID, err := gitRepo.GetRefCommitID(ctx, ref.String())
|
||||
if err != nil {
|
||||
return fmt.Errorf("gitRepo.GetRefCommitID: %w", err)
|
||||
}
|
||||
|
||||
// Get the commit object for the ref
|
||||
commit, err := gitRepo.GetCommit(commitID)
|
||||
commit, err := gitRepo.GetCommit(ctx, commitID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gitRepo.GetCommit: %w", err)
|
||||
}
|
||||
@@ -227,7 +227,7 @@ func notify(ctx context.Context, input *notifyInput) error {
|
||||
if input.PullRequest != nil {
|
||||
// detect pull_request_target workflows
|
||||
baseRef := git.BranchPrefix + input.PullRequest.BaseBranch
|
||||
baseCommit, err := gitRepo.GetCommit(baseRef)
|
||||
baseCommit, err := gitRepo.GetCommit(ctx, baseRef)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gitRepo.GetCommit: %w", err)
|
||||
}
|
||||
@@ -591,14 +591,14 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository)
|
||||
return nil
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(context.Background(), repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("git.OpenRepository: %w", err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
// Only detect schedule workflows on the default branch
|
||||
commit, err := gitRepo.GetCommit(repo.DefaultBranch)
|
||||
commit, err := gitRepo.GetCommit(ctx, repo.DefaultBranch)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gitRepo.GetCommit: %w", err)
|
||||
}
|
||||
@@ -748,6 +748,6 @@ func detectScopedWorkflowsForSource(
|
||||
if err != nil {
|
||||
return "", nil, nil, err
|
||||
}
|
||||
detected, filtered = actions_module.MatchScopedWorkflows(parsed, consumerGitRepo, consumerCommit, input.Event, input.Payload)
|
||||
detected, filtered = actions_module.MatchScopedWorkflows(ctx, parsed, consumerGitRepo, consumerCommit, input.Event, input.Payload)
|
||||
return sourceCommitSHA, detected, filtered, nil
|
||||
}
|
||||
|
||||
@@ -79,13 +79,13 @@ func loadReusableWorkflowSource(ctx context.Context, run *actions_model.ActionRu
|
||||
|
||||
// readWorkflowFromRepo loads a workflow file from `repo` at `refOrSHA` and returns its content plus the resolved commit SHA.
|
||||
func readWorkflowFromRepo(ctx context.Context, repo *repo_model.Repository, refOrSHA, path string) ([]byte, string, error) {
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("open repo %s: %w", repo.FullName(), err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
commit, err := gitRepo.GetCommit(refOrSHA)
|
||||
commit, err := gitRepo.GetCommit(ctx, refOrSHA)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("get commit %q in %s: %w", refOrSHA, repo.FullName(), err)
|
||||
}
|
||||
|
||||
@@ -50,13 +50,13 @@ func LoadParsedScopedWorkflows(ctx context.Context, sourceRepo *repo_model.Repos
|
||||
}
|
||||
|
||||
// cache miss: open the source repo at the exact SHA we keyed on
|
||||
sourceGitRepo, err := gitrepo.OpenRepository(ctx, sourceRepo)
|
||||
sourceGitRepo, err := gitrepo.OpenRepository(sourceRepo)
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("open source repo: %w", err)
|
||||
}
|
||||
defer sourceGitRepo.Close()
|
||||
|
||||
sourceCommit, err := sourceGitRepo.GetCommit(sha)
|
||||
sourceCommit, err := sourceGitRepo.GetCommit(ctx, sha)
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("get source commit %s: %w", sha, err)
|
||||
}
|
||||
|
||||
@@ -85,12 +85,12 @@ func DispatchActionWorkflow(ctx reqctx.RequestContext, doer *user_model.User, re
|
||||
var runTargetCommit *git.Commit
|
||||
var err error
|
||||
if refName.IsTag() {
|
||||
runTargetCommit, err = gitRepo.GetTagCommit(refName.TagName())
|
||||
runTargetCommit, err = gitRepo.GetTagCommit(ctx, refName.TagName())
|
||||
} else if refName.IsBranch() {
|
||||
runTargetCommit, err = gitRepo.GetBranchCommit(refName.BranchName())
|
||||
runTargetCommit, err = gitRepo.GetBranchCommit(ctx, refName.BranchName())
|
||||
} else {
|
||||
refName = git.RefNameFromBranch(ref)
|
||||
runTargetCommit, err = gitRepo.GetBranchCommit(ref)
|
||||
runTargetCommit, err = gitRepo.GetBranchCommit(ctx, ref)
|
||||
}
|
||||
if err != nil {
|
||||
return 0, util.ErrorWrapTranslatable(
|
||||
@@ -183,7 +183,7 @@ func resolveDispatchWorkflowContent(ctx reqctx.RequestContext, repo *repo_model.
|
||||
}
|
||||
for _, e := range entries {
|
||||
if e.Name() == workflowID {
|
||||
return actions.GetContentFromEntry(gitRepo, e)
|
||||
return actions.GetContentFromEntry(ctx, gitRepo, e)
|
||||
}
|
||||
}
|
||||
return nil, util.ErrorWrapTranslatable(
|
||||
|
||||
@@ -146,7 +146,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
|
||||
var commit *git.Commit
|
||||
if title == "" || description == "" {
|
||||
commit, err = gitRepo.GetCommit(opts.NewCommitIDs[i])
|
||||
commit, err = gitRepo.GetCommit(ctx, opts.NewCommitIDs[i])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get commit %s in repository: %s Error: %w", opts.NewCommitIDs[i], repo.FullName(), err)
|
||||
}
|
||||
@@ -209,7 +209,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
return nil, fmt.Errorf("unable to load base repository for PR[%d] Error: %w", pr.ID, err)
|
||||
}
|
||||
|
||||
oldCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
oldCommitID, err := gitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err)
|
||||
}
|
||||
|
||||
+10
-11
@@ -17,7 +17,6 @@ import (
|
||||
repo_model "gitea.dev/models/repo"
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/gitrepo"
|
||||
"gitea.dev/modules/log"
|
||||
"gitea.dev/modules/process"
|
||||
"gitea.dev/modules/setting"
|
||||
@@ -171,7 +170,7 @@ Loop:
|
||||
// SignWikiCommit determines if we should sign the commits to this repository wiki
|
||||
func SignWikiCommit(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, u *user_model.User) (bool, *git.SigningKey, *git.Signature, error) {
|
||||
rules := signingModeFromStrings(setting.Repository.Signing.Wiki)
|
||||
signingKey, sig := gitrepo.GetSigningKey(ctx)
|
||||
signingKey, sig := git.GetSigningKey(ctx)
|
||||
if signingKey == nil {
|
||||
return false, nil, nil, &ErrWontSign{noKey}
|
||||
}
|
||||
@@ -200,7 +199,7 @@ Loop:
|
||||
return false, nil, nil, &ErrWontSign{twofa}
|
||||
}
|
||||
case parentSigned:
|
||||
commit, err := gitRepo.GetCommit("HEAD")
|
||||
commit, err := gitRepo.GetCommit(ctx, "HEAD")
|
||||
if err != nil {
|
||||
return false, nil, nil, err
|
||||
}
|
||||
@@ -248,12 +247,12 @@ Loop:
|
||||
return false, nil, nil, &ErrWontSign{twofa}
|
||||
}
|
||||
case parentSigned:
|
||||
isEmpty, err := gitRepo.IsEmpty()
|
||||
isEmpty, err := gitRepo.IsEmpty(ctx)
|
||||
if err != nil {
|
||||
return false, nil, nil, err
|
||||
}
|
||||
if !isEmpty {
|
||||
commit, err := gitRepo.GetCommit(parentCommit)
|
||||
commit, err := gitRepo.GetCommit(ctx, parentCommit)
|
||||
if err != nil {
|
||||
return false, nil, nil, err
|
||||
}
|
||||
@@ -280,16 +279,16 @@ func SignMerge(ctx context.Context, pr *issues_model.PullRequest, u *user_model.
|
||||
}
|
||||
repo := pr.BaseRepo
|
||||
|
||||
baseCommit, err := gitRepo.GetCommit(baseRef)
|
||||
baseCommit, err := gitRepo.GetCommit(ctx, baseRef)
|
||||
if err != nil {
|
||||
return false, nil, nil, err
|
||||
}
|
||||
headCommit, err := gitRepo.GetCommit(headRef)
|
||||
headCommit, err := gitRepo.GetCommit(ctx, headRef)
|
||||
if err != nil {
|
||||
return false, nil, nil, err
|
||||
}
|
||||
|
||||
signingKey, signer := gitrepo.GetSigningKey(ctx)
|
||||
signingKey, signer := git.GetSigningKey(ctx)
|
||||
if signingKey == nil {
|
||||
return false, nil, nil, &ErrWontSign{noKey}
|
||||
}
|
||||
@@ -355,11 +354,11 @@ Loop:
|
||||
// AllHeadCommitsVerified checks that every new commit in the PR head has a
|
||||
// verified signature.
|
||||
func AllHeadCommitsVerified(ctx context.Context, pr *issues_model.PullRequest, gitRepo *git.Repository) (bool, error) {
|
||||
baseCommit, err := gitRepo.GetCommit(pr.BaseBranch)
|
||||
baseCommit, err := gitRepo.GetCommit(ctx, pr.BaseBranch)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
headCommit, err := gitRepo.GetCommit(pr.GetGitHeadRefName())
|
||||
headCommit, err := gitRepo.GetCommit(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -369,7 +368,7 @@ func AllHeadCommitsVerified(ctx context.Context, pr *issues_model.PullRequest, g
|
||||
// allCommitsVerified checks the commits a merge would introduce, those reachable from
|
||||
// headCommit but not from baseCommit. Both commits must come from gitRepo.
|
||||
func allCommitsVerified(ctx context.Context, gitRepo *git.Repository, baseCommit, headCommit *git.Commit) (bool, error) {
|
||||
commitList, err := headCommit.CommitsBeforeUntil(gitRepo, baseCommit.ID.RefName())
|
||||
commitList, err := headCommit.CommitsBeforeUntil(ctx, gitRepo, baseCommit.ID.RefName())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -104,13 +104,13 @@ func StartPRCheckAndAutoMergeBySHA(ctx context.Context, sha string, repo *repo_m
|
||||
}
|
||||
|
||||
func getPullRequestsByHeadSHA(ctx context.Context, sha string, repo *repo_model.Repository, filter func(*issues_model.PullRequest) bool) (map[int64]*issues_model.PullRequest, error) {
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
refs, err := gitRepo.GetRefsBySha(sha, "")
|
||||
refs, err := gitRepo.GetRefsBySha(ctx, sha, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -181,14 +181,14 @@ func handlePullRequestAutoMerge(pullID int64, sha string) {
|
||||
}
|
||||
|
||||
// check the sha is the same as pull request head commit id
|
||||
baseGitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
|
||||
baseGitRepo, err := gitrepo.OpenRepository(pr.BaseRepo)
|
||||
if err != nil {
|
||||
log.Error("OpenRepository: %v", err)
|
||||
return
|
||||
}
|
||||
defer baseGitRepo.Close()
|
||||
|
||||
headCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
headCommitID, err := baseGitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
log.Error("GetRefCommitID: %v", err)
|
||||
return
|
||||
|
||||
@@ -34,13 +34,13 @@ func StartPRCheckAndAutoMerge(ctx context.Context, pull *issues_model.PullReques
|
||||
return
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, pull.BaseRepo)
|
||||
gitRepo, err := gitrepo.OpenRepository(pull.BaseRepo)
|
||||
if err != nil {
|
||||
log.Error("OpenRepository: %v", err)
|
||||
return
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
commitID, err := gitRepo.GetRefCommitID(pull.GetGitHeadRefName())
|
||||
commitID, err := gitRepo.GetRefCommitID(ctx, pull.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
log.Error("GetRefCommitID: %v", err)
|
||||
return
|
||||
|
||||
@@ -306,11 +306,11 @@ func RepoRefForAPI(next http.Handler) http.Handler {
|
||||
var err error
|
||||
switch refType {
|
||||
case git.RefTypeBranch:
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx, refName)
|
||||
case git.RefTypeTag:
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(ctx, refName)
|
||||
case git.RefTypeCommit:
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(ctx, refName)
|
||||
}
|
||||
if ctx.Repo.Commit == nil || errors.Is(err, util.ErrNotExist) {
|
||||
ctx.APIErrorNotFound("unable to find a git ref")
|
||||
|
||||
+16
-12
@@ -301,7 +301,7 @@ func (r *Repository) GetEditorconfig(ctx context.Context, optCommit ...*git.Comm
|
||||
if len(optCommit) != 0 {
|
||||
commit = optCommit[0]
|
||||
} else {
|
||||
commit, err = r.GitRepo.GetBranchCommit(r.Repository.DefaultBranch)
|
||||
commit, err = r.GitRepo.GetBranchCommit(ctx, r.Repository.DefaultBranch)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -310,10 +310,10 @@ func (r *Repository) GetEditorconfig(ctx context.Context, optCommit ...*git.Comm
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if treeEntry.Blob(r.GitRepo).Size() >= setting.UI.MaxDisplayFileSize {
|
||||
if treeEntry.Blob(r.GitRepo).Size(ctx) >= setting.UI.MaxDisplayFileSize {
|
||||
return nil, nil, git.ErrNotExist{ID: "", RelPath: ".editorconfig"}
|
||||
}
|
||||
reader, err := treeEntry.Blob(r.GitRepo).DataAsync()
|
||||
reader, err := treeEntry.Blob(r.GitRepo).DataAsync(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -830,7 +830,9 @@ func getRefNameLegacy(ctx *Base, repo *Repository, reqPath, extraRef string) (re
|
||||
func getRefName(ctx *Base, repo *Repository, path string, refType git.RefType) string {
|
||||
switch refType {
|
||||
case git.RefTypeBranch:
|
||||
ref := getRefNameFromPath(repo, path, repo.GitRepo.IsBranchExist)
|
||||
ref := getRefNameFromPath(repo, path, func(s string) bool {
|
||||
return repo.GitRepo.IsBranchExist(ctx, s)
|
||||
})
|
||||
if len(ref) == 0 {
|
||||
// check if ref is HEAD
|
||||
parts := strings.Split(path, "/")
|
||||
@@ -860,7 +862,9 @@ func getRefName(ctx *Base, repo *Repository, path string, refType git.RefType) s
|
||||
|
||||
return ref
|
||||
case git.RefTypeTag:
|
||||
return getRefNameFromPath(repo, path, repo.GitRepo.IsTagExist)
|
||||
return getRefNameFromPath(repo, path, func(s string) bool {
|
||||
return repo.GitRepo.IsTagExist(ctx, s)
|
||||
})
|
||||
case git.RefTypeCommit:
|
||||
parts := strings.Split(path, "/")
|
||||
if git.IsStringLikelyCommitID(repo.GetObjectFormat(), parts[0], 7) {
|
||||
@@ -871,7 +875,7 @@ func getRefName(ctx *Base, repo *Repository, path string, refType git.RefType) s
|
||||
|
||||
if parts[0] == headRefName {
|
||||
// HEAD ref points to last default branch commit
|
||||
commit, err := repo.GitRepo.GetBranchCommit(repo.Repository.DefaultBranch)
|
||||
commit, err := repo.GitRepo.GetBranchCommit(ctx, repo.Repository.DefaultBranch)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
@@ -902,7 +906,7 @@ func RepoRefByDefaultBranch() func(*Context) {
|
||||
return func(ctx *Context) {
|
||||
ctx.Repo.RefFullName = git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch)
|
||||
ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
|
||||
ctx.Repo.Commit, _ = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.BranchName)
|
||||
ctx.Repo.Commit, _ = ctx.Repo.GitRepo.GetBranchCommit(ctx, ctx.Repo.BranchName)
|
||||
ctx.Repo.CommitsCount, _ = ctx.Repo.GetCommitsCount(ctx)
|
||||
ctx.Data["RefFullName"] = ctx.Repo.RefFullName
|
||||
ctx.Data["BranchName"] = ctx.Repo.BranchName
|
||||
@@ -936,7 +940,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
|
||||
if reqPath == "" {
|
||||
refShortName = ctx.Repo.Repository.DefaultBranch
|
||||
if !gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, refShortName) {
|
||||
brs, _, err := ctx.Repo.GitRepo.GetBranchNames(0, 1)
|
||||
brs, _, err := ctx.Repo.GitRepo.GetBranchNames(ctx, 0, 1)
|
||||
if err == nil && len(brs) != 0 {
|
||||
refShortName = brs[0]
|
||||
} else if len(brs) == 0 {
|
||||
@@ -947,7 +951,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
|
||||
}
|
||||
ctx.Repo.RefFullName = git.RefNameFromBranch(refShortName)
|
||||
ctx.Repo.BranchName = refShortName
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refShortName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx, refShortName)
|
||||
if err == nil {
|
||||
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
|
||||
} else {
|
||||
@@ -976,7 +980,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
|
||||
ctx.Repo.BranchName = refShortName
|
||||
ctx.Repo.RefFullName = git.RefNameFromBranch(refShortName)
|
||||
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refShortName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx, refShortName)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetBranchCommit", err)
|
||||
return
|
||||
@@ -985,7 +989,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
|
||||
} else if refType == git.RefTypeTag && gitrepo.IsTagExist(ctx, ctx.Repo.Repository, refShortName) {
|
||||
ctx.Repo.RefFullName = git.RefNameFromTag(refShortName)
|
||||
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refShortName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(ctx, refShortName)
|
||||
if err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
@@ -999,7 +1003,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
|
||||
ctx.Repo.RefFullName = git.RefNameFromCommit(refShortName)
|
||||
ctx.Repo.CommitID = refShortName
|
||||
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refShortName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(ctx, refShortName)
|
||||
if err != nil {
|
||||
ctx.NotFound(err)
|
||||
return
|
||||
|
||||
@@ -141,7 +141,7 @@ func LoadRepoCommit(t *testing.T, ctx gocontext.Context) {
|
||||
assert.FailNow(t, "context is not *context.Context or *context.APIContext")
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, repo.Repository)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo.Repository)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
gitRepo.Close()
|
||||
@@ -152,7 +152,7 @@ func LoadRepoCommit(t *testing.T, ctx gocontext.Context) {
|
||||
if repo.RefFullName.IsPull() {
|
||||
repo.BranchName = repo.RefFullName.ShortName()
|
||||
}
|
||||
repo.Commit, err = gitRepo.GetCommit(repo.RefFullName.String())
|
||||
repo.Commit, err = gitRepo.GetCommit(ctx, repo.RefFullName.String())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ func LoadGitRepo(t *testing.T, ctx gocontext.Context) {
|
||||
}
|
||||
assert.NoError(t, repo.Repository.LoadOwner(ctx))
|
||||
var err error
|
||||
repo.GitRepo, err = gitrepo.OpenRepository(ctx, repo.Repository)
|
||||
repo.GitRepo, err = gitrepo.OpenRepository(repo.Repository)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestGetActionWorkflow_FallbackRef(t *testing.T) {
|
||||
|
||||
repoDir := buildWorkflowTestRepo(t)
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx, repoDir)
|
||||
gitRepo, err := git.OpenRepository(repoDir)
|
||||
require.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
|
||||
@@ -554,7 +554,7 @@ func getActionWorkflowEntry(ctx context.Context, repo *repo_model.Repository, gi
|
||||
createdAt := commit.Author.When
|
||||
updatedAt := commit.Author.When
|
||||
|
||||
content, err := actions.GetContentFromEntry(gitRepo, entry)
|
||||
content, err := actions.GetContentFromEntry(ctx, gitRepo, entry)
|
||||
name := entry.Name()
|
||||
if err == nil {
|
||||
workflow, err := model.ReadWorkflow(bytes.NewReader(content))
|
||||
@@ -584,7 +584,7 @@ func getActionWorkflowEntry(ctx context.Context, repo *repo_model.Repository, gi
|
||||
}
|
||||
|
||||
func ListActionWorkflows(ctx context.Context, gitrepo *git.Repository, repo *repo_model.Repository) ([]*api.ActionWorkflow, error) {
|
||||
defaultBranchCommit, err := gitrepo.GetBranchCommit(repo.DefaultBranch)
|
||||
defaultBranchCommit, err := gitrepo.GetBranchCommit(ctx, repo.DefaultBranch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -603,7 +603,7 @@ func ListActionWorkflows(ctx context.Context, gitrepo *git.Repository, repo *rep
|
||||
}
|
||||
|
||||
func GetActionWorkflow(ctx context.Context, gitRepo *git.Repository, repo *repo_model.Repository, workflowID string) (*api.ActionWorkflow, error) {
|
||||
defaultBranchCommit, err := gitRepo.GetBranchCommit(repo.DefaultBranch)
|
||||
defaultBranchCommit, err := gitRepo.GetBranchCommit(ctx, repo.DefaultBranch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -616,11 +616,11 @@ func GetActionWorkflowByRef(ctx context.Context, gitrepo *git.Repository, repo *
|
||||
return nil, util.NewNotExistErrorf("workflow %q not found", workflowID)
|
||||
}
|
||||
|
||||
refCommitID, err := gitrepo.GetRefCommitID(ref.String())
|
||||
refCommitID, err := gitrepo.GetRefCommitID(ctx, ref.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
refCommit, err := gitrepo.GetCommit(refCommitID)
|
||||
refCommit, err := gitrepo.GetCommit(ctx, refCommitID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -645,7 +645,7 @@ func getActionWorkflowFromCommit(ctx context.Context, repo *repo_model.Repositor
|
||||
|
||||
// GetScopedActionWorkflow resolves a scoped workflow definition (under SCOPED_WORKFLOW_DIRS) from the source repo at commitSHA.
|
||||
func GetScopedActionWorkflow(ctx context.Context, sourceGitRepo *git.Repository, sourceRepo *repo_model.Repository, workflowID, commitSHA string) (*api.ActionWorkflow, error) {
|
||||
commit, err := sourceGitRepo.GetCommit(commitSHA)
|
||||
commit, err := sourceGitRepo.GetCommit(ctx, commitSHA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -680,7 +680,7 @@ func ResolveActionWorkflowForRun(ctx context.Context, repo *repo_model.Repositor
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sourceGitRepo, err := gitrepo.OpenRepository(ctx, sourceRepo)
|
||||
sourceGitRepo, err := gitrepo.OpenRepository(sourceRepo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -688,7 +688,7 @@ func ResolveActionWorkflowForRun(ctx context.Context, repo *repo_model.Repositor
|
||||
return GetScopedActionWorkflow(ctx, sourceGitRepo, sourceRepo, run.WorkflowID, run.WorkflowCommitSHA)
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+11
-11
@@ -145,7 +145,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
|
||||
apiPullRequest.Closed = pr.Issue.ClosedUnix.AsTimePtr()
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
|
||||
gitRepo, err := gitrepo.OpenRepository(pr.BaseRepo)
|
||||
if err != nil {
|
||||
log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RelativePath(), err)
|
||||
return nil
|
||||
@@ -159,7 +159,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
|
||||
}
|
||||
|
||||
if exist {
|
||||
baseCommit, err = gitRepo.GetBranchCommit(pr.BaseBranch)
|
||||
baseCommit, err = gitRepo.GetBranchCommit(ctx, pr.BaseBranch)
|
||||
if err != nil && !git.IsErrNotExist(err) {
|
||||
log.Error("GetCommit[%s]: %v", baseBranch, err)
|
||||
return nil
|
||||
@@ -171,7 +171,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
|
||||
}
|
||||
|
||||
if pr.Flow == issues_model.PullRequestFlowAGit {
|
||||
apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
log.Error("GetRefCommitID[%s]: %v", pr.GetGitHeadRefName(), err)
|
||||
return nil
|
||||
@@ -191,7 +191,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
|
||||
apiPullRequest.Head.RepoID = pr.HeadRepo.ID
|
||||
apiPullRequest.Head.Repository = ToRepo(ctx, pr.HeadRepo, p)
|
||||
|
||||
headGitRepo, err := gitrepo.OpenRepository(ctx, pr.HeadRepo)
|
||||
headGitRepo, err := gitrepo.OpenRepository(pr.HeadRepo)
|
||||
if err != nil {
|
||||
log.Error("OpenRepository[%s]: %v", pr.HeadRepo.RelativePath(), err)
|
||||
return nil
|
||||
@@ -211,7 +211,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
|
||||
)
|
||||
|
||||
if !exist {
|
||||
headCommitID, err := headGitRepo.GetRefCommitID(apiPullRequest.Head.Ref)
|
||||
headCommitID, err := headGitRepo.GetRefCommitID(ctx, apiPullRequest.Head.Ref)
|
||||
if err != nil && !git.IsErrNotExist(err) {
|
||||
log.Error("GetCommit[%s]: %v", pr.HeadBranch, err)
|
||||
return nil
|
||||
@@ -221,7 +221,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
|
||||
endCommitID = headCommitID
|
||||
}
|
||||
} else {
|
||||
commit, err := headGitRepo.GetBranchCommit(pr.HeadBranch)
|
||||
commit, err := headGitRepo.GetBranchCommit(ctx, pr.HeadBranch)
|
||||
if err != nil && !git.IsErrNotExist(err) {
|
||||
log.Error("GetCommit[%s]: %v", headBranch, err)
|
||||
return nil
|
||||
@@ -247,13 +247,13 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
|
||||
}
|
||||
|
||||
if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 {
|
||||
baseGitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
|
||||
baseGitRepo, err := gitrepo.OpenRepository(pr.BaseRepo)
|
||||
if err != nil {
|
||||
log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RelativePath(), err)
|
||||
return nil
|
||||
}
|
||||
defer baseGitRepo.Close()
|
||||
refs, err := baseGitRepo.GetRefsFiltered(apiPullRequest.Head.Ref)
|
||||
refs, err := baseGitRepo.GetRefsFiltered(ctx, apiPullRequest.Head.Ref)
|
||||
if err != nil {
|
||||
log.Error("GetRefsFiltered[%s]: %v", apiPullRequest.Head.Ref, err)
|
||||
return nil
|
||||
@@ -329,7 +329,7 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
|
||||
return nil, err
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, baseRepo)
|
||||
gitRepo, err := gitrepo.OpenRepository(baseRepo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -452,13 +452,13 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
|
||||
if pr.Flow == issues_model.PullRequestFlowAGit {
|
||||
apiPullRequest.Head.Name = ""
|
||||
}
|
||||
apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
log.Error("GetRefCommitID[%s]: %v", pr.GetGitHeadRefName(), err)
|
||||
}
|
||||
|
||||
if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 {
|
||||
refs, err := gitRepo.GetRefsFiltered(apiPullRequest.Head.Ref)
|
||||
refs, err := gitRepo.GetRefsFiltered(ctx, apiPullRequest.Head.Ref)
|
||||
if err != nil {
|
||||
log.Error("GetRefsFiltered[%s]: %v", apiPullRequest.Head.Ref, err)
|
||||
return nil, err
|
||||
|
||||
@@ -72,7 +72,7 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
|
||||
// if they are not the same repository, then we need to fetch the base commit into the head repository
|
||||
// because we will use headGitRepo in the following code
|
||||
if baseRepo.ID != headRepo.ID {
|
||||
exist := headGitRepo.IsReferenceExist(compareInfo.BaseCommitID)
|
||||
exist := headGitRepo.IsReferenceExist(ctx, compareInfo.BaseCommitID)
|
||||
if !exist {
|
||||
if err := gitrepo.FetchRemoteCommit(ctx, headRepo, baseRepo, compareInfo.BaseCommitID); err != nil {
|
||||
return compareInfo, fmt.Errorf("FetchRemoteCommit: %w", err)
|
||||
@@ -108,6 +108,6 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
|
||||
// Count number of changed files.
|
||||
// TODO: This probably should be removed as we need to use shortstat elsewhere
|
||||
// Now there is git diff --shortstat but this appears to be slower than simply iterating with --nameonly
|
||||
compareInfo.NumFiles, err = headGitRepo.GetDiffNumChangedFiles(compareInfo.BaseCommitID, compareInfo.HeadCommitID, directComparison)
|
||||
compareInfo.NumFiles, err = headGitRepo.GetDiffNumChangedFiles(ctx, compareInfo.BaseCommitID, compareInfo.HeadCommitID, directComparison)
|
||||
return compareInfo, err
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func GetDiffTree(ctx context.Context, gitRepo *git.Repository, useMergeBase bool
|
||||
}
|
||||
|
||||
func runGitDiffTree(ctx context.Context, gitRepo *git.Repository, useMergeBase bool, baseSha, headSha string) ([]*DiffTreeRecord, error) {
|
||||
useMergeBase, baseCommitID, headCommitID, err := validateGitDiffTreeArguments(gitRepo, useMergeBase, baseSha, headSha)
|
||||
useMergeBase, baseCommitID, headCommitID, err := validateGitDiffTreeArguments(ctx, gitRepo, useMergeBase, baseSha, headSha)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -73,14 +73,14 @@ func runGitDiffTree(ctx context.Context, gitRepo *git.Repository, useMergeBase b
|
||||
return parseGitDiffTree(strings.NewReader(stdout))
|
||||
}
|
||||
|
||||
func validateGitDiffTreeArguments(gitRepo *git.Repository, useMergeBase bool, baseSha, headSha string) (shouldUseMergeBase bool, resolvedBaseSha, resolvedHeadSha string, err error) {
|
||||
func validateGitDiffTreeArguments(ctx context.Context, gitRepo *git.Repository, useMergeBase bool, baseSha, headSha string) (shouldUseMergeBase bool, resolvedBaseSha, resolvedHeadSha string, err error) {
|
||||
// if the head is empty its an error
|
||||
if headSha == "" {
|
||||
return false, "", "", errors.New("headSha is empty")
|
||||
}
|
||||
|
||||
// if the head commit doesn't exist its and error
|
||||
headCommit, err := gitRepo.GetCommit(headSha)
|
||||
headCommit, err := gitRepo.GetCommit(ctx, headSha)
|
||||
if err != nil {
|
||||
return false, "", "", fmt.Errorf("failed to get commit headSha: %v", err)
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func validateGitDiffTreeArguments(gitRepo *git.Repository, useMergeBase bool, ba
|
||||
// if the headCommit has no parent we should use an empty commit
|
||||
// this can happen when we are generating a diff against an orphaned commit
|
||||
if headCommit.ParentCount() == 0 {
|
||||
objectFormat, err := gitRepo.GetObjectFormat()
|
||||
objectFormat, err := gitRepo.GetObjectFormat(ctx)
|
||||
if err != nil {
|
||||
return false, "", "", err
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func validateGitDiffTreeArguments(gitRepo *git.Repository, useMergeBase bool, ba
|
||||
return false, objectFormat.EmptyTree().String(), headCommitID, nil
|
||||
}
|
||||
|
||||
baseCommit, err := headCommit.Parent(gitRepo, 0)
|
||||
baseCommit, err := headCommit.Parent(ctx, gitRepo, 0)
|
||||
if err != nil {
|
||||
return false, "", "", fmt.Errorf("baseSha is '', attempted to use parent of commit %s, got error: %v", headCommit.ID.String(), err)
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func validateGitDiffTreeArguments(gitRepo *git.Repository, useMergeBase bool, ba
|
||||
}
|
||||
|
||||
// try and get the base commit
|
||||
baseCommit, err := gitRepo.GetCommit(baseSha)
|
||||
baseCommit, err := gitRepo.GetCommit(ctx, baseSha)
|
||||
// propagate the error if we couldn't get the base commit
|
||||
if err != nil {
|
||||
return useMergeBase, "", "", fmt.Errorf("failed to get base commit %s: %v", baseSha, err)
|
||||
|
||||
@@ -205,7 +205,7 @@ func TestGitDiffTree(t *testing.T) {
|
||||
|
||||
for _, tt := range test {
|
||||
t.Run(tt.Name, func(t *testing.T) {
|
||||
gitRepo, err := git.OpenRepository(t.Context(), tt.RepoPath)
|
||||
gitRepo, err := git.OpenRepository(tt.RepoPath)
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
@@ -414,7 +414,7 @@ func TestGitDiffTreeErrors(t *testing.T) {
|
||||
|
||||
for _, tt := range test {
|
||||
t.Run(tt.Name, func(t *testing.T) {
|
||||
gitRepo, err := git.OpenRepository(t.Context(), tt.RepoPath)
|
||||
gitRepo, err := git.OpenRepository(tt.RepoPath)
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
|
||||
+12
-12
@@ -583,7 +583,7 @@ func getCommitFileLineCountAndLimitedContent(ctx context.Context, gitRepo *git.R
|
||||
return 0, nil
|
||||
}
|
||||
w := &limitByteWriter{limit: MaxFullFileHighlightSizeLimit + 1}
|
||||
lineCount, err = blob.GetBlobLineCount(w)
|
||||
lineCount, err = blob.GetBlobLineCount(ctx, w)
|
||||
if err != nil {
|
||||
return 0, nil
|
||||
}
|
||||
@@ -1248,7 +1248,7 @@ type DiffOptions struct {
|
||||
DirectComparison bool
|
||||
}
|
||||
|
||||
func guessBeforeCommitForDiff(gitRepo *git.Repository, beforeCommitID string, afterCommit *git.Commit) (actualBeforeCommit *git.Commit, actualBeforeCommitID git.ObjectID, err error) {
|
||||
func guessBeforeCommitForDiff(ctx context.Context, gitRepo *git.Repository, beforeCommitID string, afterCommit *git.Commit) (actualBeforeCommit *git.Commit, actualBeforeCommitID git.ObjectID, err error) {
|
||||
commitObjectFormat := afterCommit.ID.Type()
|
||||
isBeforeCommitIDEmpty := beforeCommitID == "" || beforeCommitID == commitObjectFormat.EmptyObjectID().String()
|
||||
|
||||
@@ -1256,9 +1256,9 @@ func guessBeforeCommitForDiff(gitRepo *git.Repository, beforeCommitID string, af
|
||||
actualBeforeCommitID = commitObjectFormat.EmptyTree()
|
||||
} else {
|
||||
if isBeforeCommitIDEmpty {
|
||||
actualBeforeCommit, err = afterCommit.Parent(gitRepo, 0)
|
||||
actualBeforeCommit, err = afterCommit.Parent(ctx, gitRepo, 0)
|
||||
} else {
|
||||
actualBeforeCommit, err = gitRepo.GetCommit(beforeCommitID)
|
||||
actualBeforeCommit, err = gitRepo.GetCommit(ctx, beforeCommitID)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -1275,12 +1275,12 @@ func guessBeforeCommitForDiff(gitRepo *git.Repository, beforeCommitID string, af
|
||||
func getDiffBasic(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, files ...string) (_ *Diff, beforeCommit, afterCommit *git.Commit, err error) {
|
||||
repoPath := gitRepo.Path
|
||||
|
||||
afterCommit, err = gitRepo.GetCommit(opts.AfterCommitID)
|
||||
afterCommit, err = gitRepo.GetCommit(ctx, opts.AfterCommitID)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
beforeCommit, beforeCommitID, err := guessBeforeCommitForDiff(gitRepo, opts.BeforeCommitID, afterCommit)
|
||||
beforeCommit, beforeCommitID, err := guessBeforeCommitForDiff(ctx, gitRepo, opts.BeforeCommitID, afterCommit)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
@@ -1340,7 +1340,7 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit
|
||||
|
||||
startTime := time.Now()
|
||||
|
||||
checker, err := attribute.NewBatchChecker(gitRepo, opts.AfterCommitID, []string{attribute.LinguistVendored, attribute.LinguistGenerated, attribute.LinguistLanguage, attribute.GitlabLanguage, attribute.Diff})
|
||||
checker, err := attribute.NewBatchChecker(ctx, gitRepo, opts.AfterCommitID, []string{attribute.LinguistVendored, attribute.LinguistGenerated, attribute.LinguistLanguage, attribute.GitlabLanguage, attribute.Diff})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1440,12 +1440,12 @@ type DiffShortStat struct {
|
||||
}
|
||||
|
||||
func GetDiffShortStat(ctx context.Context, repoStorage gitrepo.Repository, gitRepo *git.Repository, beforeCommitID, afterCommitID string) (*DiffShortStat, error) {
|
||||
afterCommit, err := gitRepo.GetCommit(afterCommitID)
|
||||
afterCommit, err := gitRepo.GetCommit(ctx, afterCommitID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, actualBeforeCommitID, err := guessBeforeCommitForDiff(gitRepo, beforeCommitID, afterCommit)
|
||||
_, actualBeforeCommitID, err := guessBeforeCommitForDiff(ctx, gitRepo, beforeCommitID, afterCommit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1474,7 +1474,7 @@ func SyncUserSpecificDiff(ctx context.Context, userID int64, pull *issues_model.
|
||||
latestCommit = pull.HeadBranch // opts.AfterCommitID is preferred because it handles PRs from forks correctly and the branch name doesn't
|
||||
}
|
||||
|
||||
changedFiles, errIgnored := gitRepo.GetFilesChangedBetween(review.CommitSHA, latestCommit)
|
||||
changedFiles, errIgnored := gitRepo.GetFilesChangedBetween(ctx, review.CommitSHA, latestCommit)
|
||||
// There are way too many possible errors.
|
||||
// Examples are various git errors such as the commit the review was based on was gc'ed and hence doesn't exist anymore as well as unrecoverable errors where we should serve a 500 response
|
||||
// Due to the current architecture and physical limitation of needing to compare explicit error messages, we can only choose one approach without the code getting ugly
|
||||
@@ -1549,7 +1549,7 @@ func CommentAsDiff(ctx context.Context, c *issues_model.Comment) (*Diff, error)
|
||||
|
||||
// GeneratePatchForUnchangedLine creates a patch showing code context for an unchanged line
|
||||
func GeneratePatchForUnchangedLine(ctx context.Context, gitRepo *git.Repository, commitID, treePath string, line int64, contextLines int) (string, error) {
|
||||
commit, err := gitRepo.GetCommit(commitID)
|
||||
commit, err := gitRepo.GetCommit(ctx, commitID)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("GetCommit: %w", err)
|
||||
}
|
||||
@@ -1560,7 +1560,7 @@ func GeneratePatchForUnchangedLine(ctx context.Context, gitRepo *git.Repository,
|
||||
}
|
||||
|
||||
blob := entry.Blob(gitRepo)
|
||||
dataRc, err := blob.DataAsync()
|
||||
dataRc, err := blob.DataAsync(ctx)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("DataAsync: %w", err)
|
||||
}
|
||||
|
||||
@@ -601,7 +601,7 @@ func TestDiffLine_GetCommentSide(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
|
||||
gitRepo, err := git.OpenRepository(t.Context(), "../../modules/git/tests/repos/repo5_pulls")
|
||||
gitRepo, err := git.OpenRepository("../../modules/git/tests/repos/repo5_pulls")
|
||||
require.NoError(t, err)
|
||||
|
||||
defer gitRepo.Close()
|
||||
@@ -1188,7 +1188,7 @@ D test2.txt
|
||||
D test10.txt`
|
||||
require.NoError(t, gitcmd.NewCommand("fast-import").WithDir(pull.BaseRepo.RepoPath()).WithStdinBytes([]byte(stdin)).Run(t.Context()))
|
||||
|
||||
gitRepo, err := git.OpenRepository(t.Context(), pull.BaseRepo.RepoPath())
|
||||
gitRepo, err := git.OpenRepository(pull.BaseRepo.RepoPath())
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ func LoadCommentPushCommits(ctx context.Context, c *issues_model.Comment) error
|
||||
}
|
||||
defer closer.Close()
|
||||
|
||||
c.Commits, err = git_service.ConvertFromGitCommit(ctx, gitRepo.GetCommitsFromIDs(data.CommitIDs), c.Issue.Repo, "") // no current ref sub path for PR commit list
|
||||
c.Commits, err = git_service.ConvertFromGitCommit(ctx, gitRepo.GetCommitsFromIDs(ctx, data.CommitIDs), c.Issue.Repo, "") // no current ref sub path for PR commit list
|
||||
if err != nil {
|
||||
log.Debug("ConvertFromGitCommit: %v", err) // no need to show 500 error to end user when the commit does not exist
|
||||
} else {
|
||||
|
||||
@@ -55,13 +55,13 @@ func PullRequestCodeOwnersReview(ctx context.Context, pr *issues_model.PullReque
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
repo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
|
||||
repo, err := gitrepo.OpenRepository(pr.BaseRepo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer repo.Close()
|
||||
|
||||
commit, err := repo.GetBranchCommit(pr.BaseRepo.DefaultBranch)
|
||||
commit, err := repo.GetBranchCommit(ctx, pr.BaseRepo.DefaultBranch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -69,7 +69,7 @@ func PullRequestCodeOwnersReview(ctx context.Context, pr *issues_model.PullReque
|
||||
var data string
|
||||
for _, file := range codeOwnerFiles {
|
||||
if blob, err := commit.GetBlobByPath(ctx, repo, file); err == nil {
|
||||
data, err = blob.GetBlobContent(setting.UI.MaxDisplayFileSize)
|
||||
data, err = blob.GetBlobContent(ctx, setting.UI.MaxDisplayFileSize)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func PullRequestCodeOwnersReview(ctx context.Context, pr *issues_model.PullReque
|
||||
}
|
||||
// https://github.com/go-gitea/gitea/issues/29763, we need to get the files changed
|
||||
// between the merge base and the head commit but not the base branch and the head commit
|
||||
changedFiles, err := repo.GetFilesChangedBetween(mergeBase, pr.GetGitHeadRefName())
|
||||
changedFiles, err := repo.GetFilesChangedBetween(ctx, mergeBase, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func GetTemplateConfig(ctx context.Context, gitRepo *git.Repository, path string
|
||||
return GetDefaultTemplateConfig(), err
|
||||
}
|
||||
|
||||
reader, err := treeEntry.Blob(gitRepo).DataAsync()
|
||||
reader, err := treeEntry.Blob(gitRepo).DataAsync(ctx)
|
||||
if err != nil {
|
||||
log.Debug("DataAsync: %v", err)
|
||||
return GetDefaultTemplateConfig(), nil
|
||||
@@ -120,7 +120,7 @@ func ParseTemplatesFromDefaultBranch(ctx context.Context, repo *repo.Repository,
|
||||
return ret
|
||||
}
|
||||
|
||||
commit, err := gitRepo.GetBranchCommit(repo.DefaultBranch)
|
||||
commit, err := gitRepo.GetBranchCommit(ctx, repo.DefaultBranch)
|
||||
if err != nil {
|
||||
return ret
|
||||
}
|
||||
@@ -141,7 +141,7 @@ func ParseTemplatesFromDefaultBranch(ctx context.Context, repo *repo.Repository,
|
||||
continue
|
||||
}
|
||||
fullName := path.Join(dirName, entry.Name())
|
||||
if it, err := template.UnmarshalFromEntry(gitRepo, entry, dirName); err != nil {
|
||||
if it, err := template.UnmarshalFromEntry(ctx, gitRepo, entry, dirName); err != nil {
|
||||
ret.TemplateErrors[fullName] = err
|
||||
} else {
|
||||
if !strings.HasPrefix(it.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/<ref>
|
||||
@@ -161,7 +161,7 @@ func GetTemplateConfigFromDefaultBranch(ctx context.Context, repo *repo.Reposito
|
||||
return GetDefaultTemplateConfig(), nil
|
||||
}
|
||||
|
||||
commit, err := gitRepo.GetBranchCommit(repo.DefaultBranch)
|
||||
commit, err := gitRepo.GetBranchCommit(ctx, repo.DefaultBranch)
|
||||
if err != nil {
|
||||
return GetDefaultTemplateConfig(), err
|
||||
}
|
||||
|
||||
@@ -50,13 +50,13 @@ func renderRepoFileCodePreview(ctx context.Context, opts markup.RenderCodePrevie
|
||||
return "", util.ErrPermissionDenied
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, dbRepo)
|
||||
gitRepo, err := gitrepo.OpenRepository(dbRepo)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
commit, err := gitRepo.GetCommit(opts.CommitID)
|
||||
commit, err := gitRepo.GetCommit(ctx, opts.CommitID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -67,11 +67,11 @@ func renderRepoFileCodePreview(ctx context.Context, opts markup.RenderCodePrevie
|
||||
return "", err
|
||||
}
|
||||
|
||||
if blob.Size() > setting.UI.MaxDisplayFileSize {
|
||||
if blob.Size(ctx) > setting.UI.MaxDisplayFileSize {
|
||||
return "", errors.New("file is too large")
|
||||
}
|
||||
|
||||
dataRc, err := blob.DataAsync()
|
||||
dataRc, err := blob.DataAsync(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ func (g *RepositoryDumper) CreateRepo(ctx context.Context, repo *base.Repository
|
||||
}
|
||||
}
|
||||
|
||||
g.gitRepo, err = git.OpenRepository(ctx, g.gitPath())
|
||||
g.gitRepo, err = git.OpenRepository(g.gitPath())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -519,7 +519,7 @@ func (g *RepositoryDumper) handlePullRequest(ctx context.Context, pr *base.PullR
|
||||
remote = "head-pr-" + strconv.FormatInt(pr.Number, 10)
|
||||
}
|
||||
// ... now add the remote
|
||||
err := g.gitRepo.AddRemote(remote, pr.Head.CloneURL, true)
|
||||
err := g.gitRepo.AddRemote(ctx, remote, pr.Head.CloneURL, true)
|
||||
if err != nil {
|
||||
log.Error("PR #%d in %s/%s AddRemote[%s] failed: %v", pr.Number, g.repoOwner, g.repoName, remote, err)
|
||||
} else {
|
||||
@@ -546,10 +546,10 @@ func (g *RepositoryDumper) handlePullRequest(ctx context.Context, pr *base.PullR
|
||||
localRef = git.SanitizeRefPattern(oldHeadOwnerName + "/" + pr.Head.Ref)
|
||||
|
||||
// ... Now we must assert that this does not exist
|
||||
if g.gitRepo.IsBranchExist(localRef) {
|
||||
if g.gitRepo.IsBranchExist(ctx, localRef) {
|
||||
localRef = "head-pr-" + strconv.FormatInt(pr.Number, 10) + "/" + localRef
|
||||
i := 0
|
||||
for g.gitRepo.IsBranchExist(localRef) {
|
||||
for g.gitRepo.IsBranchExist(ctx, localRef) {
|
||||
if i > 5 {
|
||||
// ... We tried, we really tried but this is just a seriously unfriendly repo
|
||||
return fmt.Errorf("unable to create unique local reference from %s", pr.Head.Ref)
|
||||
@@ -581,7 +581,7 @@ func (g *RepositoryDumper) handlePullRequest(ctx context.Context, pr *base.PullR
|
||||
|
||||
// 5. Now if pr.Head.SHA == "" we should recover this to the head of this branch
|
||||
if pr.Head.SHA == "" {
|
||||
headSha, err := g.gitRepo.GetBranchCommitID(localRef)
|
||||
headSha, err := g.gitRepo.GetBranchCommitID(ctx, localRef)
|
||||
if err != nil {
|
||||
log.Error("unable to get head SHA of local head for PR #%d from %s in %s/%s. Error: %v", pr.Number, pr.Head.Ref, g.repoOwner, g.repoName, err)
|
||||
return nil
|
||||
|
||||
@@ -139,13 +139,13 @@ func (g *GiteaLocalUploader) CreateRepo(ctx context.Context, repo *base.Reposito
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
g.gitRepo, err = gitrepo.OpenRepository(ctx, g.repo)
|
||||
g.gitRepo, err = gitrepo.OpenRepository(g.repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// detect object format from git repository and update to database
|
||||
objectFormat, err := g.gitRepo.GetObjectFormat()
|
||||
objectFormat, err := g.gitRepo.GetObjectFormat(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -298,7 +298,7 @@ func (g *GiteaLocalUploader) CreateReleases(ctx context.Context, releases ...*ba
|
||||
|
||||
// calc NumCommits if possible
|
||||
if rel.TagName != "" {
|
||||
commit, err := g.gitRepo.GetTagCommit(rel.TagName)
|
||||
commit, err := g.gitRepo.GetTagCommit(ctx, rel.TagName)
|
||||
if !git.IsErrNotExist(err) {
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetTagCommit[%v]: %w", rel.TagName, err)
|
||||
@@ -632,7 +632,7 @@ func (g *GiteaLocalUploader) updateGitForPullRequest(ctx context.Context, pr *ba
|
||||
remote = "head-pr-" + strconv.FormatInt(pr.Number, 10)
|
||||
}
|
||||
// ... now add the remote
|
||||
err := g.gitRepo.AddRemote(remote, pr.Head.CloneURL, true)
|
||||
err := g.gitRepo.AddRemote(ctx, remote, pr.Head.CloneURL, true)
|
||||
if err != nil {
|
||||
log.Error("PR #%d in %s/%s AddRemote[%s] failed: %v", pr.Number, g.repoOwner, g.repoName, remote, err)
|
||||
} else {
|
||||
@@ -651,10 +651,10 @@ func (g *GiteaLocalUploader) updateGitForPullRequest(ctx context.Context, pr *ba
|
||||
localRef = git.SanitizeRefPattern(pr.Head.OwnerName + "/" + pr.Head.Ref)
|
||||
|
||||
// ... Now we must assert that this does not exist
|
||||
if g.gitRepo.IsBranchExist(localRef) {
|
||||
if g.gitRepo.IsBranchExist(ctx, localRef) {
|
||||
localRef = "head-pr-" + strconv.FormatInt(pr.Number, 10) + "/" + localRef
|
||||
i := 0
|
||||
for g.gitRepo.IsBranchExist(localRef) {
|
||||
for g.gitRepo.IsBranchExist(ctx, localRef) {
|
||||
if i > 5 {
|
||||
// ... We tried, we really tried but this is just a seriously unfriendly repo
|
||||
return head, nil
|
||||
@@ -681,7 +681,7 @@ func (g *GiteaLocalUploader) updateGitForPullRequest(ctx context.Context, pr *ba
|
||||
|
||||
// 5. Now if pr.Head.SHA == "" we should recover this to the head of this branch
|
||||
if pr.Head.SHA == "" {
|
||||
headSha, err := g.gitRepo.GetBranchCommitID(localRef)
|
||||
headSha, err := g.gitRepo.GetBranchCommitID(ctx, localRef)
|
||||
if err != nil {
|
||||
log.Error("unable to get head SHA of local head for PR #%d from %s in %s/%s. Error: %v", pr.Number, pr.Head.Ref, g.repoOwner, g.repoName, err)
|
||||
return head, nil
|
||||
@@ -886,7 +886,7 @@ func (g *GiteaLocalUploader) CreateReviews(ctx context.Context, reviews ...*base
|
||||
continue
|
||||
}
|
||||
|
||||
headCommitID, err := g.gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
headCommitID, err := g.gitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
log.Warn("PR #%d GetRefCommitID[%s] in %s/%s: %v, all review comments will be ignored", pr.Index, pr.GetGitHeadRefName(), g.repoOwner, g.repoName, err)
|
||||
continue
|
||||
@@ -903,7 +903,7 @@ func (g *GiteaLocalUploader) CreateReviews(ctx context.Context, reviews ...*base
|
||||
// SECURITY: The TreePath must be cleaned! use relative path
|
||||
comment.TreePath = util.PathJoinRel(comment.TreePath)
|
||||
|
||||
patch, _ := git.GetFileDiffCutAroundLine(
|
||||
patch, _ := git.GetFileDiffCutAroundLine(ctx,
|
||||
g.gitRepo, pr.MergeBase, headCommitID, comment.TreePath,
|
||||
int64((&issues_model.Comment{Line: int64(line + comment.Position - 1)}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines,
|
||||
)
|
||||
|
||||
@@ -176,7 +176,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*repo_module.SyncResu
|
||||
log.Error("SyncMirrors [repo: %-v]: %v", m.Repo, err)
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, m.Repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(m.Repo)
|
||||
if err != nil {
|
||||
log.Error("SyncMirrors [repo: %-v]: failed to OpenRepository: %v", m.Repo, err)
|
||||
return nil, false
|
||||
@@ -325,7 +325,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, m.Repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(m.Repo)
|
||||
if err != nil {
|
||||
log.Error("SyncMirrors [repo: %-v]: unable to OpenRepository: %v", m.Repo, err)
|
||||
return false
|
||||
@@ -348,7 +348,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
||||
|
||||
// Create reference
|
||||
if result.OldCommitID == "" {
|
||||
commitID, err := gitRepo.GetRefCommitID(result.RefName.String())
|
||||
commitID, err := gitRepo.GetRefCommitID(ctx, result.RefName.String())
|
||||
if err != nil {
|
||||
log.Error("SyncMirrors [repo: %-v]: unable to GetRefCommitID [ref_name: %s]: %v", m.Repo, result.RefName, err)
|
||||
continue
|
||||
@@ -370,14 +370,14 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
||||
}
|
||||
|
||||
oldCommitID, newCommitID := result.OldCommitID, result.NewCommitID
|
||||
commits, err := gitRepo.CommitsBetween(newCommitID, oldCommitID, setting.UI.FeedMaxCommitNum)
|
||||
commits, err := gitRepo.CommitsBetween(ctx, newCommitID, oldCommitID, setting.UI.FeedMaxCommitNum)
|
||||
if err != nil {
|
||||
log.Error("SyncMirrors [repo: %-v]: unable to get CommitsBetween [new_commit_id: %s, old_commit_id: %s]: %v", m.Repo, newCommitID, oldCommitID, err)
|
||||
continue
|
||||
}
|
||||
theCommits := repo_module.GitToPushCommits(commits)
|
||||
|
||||
newCommit, err := gitRepo.GetCommit(newCommitID.String())
|
||||
newCommit, err := gitRepo.GetCommit(ctx, newCommitID.String())
|
||||
if err != nil {
|
||||
log.Error("SyncMirrors [repo: %-v]: unable to get commit %s: %v", m.Repo, newCommitID, err)
|
||||
continue
|
||||
@@ -394,7 +394,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
||||
}
|
||||
log.Trace("SyncMirrors [repo: %-v]: done notifying updated branches/tags - now updating last commit time", m.Repo)
|
||||
|
||||
isEmpty, err := gitRepo.IsEmpty()
|
||||
isEmpty, err := gitRepo.IsEmpty(ctx)
|
||||
if err != nil {
|
||||
log.Error("SyncMirrors [repo: %-v]: unable to check empty git repo: %v", m.Repo, err)
|
||||
return false
|
||||
|
||||
@@ -137,7 +137,7 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
|
||||
if setting.LFS.StartServer {
|
||||
log.Trace("SyncMirrors [repo: %-v]: syncing LFS objects...", m.Repo)
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, storageRepo)
|
||||
gitRepo, err := gitrepo.OpenRepository(storageRepo)
|
||||
if err != nil {
|
||||
log.Error("OpenRepository: %v", err)
|
||||
return errors.New("Unexpected error")
|
||||
|
||||
@@ -278,7 +278,7 @@ func alterRepositoryContent(ctx context.Context, doer *user_model.User, repo *re
|
||||
return err
|
||||
}
|
||||
|
||||
commit, err := t.GetBranchCommit(repo.DefaultBranch)
|
||||
commit, err := t.GetBranchCommit(ctx, repo.DefaultBranch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ type GenerateReleaseNotesOptions struct {
|
||||
|
||||
// GenerateReleaseNotes builds the Markdown snippet for release notes.
|
||||
func GenerateReleaseNotes(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, opts GenerateReleaseNotesOptions) (string, error) {
|
||||
headCommit, err := resolveHeadCommit(gitRepo, opts.TagName, opts.TagTarget)
|
||||
headCommit, err := resolveHeadCommit(ctx, gitRepo, opts.TagName, opts.TagTarget)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func GenerateReleaseNotes(ctx context.Context, repo *repo_model.Repository, gitR
|
||||
|
||||
var baseCommitID git.RefName
|
||||
if opts.PreviousTag != "" {
|
||||
baseCommit, err := gitRepo.GetCommit(opts.PreviousTag)
|
||||
baseCommit, err := gitRepo.GetCommit(ctx, opts.PreviousTag)
|
||||
if err != nil {
|
||||
return "", util.ErrorWrapTranslatable(util.ErrNotExist, "repo.release.generate_notes_tag_not_found", opts.PreviousTag)
|
||||
}
|
||||
@@ -49,7 +49,7 @@ func GenerateReleaseNotes(ctx context.Context, repo *repo_model.Repository, gitR
|
||||
return "", util.ErrorWrapTranslatable(util.ErrNotExist, "repo.release.generate_notes_tag_not_found", opts.TagName)
|
||||
}
|
||||
|
||||
commits, err := gitRepo.CommitsBetween(headCommit.ID.RefName(), baseCommitID, -1)
|
||||
commits, err := gitRepo.CommitsBetween(ctx, headCommit.ID.RefName(), baseCommitID, -1)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("CommitsBetween: %w", err)
|
||||
}
|
||||
@@ -85,13 +85,13 @@ func repoReleaseIsEmpty(ctx context.Context, repoID int64) (bool, error) {
|
||||
return count == 0, nil
|
||||
}
|
||||
|
||||
func resolveHeadCommit(gitRepo *git.Repository, tagName, tagTarget string) (*git.Commit, error) {
|
||||
func resolveHeadCommit(ctx context.Context, gitRepo *git.Repository, tagName, tagTarget string) (*git.Commit, error) {
|
||||
ref := tagName
|
||||
if !gitRepo.IsTagExist(tagName) {
|
||||
if !gitRepo.IsTagExist(ctx, tagName) {
|
||||
ref = tagTarget
|
||||
}
|
||||
|
||||
commit, err := gitRepo.GetCommit(ref)
|
||||
commit, err := gitRepo.GetCommit(ctx, ref)
|
||||
if err != nil {
|
||||
return nil, util.ErrorWrapTranslatable(util.ErrNotExist, "repo.release.generate_notes_target_not_found", ref)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestGenerateReleaseNotes(t *testing.T) {
|
||||
|
||||
t.Run("ChangeLogsWithPRs", func(t *testing.T) {
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { gitRepo.Close() })
|
||||
|
||||
@@ -52,7 +52,7 @@ func TestGenerateReleaseNotes(t *testing.T) {
|
||||
|
||||
t.Run("NoPreviousTag", func(t *testing.T) {
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 16})
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { gitRepo.Close() })
|
||||
|
||||
@@ -83,7 +83,7 @@ func TestGenerateReleaseNotes(t *testing.T) {
|
||||
|
||||
t.Run("EmptyPreviousTagWithExistingTags", func(t *testing.T) {
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { gitRepo.Close() })
|
||||
|
||||
|
||||
+12
-12
@@ -103,13 +103,13 @@ func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Rel
|
||||
}
|
||||
}
|
||||
|
||||
commit, err := gitRepo.GetCommit(rel.Target)
|
||||
commit, err := gitRepo.GetCommit(ctx, rel.Target)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if len(msg) > 0 {
|
||||
if err = gitRepo.CreateAnnotatedTag(rel.TagName, msg, commit.ID.String()); err != nil {
|
||||
if err = gitRepo.CreateAnnotatedTag(ctx, rel.TagName, msg, commit.ID.String()); err != nil {
|
||||
if strings.Contains(err.Error(), "is not a valid tag name") {
|
||||
return false, ErrInvalidTagName{
|
||||
TagName: rel.TagName,
|
||||
@@ -117,7 +117,7 @@ func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Rel
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
} else if err = gitRepo.CreateTag(rel.TagName, commit.ID.String()); err != nil {
|
||||
} else if err = gitRepo.CreateTag(ctx, rel.TagName, commit.ID.String()); err != nil {
|
||||
if strings.Contains(err.Error(), "is not a valid tag name") {
|
||||
return false, ErrInvalidTagName{
|
||||
TagName: rel.TagName,
|
||||
@@ -144,7 +144,7 @@ func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Rel
|
||||
notify_service.CreateRef(ctx, rel.Publisher, rel.Repo, refFullName, commit.ID.String())
|
||||
rel.CreatedUnix = timeutil.TimeStampNow()
|
||||
}
|
||||
commit, err := gitRepo.GetTagCommit(rel.TagName)
|
||||
commit, err := gitRepo.GetTagCommit(ctx, rel.TagName)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("GetTagCommit: %w", err)
|
||||
}
|
||||
@@ -168,8 +168,8 @@ func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Rel
|
||||
}
|
||||
|
||||
// CreateRelease creates a new release of repository.
|
||||
func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentUUIDs []string, msg string) error {
|
||||
has, err := repo_model.IsReleaseExist(gitRepo.Ctx, rel.RepoID, rel.TagName)
|
||||
func CreateRelease(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Release, attachmentUUIDs []string, msg string) error {
|
||||
has, err := repo_model.IsReleaseExist(ctx, rel.RepoID, rel.TagName)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if has {
|
||||
@@ -178,22 +178,22 @@ func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentU
|
||||
}
|
||||
}
|
||||
|
||||
if _, err = createTag(gitRepo.Ctx, gitRepo, rel, msg); err != nil {
|
||||
if _, err = createTag(ctx, gitRepo, rel, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rel.Title = util.EllipsisDisplayString(rel.Title, 255)
|
||||
rel.LowerTagName = strings.ToLower(rel.TagName)
|
||||
if err = db.Insert(gitRepo.Ctx, rel); err != nil {
|
||||
if err = db.Insert(ctx, rel); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = repo_model.AddReleaseAttachments(gitRepo.Ctx, rel.ID, attachmentUUIDs); err != nil {
|
||||
if err = repo_model.AddReleaseAttachments(ctx, rel.ID, attachmentUUIDs); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !rel.IsDraft {
|
||||
notify_service.NewRelease(gitRepo.Ctx, rel)
|
||||
notify_service.NewRelease(ctx, rel)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -352,10 +352,10 @@ func UpdateRelease(ctx context.Context, doer *user_model.User, gitRepo *git.Repo
|
||||
|
||||
if !rel.IsDraft {
|
||||
if !isTagCreated && !isConvertedFromTag {
|
||||
notify_service.UpdateRelease(gitRepo.Ctx, doer, rel)
|
||||
notify_service.UpdateRelease(ctx, doer, rel)
|
||||
return nil
|
||||
}
|
||||
notify_service.NewRelease(gitRepo.Ctx, rel)
|
||||
notify_service.NewRelease(ctx, rel)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ func TestRelease_Create(t *testing.T) {
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
assert.NoError(t, CreateRelease(gitRepo, &repo_model.Release{
|
||||
assert.NoError(t, CreateRelease(t.Context(), gitRepo, &repo_model.Release{
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
PublisherID: user.ID,
|
||||
@@ -51,7 +51,7 @@ func TestRelease_Create(t *testing.T) {
|
||||
IsTag: false,
|
||||
}, nil, ""))
|
||||
|
||||
assert.NoError(t, CreateRelease(gitRepo, &repo_model.Release{
|
||||
assert.NoError(t, CreateRelease(t.Context(), gitRepo, &repo_model.Release{
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
PublisherID: user.ID,
|
||||
@@ -65,7 +65,7 @@ func TestRelease_Create(t *testing.T) {
|
||||
IsTag: false,
|
||||
}, nil, ""))
|
||||
|
||||
assert.NoError(t, CreateRelease(gitRepo, &repo_model.Release{
|
||||
assert.NoError(t, CreateRelease(t.Context(), gitRepo, &repo_model.Release{
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
PublisherID: user.ID,
|
||||
@@ -79,7 +79,7 @@ func TestRelease_Create(t *testing.T) {
|
||||
IsTag: false,
|
||||
}, nil, ""))
|
||||
|
||||
assert.NoError(t, CreateRelease(gitRepo, &repo_model.Release{
|
||||
assert.NoError(t, CreateRelease(t.Context(), gitRepo, &repo_model.Release{
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
PublisherID: user.ID,
|
||||
@@ -93,7 +93,7 @@ func TestRelease_Create(t *testing.T) {
|
||||
IsTag: false,
|
||||
}, nil, ""))
|
||||
|
||||
assert.NoError(t, CreateRelease(gitRepo, &repo_model.Release{
|
||||
assert.NoError(t, CreateRelease(t.Context(), gitRepo, &repo_model.Release{
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
PublisherID: user.ID,
|
||||
@@ -129,7 +129,7 @@ func TestRelease_Create(t *testing.T) {
|
||||
IsPrerelease: false,
|
||||
IsTag: true,
|
||||
}
|
||||
assert.NoError(t, CreateRelease(gitRepo, &release, []string{attach.UUID}, "test"))
|
||||
assert.NoError(t, CreateRelease(t.Context(), gitRepo, &release, []string{attach.UUID}, "test"))
|
||||
}
|
||||
|
||||
func TestRelease_Update(t *testing.T) {
|
||||
@@ -138,7 +138,7 @@ func TestRelease_Update(t *testing.T) {
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
@@ -149,7 +149,7 @@ func TestRelease_Update(t *testing.T) {
|
||||
advance := func() { fakeNow = fakeNow.Add(time.Second); timeutil.MockSet(fakeNow) }
|
||||
|
||||
// Test a changed release
|
||||
assert.NoError(t, CreateRelease(gitRepo, &repo_model.Release{
|
||||
assert.NoError(t, CreateRelease(t.Context(), gitRepo, &repo_model.Release{
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
PublisherID: user.ID,
|
||||
@@ -173,7 +173,7 @@ func TestRelease_Update(t *testing.T) {
|
||||
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
||||
// Test a changed draft
|
||||
assert.NoError(t, CreateRelease(gitRepo, &repo_model.Release{
|
||||
assert.NoError(t, CreateRelease(t.Context(), gitRepo, &repo_model.Release{
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
PublisherID: user.ID,
|
||||
@@ -197,7 +197,7 @@ func TestRelease_Update(t *testing.T) {
|
||||
assert.Less(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
||||
// Test a changed pre-release
|
||||
assert.NoError(t, CreateRelease(gitRepo, &repo_model.Release{
|
||||
assert.NoError(t, CreateRelease(t.Context(), gitRepo, &repo_model.Release{
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
PublisherID: user.ID,
|
||||
@@ -235,7 +235,7 @@ func TestRelease_Update(t *testing.T) {
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}
|
||||
assert.NoError(t, CreateRelease(gitRepo, release, nil, ""))
|
||||
assert.NoError(t, CreateRelease(t.Context(), gitRepo, release, nil, ""))
|
||||
assert.Positive(t, release.ID)
|
||||
|
||||
release.IsDraft = false
|
||||
@@ -297,7 +297,7 @@ func TestRelease_createTag(t *testing.T) {
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ func adoptRepository(ctx context.Context, repo *repo_model.Repository, defaultBr
|
||||
}
|
||||
|
||||
// Don't bother looking this repo in the context it won't be there
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("openRepository: %w", err)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func (item *archiveQueueItem) toArchiveRequest(ctx context.Context) (*ArchiveReq
|
||||
// NewRequest creates an archival request, based on the URI. The
|
||||
// resulting ArchiveRequest is suitable for being passed to Await()
|
||||
// if it's determined that the request still needs to be satisfied.
|
||||
func NewRequest(repo *repo_model.Repository, gitRepo *git.Repository, archiveRefExt string, paths []string) (*ArchiveRequest, error) {
|
||||
func NewRequest(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, archiveRefExt string, paths []string) (*ArchiveRequest, error) {
|
||||
// here the archiveRefShortName is not a clear ref, it could be a tag, branch or commit id
|
||||
archiveRefShortName, archiveType := repo_model.SplitArchiveNameType(archiveRefExt)
|
||||
if archiveType == repo_model.ArchiveUnknown {
|
||||
@@ -88,7 +88,7 @@ func NewRequest(repo *repo_model.Repository, gitRepo *git.Repository, archiveRef
|
||||
}
|
||||
|
||||
// Get corresponding commit.
|
||||
commit, err := gitRepo.GetCommit(archiveRefShortName)
|
||||
commit, err := gitRepo.GetCommit(ctx, archiveRefShortName)
|
||||
if err != nil {
|
||||
return nil, util.NewNotExistErrorf("unrecognized repository reference: %s", archiveRefShortName)
|
||||
}
|
||||
|
||||
@@ -49,47 +49,47 @@ func TestArchive_Basic(t *testing.T) {
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
bogusReq, err := NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".zip", nil)
|
||||
bogusReq, err := NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".zip", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, bogusReq)
|
||||
assert.Equal(t, firstCommit+".zip", bogusReq.GetArchiveName())
|
||||
|
||||
// Check a series of bogus requests.
|
||||
// Step 1, valid commit with a bad extension.
|
||||
bogusReq, err = NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".unknown", nil)
|
||||
bogusReq, err = NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".unknown", nil)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, bogusReq)
|
||||
|
||||
// Step 2, missing commit.
|
||||
bogusReq, err = NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, "dbffff.zip", nil)
|
||||
bogusReq, err = NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, "dbffff.zip", nil)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, bogusReq)
|
||||
|
||||
// Step 3, doesn't look like branch/tag/commit.
|
||||
bogusReq, err = NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, "db.zip", nil)
|
||||
bogusReq, err = NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, "db.zip", nil)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, bogusReq)
|
||||
|
||||
bogusReq, err = NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, "master.zip", nil)
|
||||
bogusReq, err = NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, "master.zip", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, bogusReq)
|
||||
assert.Equal(t, "master.zip", bogusReq.GetArchiveName())
|
||||
|
||||
bogusReq, err = NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, "test/archive.zip", nil)
|
||||
bogusReq, err = NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, "test/archive.zip", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, bogusReq)
|
||||
assert.Equal(t, "test-archive.zip", bogusReq.GetArchiveName())
|
||||
|
||||
// Now two valid requests, firstCommit with valid extensions.
|
||||
zipReq, err := NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".zip", nil)
|
||||
zipReq, err := NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".zip", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, zipReq)
|
||||
|
||||
tgzReq, err := NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".tar.gz", nil)
|
||||
tgzReq, err := NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".tar.gz", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, tgzReq)
|
||||
|
||||
secondReq, err := NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, secondCommit+".bundle", nil)
|
||||
secondReq, err := NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, secondCommit+".bundle", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, secondReq)
|
||||
|
||||
@@ -109,7 +109,7 @@ func TestArchive_Basic(t *testing.T) {
|
||||
// Sleep two seconds to make sure the queue doesn't change.
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
zipReq2, err := NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".zip", nil)
|
||||
zipReq2, err := NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".zip", nil)
|
||||
assert.NoError(t, err)
|
||||
// This zipReq should match what's sitting in the queue, as we haven't
|
||||
// let it release yet. From the consumer's point of view, this looks like
|
||||
@@ -124,12 +124,12 @@ func TestArchive_Basic(t *testing.T) {
|
||||
// Now we'll submit a request and TimedWaitForCompletion twice, before and
|
||||
// after we release it. We should trigger both the timeout and non-timeout
|
||||
// cases.
|
||||
timedReq, err := NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, secondCommit+".tar.gz", nil)
|
||||
timedReq, err := NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, secondCommit+".tar.gz", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, timedReq)
|
||||
doArchive(t.Context(), timedReq)
|
||||
|
||||
zipReq2, err = NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".zip", nil)
|
||||
zipReq2, err = NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".zip", nil)
|
||||
assert.NoError(t, err)
|
||||
// Now, we're guaranteed to have released the original zipReq from the queue.
|
||||
// Ensure that we don't get handed back the released entry somehow, but they
|
||||
@@ -146,7 +146,7 @@ func TestArchive_Basic(t *testing.T) {
|
||||
assert.NotEqual(t, zipReq.GetArchiveName(), secondReq.GetArchiveName())
|
||||
|
||||
t.Run("BadPath", func(t *testing.T) {
|
||||
badRequest, err := NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".tar.gz", []string{"not-a-path"})
|
||||
badRequest, err := NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, firstCommit+".tar.gz", []string{"not-a-path"})
|
||||
require.NoError(t, err)
|
||||
err = ServeRepoArchive(ctx.Base, badRequest)
|
||||
require.Error(t, err)
|
||||
|
||||
@@ -38,13 +38,13 @@ import (
|
||||
)
|
||||
|
||||
// CreateNewBranch creates a new repository branch
|
||||
func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldBranchName, branchName string) (err error) {
|
||||
func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, oldBranchName, branchName string) (err error) {
|
||||
branch, err := git_model.GetBranch(ctx, repo.ID, oldBranchName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return CreateNewBranchFromCommit(ctx, doer, repo, branch.CommitID, branchName)
|
||||
return CreateNewBranchFromCommit(ctx, doer, repo, gitRepo, branch.CommitID, branchName)
|
||||
}
|
||||
|
||||
// Branch contains the branch information
|
||||
@@ -226,14 +226,14 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g
|
||||
if pr.HasMerged {
|
||||
baseGitRepo, ok := repoIDToGitRepo[pr.BaseRepoID]
|
||||
if !ok {
|
||||
baseGitRepo, err = gitrepo.OpenRepository(ctx, pr.BaseRepo)
|
||||
baseGitRepo, err = gitrepo.OpenRepository(pr.BaseRepo)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("OpenRepository: %v", err)
|
||||
}
|
||||
defer baseGitRepo.Close()
|
||||
repoIDToGitRepo[pr.BaseRepoID] = baseGitRepo
|
||||
}
|
||||
pullCommit, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
pullCommit, err := baseGitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil && !git.IsErrNotExist(err) {
|
||||
return nil, fmt.Errorf("GetBranchCommitID: %v", err)
|
||||
}
|
||||
@@ -257,8 +257,8 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g
|
||||
}
|
||||
|
||||
// checkBranchName validates branch name with existing repository branches
|
||||
func checkBranchName(ctx context.Context, repo *repo_model.Repository, name string) error {
|
||||
_, err := gitrepo.WalkReferences(ctx, repo, func(_, refName string) error {
|
||||
func checkBranchName(ctx context.Context, gitRepo *git.Repository, name string) error {
|
||||
_, err := gitRepo.WalkReferences(ctx, "", 0, 0, func(_, refName string) error {
|
||||
branchRefName := strings.TrimPrefix(refName, git.BranchPrefix)
|
||||
switch {
|
||||
case branchRefName == name:
|
||||
@@ -289,7 +289,7 @@ func checkBranchName(ctx context.Context, repo *repo_model.Repository, name stri
|
||||
// It will check whether the branches of the repository have never been synced before.
|
||||
// If so, it will sync all branches of the repository.
|
||||
// Otherwise, it will sync the branches that need to be updated.
|
||||
func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, branchNames, commitIDs []string, getCommit func(commitID string) (*git.Commit, error)) error {
|
||||
func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, gitRepo *git.Repository, branchNames, commitIDs []string) error {
|
||||
// Some designs that make the code look strange but are made for performance optimization purposes:
|
||||
// 1. Sync branches in a batch to reduce the number of DB queries.
|
||||
// 2. Lazy load commit information since it may be not necessary.
|
||||
@@ -343,7 +343,7 @@ func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, branchNames,
|
||||
continue
|
||||
}
|
||||
|
||||
commit, err := getCommit(commitID)
|
||||
commit, err := gitRepo.GetCommit(ctx, commitID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get commit of %s failed: %v", branchName, err)
|
||||
}
|
||||
@@ -374,14 +374,14 @@ func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, branchNames,
|
||||
}
|
||||
|
||||
// CreateNewBranchFromCommit creates a new repository branch
|
||||
func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, commitID, branchName string) (err error) {
|
||||
func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, commitID, branchName string) (err error) {
|
||||
err = repo.MustNotBeArchived()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check if branch name can be used
|
||||
if err := checkBranchName(ctx, repo, branchName); err != nil {
|
||||
if err := checkBranchName(ctx, gitRepo, branchName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -504,7 +504,7 @@ func UpdateBranch(ctx context.Context, repo *repo_model.Repository, gitRepo *git
|
||||
}
|
||||
|
||||
if expectedOldCommitID != "" {
|
||||
expectedID, err := gitRepo.ConvertToGitID(expectedOldCommitID)
|
||||
expectedID, err := gitRepo.ConvertToGitID(ctx, expectedOldCommitID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ConvertToGitID(old): %w", err)
|
||||
}
|
||||
@@ -513,11 +513,11 @@ func UpdateBranch(ctx context.Context, repo *repo_model.Repository, gitRepo *git
|
||||
}
|
||||
}
|
||||
|
||||
newID, err := gitRepo.ConvertToGitID(newCommitID)
|
||||
newID, err := gitRepo.ConvertToGitID(ctx, newCommitID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ConvertToGitID(new): %w", err)
|
||||
}
|
||||
newCommit, err := gitRepo.GetCommit(newID.String())
|
||||
newCommit, err := gitRepo.GetCommit(ctx, newID.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -615,7 +615,7 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
|
||||
return err
|
||||
}
|
||||
|
||||
branchCommit, err := gitRepo.GetBranchCommit(branchName)
|
||||
branchCommit, err := gitRepo.GetBranchCommit(ctx, branchName)
|
||||
// branchCommit can be nil if the branch doesn't exist in git
|
||||
if err != nil && !errors.Is(err, util.ErrNotExist) {
|
||||
return err
|
||||
@@ -803,7 +803,7 @@ func GetBranchDivergingInfo(ctx reqctx.RequestContext, baseRepo *repo_model.Repo
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
headCommit, err := headGitRepo.GetCommit(headGitBranch.CommitID)
|
||||
headCommit, err := headGitRepo.GetCommit(ctx, headGitBranch.CommitID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -886,12 +886,12 @@ func DeleteBranchAfterMerge(ctx context.Context, doer *user_model.User, prID int
|
||||
defer gitHeadCloser.Close()
|
||||
|
||||
// Check if branch has no new commits
|
||||
headCommitID, err := gitBaseRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
headCommitID, err := gitBaseRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
log.Error("GetRefCommitID: %v", err)
|
||||
return errFailedToDelete(err)
|
||||
}
|
||||
branchCommitID, err := gitHeadRepo.GetBranchCommitID(pr.HeadBranch)
|
||||
branchCommitID, err := gitHeadRepo.GetBranchCommitID(ctx, pr.HeadBranch)
|
||||
if err != nil {
|
||||
log.Error("GetBranchCommitID: %v", err)
|
||||
return errFailedToDelete(err)
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
// CacheRef cachhe last commit information of the branch or the tag
|
||||
func CacheRef(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, fullRefName git.RefName) error {
|
||||
commit, err := gitRepo.GetCommit(fullRefName.String())
|
||||
commit, err := gitRepo.GetCommit(ctx, fullRefName.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
|
||||
|
||||
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
|
||||
|
||||
commit, err := gitRepo.GetCommit(sha)
|
||||
commit, err := gitRepo.GetCommit(ctx, sha)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetCommit[%s]: %w", sha, err)
|
||||
}
|
||||
@@ -104,7 +104,7 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
|
||||
|
||||
notify.CreateCommitStatus(ctx, repo, repo_module.CommitToPushCommit(commit), creator, status)
|
||||
|
||||
defaultBranchCommit, err := gitRepo.GetBranchCommit(repo.DefaultBranch)
|
||||
defaultBranchCommit, err := gitRepo.GetBranchCommit(ctx, repo.DefaultBranch)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetBranchCommit[%s]: %w", repo.DefaultBranch, err)
|
||||
}
|
||||
|
||||
@@ -111,8 +111,8 @@ func GetContributorStats(ctx context.Context, cache cache.StringCache, repo *rep
|
||||
}
|
||||
|
||||
// getExtendedCommitStats return the list of *ExtendedCommitStats for the given revision
|
||||
func getExtendedCommitStats(repo *git.Repository, revision string /*, limit int */) ([]*ExtendedCommitStats, error) {
|
||||
baseCommit, err := repo.GetCommit(revision)
|
||||
func getExtendedCommitStats(ctx context.Context, repo *git.Repository, revision string /*, limit int */) ([]*ExtendedCommitStats, error) {
|
||||
baseCommit, err := repo.GetCommit(ctx, revision)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -180,7 +180,7 @@ func getExtendedCommitStats(repo *git.Repository, revision string /*, limit int
|
||||
}
|
||||
return nil
|
||||
}).
|
||||
RunWithStderr(repo.Ctx)
|
||||
RunWithStderr(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ContributorsCommitStats: %w", err)
|
||||
}
|
||||
@@ -201,7 +201,7 @@ func generateContributorStats(genDone chan struct{}, cache cache.StringCache, ca
|
||||
if len(revision) == 0 {
|
||||
revision = repo.DefaultBranch
|
||||
}
|
||||
extendedCommitStats, err := getExtendedCommitStats(gitRepo, revision)
|
||||
extendedCommitStats, err := getExtendedCommitStats(ctx, gitRepo, revision)
|
||||
if err != nil {
|
||||
_ = cache.PutJSON(cacheKey, fmt.Errorf("ExtendedCommitStats: %w", err), contributorStatsCacheTimeout)
|
||||
return
|
||||
|
||||
@@ -63,7 +63,7 @@ func CherryPick(ctx context.Context, repo *repo_model.Repository, doer *user_mod
|
||||
}
|
||||
|
||||
// Get the commit of the original branch
|
||||
commit, err := t.GetBranchCommit(opts.OldBranch)
|
||||
commit, err := t.GetBranchCommit(ctx, opts.OldBranch)
|
||||
if err != nil {
|
||||
return nil, err // Couldn't get a commit for the branch
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func CherryPick(ctx context.Context, repo *repo_model.Repository, doer *user_mod
|
||||
if opts.LastCommitID == "" {
|
||||
opts.LastCommitID = commit.ID.String()
|
||||
} else {
|
||||
lastCommitID, err := t.gitRepo.ConvertToGitID(opts.LastCommitID)
|
||||
lastCommitID, err := t.gitRepo.ConvertToGitID(ctx, opts.LastCommitID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("CherryPick: Invalid last commit ID: %w", err)
|
||||
}
|
||||
@@ -85,7 +85,7 @@ func CherryPick(ctx context.Context, repo *repo_model.Repository, doer *user_mod
|
||||
}
|
||||
}
|
||||
|
||||
commit, err = t.GetCommit(strings.TrimSpace(opts.Content))
|
||||
commit, err = t.GetCommit(ctx, strings.TrimSpace(opts.Content))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -142,12 +142,12 @@ func CherryPick(ctx context.Context, repo *repo_model.Repository, doer *user_mod
|
||||
return nil, err
|
||||
}
|
||||
|
||||
commit, err = t.GetCommit(commitHash)
|
||||
commit, err = t.GetCommit(ctx, commitHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fileCommitResponse, _ := GetFileCommitResponse(repo, gitRepo, commit) // ok if fails, then will be nil
|
||||
fileCommitResponse, _ := GetFileCommitResponse(ctx, repo, gitRepo, commit) // ok if fails, then will be nil
|
||||
verification := GetPayloadCommitVerification(ctx, commit)
|
||||
fileResponse := &structs.FileResponse{
|
||||
Commit: fileCommitResponse,
|
||||
|
||||
@@ -162,7 +162,7 @@ func getFileContentsByEntryInternal(ctx context.Context, repo *repo_model.Reposi
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lastCommit, err := refCommit.Commit.GetCommitByPath(gitRepo, opts.TreePath)
|
||||
lastCommit, err := refCommit.Commit.GetCommitByPath(ctx, gitRepo, opts.TreePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -188,14 +188,14 @@ func getFileContentsByEntryInternal(ctx context.Context, repo *repo_model.Reposi
|
||||
contentsResponse.Type = string(ContentTypeRegular)
|
||||
// if it is listing the repo root dir, don't waste system resources on reading content
|
||||
if opts.IncludeSingleFileContent {
|
||||
blobResponse, err := GetBlobBySHA(repo, gitRepo, entry.ID.String())
|
||||
blobResponse, err := GetBlobBySHA(ctx, repo, gitRepo, entry.ID.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
contentsResponse.Encoding, contentsResponse.Content = blobResponse.Encoding, blobResponse.Content
|
||||
contentsResponse.LfsOid, contentsResponse.LfsSize = blobResponse.LfsOid, blobResponse.LfsSize
|
||||
} else if opts.IncludeLfsMetadata {
|
||||
contentsResponse.LfsOid, contentsResponse.LfsSize, err = parsePossibleLfsPointerBlob(gitRepo, entry.ID.String())
|
||||
contentsResponse.LfsOid, contentsResponse.LfsSize, err = parsePossibleLfsPointerBlob(ctx, gitRepo, entry.ID.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -205,7 +205,7 @@ func getFileContentsByEntryInternal(ctx context.Context, repo *repo_model.Reposi
|
||||
} else if entry.IsLink() {
|
||||
contentsResponse.Type = string(ContentTypeLink)
|
||||
// The target of a symlink file is the content of the file
|
||||
targetFromContent, err := entry.Blob(gitRepo).GetBlobContent(1024)
|
||||
targetFromContent, err := entry.Blob(gitRepo).GetBlobContent(ctx, 1024)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -250,7 +250,7 @@ func getFileContentsByEntryInternal(ctx context.Context, repo *repo_model.Reposi
|
||||
return contentsResponse, nil
|
||||
}
|
||||
|
||||
func GetBlobBySHA(repo *repo_model.Repository, gitRepo *git.Repository, sha string) (*api.GitBlobResponse, error) {
|
||||
func GetBlobBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, sha string) (*api.GitBlobResponse, error) {
|
||||
gitBlob, err := gitRepo.GetBlob(sha)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -258,10 +258,10 @@ func GetBlobBySHA(repo *repo_model.Repository, gitRepo *git.Repository, sha stri
|
||||
ret := &api.GitBlobResponse{
|
||||
SHA: gitBlob.ID.String(),
|
||||
URL: repo.APIURL() + "/git/blobs/" + url.PathEscape(gitBlob.ID.String()),
|
||||
Size: gitBlob.Size(),
|
||||
Size: gitBlob.Size(ctx),
|
||||
}
|
||||
|
||||
blobSize := gitBlob.Size()
|
||||
blobSize := gitBlob.Size(ctx)
|
||||
if blobSize > setting.API.DefaultMaxBlobSize {
|
||||
return ret, nil
|
||||
}
|
||||
@@ -271,7 +271,7 @@ func GetBlobBySHA(repo *repo_model.Repository, gitRepo *git.Repository, sha stri
|
||||
originContent = &strings.Builder{}
|
||||
}
|
||||
|
||||
content, err := gitBlob.GetBlobContentBase64(originContent)
|
||||
content, err := gitBlob.GetBlobContentBase64(ctx, originContent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -291,15 +291,15 @@ func parsePossibleLfsPointerBuffer(r io.Reader) (*string, *int64) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func parsePossibleLfsPointerBlob(gitRepo *git.Repository, sha string) (*string, *int64, error) {
|
||||
func parsePossibleLfsPointerBlob(ctx context.Context, gitRepo *git.Repository, sha string) (*string, *int64, error) {
|
||||
gitBlob, err := gitRepo.GetBlob(sha)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if gitBlob.Size() > lfs.MetaFileMaxSize {
|
||||
if gitBlob.Size(ctx) > lfs.MetaFileMaxSize {
|
||||
return nil, nil, nil // not a LFS pointer
|
||||
}
|
||||
buf, err := gitBlob.GetBlobContent(lfs.MetaFileMaxSize)
|
||||
buf, err := gitBlob.GetBlobContent(ctx, lfs.MetaFileMaxSize)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestGetContents(t *testing.T) {
|
||||
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
|
||||
ctx.SetPathParam("id", "1")
|
||||
ctx.SetPathParam("sha", sha)
|
||||
gbr, err := GetBlobBySHA(ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.PathParam("sha"))
|
||||
gbr, err := GetBlobBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.PathParam("sha"))
|
||||
expectedGBR := &api.GitBlobResponse{
|
||||
Content: new("dHJlZSAyYTJmMWQ0NjcwNzI4YTJlMTAwNDllMzQ1YmQ3YTI3NjQ2OGJlYWI2CmF1dGhvciB1c2VyMSA8YWRkcmVzczFAZXhhbXBsZS5jb20+IDE0ODk5NTY0NzkgLTA0MDAKY29tbWl0dGVyIEV0aGFuIEtvZW5pZyA8ZXRoYW50a29lbmlnQGdtYWlsLmNvbT4gMTQ4OTk1NjQ3OSAtMDQwMAoKSW5pdGlhbCBjb21taXQK"),
|
||||
Encoding: new("base64"),
|
||||
|
||||
@@ -45,7 +45,7 @@ func GetContentsListFromTreePaths(ctx context.Context, repo *repo_model.Reposito
|
||||
|
||||
func GetFilesResponseFromCommit(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, refCommit *utils.RefCommit, treeNames []string) (*api.FilesResponse, error) {
|
||||
files := GetContentsListFromTreePaths(ctx, repo, gitRepo, refCommit, treeNames)
|
||||
fileCommitResponse, _ := GetFileCommitResponse(repo, gitRepo, refCommit.Commit) // ok if fails, then will be nil
|
||||
fileCommitResponse, _ := GetFileCommitResponse(ctx, repo, gitRepo, refCommit.Commit) // ok if fails, then will be nil
|
||||
verification := GetPayloadCommitVerification(ctx, refCommit.Commit)
|
||||
filesResponse := &api.FilesResponse{
|
||||
Files: files,
|
||||
@@ -70,7 +70,7 @@ func GetFileResponseFromFilesResponse(filesResponse *api.FilesResponse, index in
|
||||
}
|
||||
|
||||
// GetFileCommitResponse Constructs a FileCommitResponse from a Commit object
|
||||
func GetFileCommitResponse(repo *repo_model.Repository, gitRepo *git.Repository, commit *git.Commit) (*api.FileCommitResponse, error) {
|
||||
func GetFileCommitResponse(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, commit *git.Commit) (*api.FileCommitResponse, error) {
|
||||
if repo == nil {
|
||||
return nil, errors.New("repo cannot be nil")
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func GetFileCommitResponse(repo *repo_model.Repository, gitRepo *git.Repository,
|
||||
commitTreeURL, _ := url.Parse(repo.APIURL() + "/git/trees/" + url.PathEscape(commit.TreeID.String()))
|
||||
parents := make([]*api.CommitMeta, commit.ParentCount())
|
||||
for i := 0; i < commit.ParentCount(); i++ {
|
||||
if parent, err := commit.Parent(gitRepo, i); err == nil && parent != nil {
|
||||
if parent, err := commit.Parent(ctx, gitRepo, i); err == nil && parent != nil {
|
||||
parentCommitURL, _ := url.Parse(repo.APIURL() + "/git/commits/" + url.PathEscape(parent.ID.String()))
|
||||
parents[i] = &api.CommitMeta{
|
||||
SHA: parent.ID.String(),
|
||||
|
||||
@@ -142,7 +142,7 @@ func ApplyDiffPatch(ctx context.Context, repo *repo_model.Repository, doer *user
|
||||
}
|
||||
|
||||
// Get the commit of the original branch
|
||||
commit, err := t.GetBranchCommit(opts.OldBranch)
|
||||
commit, err := t.GetBranchCommit(ctx, opts.OldBranch)
|
||||
if err != nil {
|
||||
return nil, err // Couldn't get a commit for the branch
|
||||
}
|
||||
@@ -151,7 +151,7 @@ func ApplyDiffPatch(ctx context.Context, repo *repo_model.Repository, doer *user
|
||||
if opts.LastCommitID == "" {
|
||||
opts.LastCommitID = commit.ID.String()
|
||||
} else {
|
||||
lastCommitID, err := t.gitRepo.ConvertToGitID(opts.LastCommitID)
|
||||
lastCommitID, err := t.gitRepo.ConvertToGitID(ctx, opts.LastCommitID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ApplyPatch: Invalid last commit ID: %w", err)
|
||||
}
|
||||
@@ -206,12 +206,12 @@ func ApplyDiffPatch(ctx context.Context, repo *repo_model.Repository, doer *user
|
||||
return nil, err
|
||||
}
|
||||
|
||||
commit, err = t.GetCommit(commitHash)
|
||||
commit, err = t.GetCommit(ctx, commitHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fileCommitResponse, _ := GetFileCommitResponse(repo, gitRepo, commit) // ok if fails, then will be nil
|
||||
fileCommitResponse, _ := GetFileCommitResponse(ctx, repo, gitRepo, commit) // ok if fails, then will be nil
|
||||
verification := GetPayloadCommitVerification(ctx, commit)
|
||||
fileResponse := &structs.FileResponse{
|
||||
Commit: fileCommitResponse,
|
||||
|
||||
@@ -48,7 +48,10 @@ func NewTemporaryUploadRepository(repo *repo_model.Repository) (*TemporaryUpload
|
||||
// Close the repository cleaning up all files
|
||||
func (t *TemporaryUploadRepository) Close() {
|
||||
// must stop the repo access before removal, otherwise Windows can't remove the directory occupied by other processes
|
||||
t.gitRepo.Close()
|
||||
if t.gitRepo != nil {
|
||||
_ = t.gitRepo.Close()
|
||||
t.gitRepo = nil
|
||||
}
|
||||
if t.cleanup != nil {
|
||||
t.cleanup()
|
||||
}
|
||||
@@ -76,7 +79,7 @@ func (t *TemporaryUploadRepository) Clone(ctx context.Context, branch string, ba
|
||||
}
|
||||
return fmt.Errorf("Clone: %w %s", err, stderr)
|
||||
}
|
||||
gitRepo, err := git.OpenRepository(ctx, t.basePath)
|
||||
gitRepo, err := git.OpenRepository(t.basePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -89,7 +92,7 @@ func (t *TemporaryUploadRepository) Init(ctx context.Context, objectFormatName s
|
||||
if err := git.InitRepository(ctx, t.basePath, false, objectFormatName); err != nil {
|
||||
return err
|
||||
}
|
||||
gitRepo, err := git.OpenRepository(ctx, t.basePath)
|
||||
gitRepo, err := git.OpenRepository(t.basePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -141,7 +144,7 @@ func (t *TemporaryUploadRepository) RemoveRecursivelyFromIndex(ctx context.Conte
|
||||
|
||||
// RemoveFilesFromIndex removes the given files from the index
|
||||
func (t *TemporaryUploadRepository) RemoveFilesFromIndex(ctx context.Context, filenames ...string) error {
|
||||
objFmt, err := t.gitRepo.GetObjectFormat()
|
||||
objFmt, err := t.gitRepo.GetObjectFormat(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get object format for temporary repo: %q, error: %w", t.repo.FullName(), err)
|
||||
}
|
||||
@@ -387,17 +390,17 @@ func (t *TemporaryUploadRepository) DiffIndex(ctx context.Context, oldContent, n
|
||||
}
|
||||
|
||||
// GetBranchCommit Gets the commit object of the given branch
|
||||
func (t *TemporaryUploadRepository) GetBranchCommit(branch string) (*git.Commit, error) {
|
||||
func (t *TemporaryUploadRepository) GetBranchCommit(ctx context.Context, branch string) (*git.Commit, error) {
|
||||
if t.gitRepo == nil {
|
||||
return nil, errors.New("repository has not been cloned")
|
||||
}
|
||||
return t.gitRepo.GetBranchCommit(branch)
|
||||
return t.gitRepo.GetBranchCommit(ctx, branch)
|
||||
}
|
||||
|
||||
// GetCommit Gets the commit object of the given commit ID
|
||||
func (t *TemporaryUploadRepository) GetCommit(commitID string) (*git.Commit, error) {
|
||||
func (t *TemporaryUploadRepository) GetCommit(ctx context.Context, commitID string) (*git.Commit, error) {
|
||||
if t.gitRepo == nil {
|
||||
return nil, errors.New("repository has not been cloned")
|
||||
}
|
||||
return t.gitRepo.GetCommit(commitID)
|
||||
return t.gitRepo.GetCommit(ctx, commitID)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
// GetTreeBySHA get the GitTreeResponse of a repository using a sha hash (id of a commit or a tree)
|
||||
func GetTreeBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, sha string, page, perPage int, recursive bool) (*api.GitTreeResponse, error) {
|
||||
gitTree, err := gitRepo.GetTree(sha)
|
||||
gitTree, err := gitRepo.GetTree(ctx, sha)
|
||||
if err != nil {
|
||||
return nil, util.NewInvalidArgumentErrorf("sha not found [%s]", sha)
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func listTreeNodes(ctx context.Context, repoLink string, renderedIconPool *filei
|
||||
if subTreePath[0] == '/' {
|
||||
subTreePath = subTreePath[1:]
|
||||
}
|
||||
subNodes, err := listTreeNodes(ctx, repoLink, renderedIconPool, gitRepo, commit, entry.Tree(gitRepo), subTreePath, subPathRemaining)
|
||||
subNodes, err := listTreeNodes(ctx, repoLink, renderedIconPool, gitRepo, commit, entry.Tree(ctx, gitRepo), subTreePath, subPathRemaining)
|
||||
if err != nil {
|
||||
log.Error("listTreeNodes: %v", err)
|
||||
} else {
|
||||
@@ -187,5 +187,5 @@ func GetTreeViewNodes(ctx context.Context, repoLink string, renderedIconPool *fi
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return listTreeNodes(ctx, repoLink, renderedIconPool, gitRepo, commit, entry.Tree(gitRepo), treePath, subPath)
|
||||
return listTreeNodes(ctx, repoLink, renderedIconPool, gitRepo, commit, entry.Tree(ctx, gitRepo), treePath, subPath)
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
|
||||
|
||||
if hasOldBranch {
|
||||
// Get the commit of the original branch
|
||||
commit, err := t.GetBranchCommit(opts.OldBranch)
|
||||
commit, err := t.GetBranchCommit(ctx, opts.OldBranch)
|
||||
if err != nil {
|
||||
return nil, err // Couldn't get a commit for the branch
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
|
||||
if opts.LastCommitID == "" {
|
||||
opts.LastCommitID = commit.ID.String()
|
||||
} else {
|
||||
lastCommitID, err := t.gitRepo.ConvertToGitID(opts.LastCommitID)
|
||||
lastCommitID, err := t.gitRepo.ConvertToGitID(ctx, opts.LastCommitID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ConvertToSHA1: Invalid last commit ID: %w", err)
|
||||
}
|
||||
@@ -282,7 +282,7 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
|
||||
return nil, err
|
||||
}
|
||||
|
||||
commit, err := t.GetCommit(commitHash)
|
||||
commit, err := t.GetCommit(ctx, commitHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -295,7 +295,7 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
|
||||
}
|
||||
|
||||
if repo.IsEmpty {
|
||||
if isEmpty, err := gitRepo.IsEmpty(); err == nil && !isEmpty {
|
||||
if isEmpty, err := gitRepo.IsEmpty(ctx); err == nil && !isEmpty {
|
||||
_ = repo_model.UpdateRepositoryColsWithAutoTime(ctx, &repo_model.Repository{ID: repo.ID, IsEmpty: false, DefaultBranch: opts.NewBranch}, "is_empty", "default_branch")
|
||||
}
|
||||
}
|
||||
@@ -391,7 +391,7 @@ func handleCheckErrors(ctx context.Context, file *ChangeRepoFile, gitRepo *git.R
|
||||
// If a lastCommitID given doesn't match the branch head's commitID throw
|
||||
// an error, but only if we aren't creating a new branch.
|
||||
if commit.ID.String() != opts.LastCommitID && opts.OldBranch == opts.NewBranch {
|
||||
if changed, err := commit.FileChangedSinceCommit(gitRepo, file.Options.treePath, opts.LastCommitID); err != nil {
|
||||
if changed, err := commit.FileChangedSinceCommit(ctx, gitRepo, file.Options.treePath, opts.LastCommitID); err != nil {
|
||||
return err
|
||||
} else if changed {
|
||||
return ErrCommitIDDoesNotMatch{
|
||||
@@ -592,7 +592,7 @@ func writeRepoObjectForRename(ctx context.Context, t *TemporaryUploadRepository,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
commit, err := t.GetCommit(lastCommitID)
|
||||
commit, err := t.GetCommit(ctx, lastCommitID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -619,7 +619,7 @@ func writeRepoObjectForRename(ctx context.Context, t *TemporaryUploadRepository,
|
||||
}
|
||||
|
||||
oldEntryBlobPointerBy := func(f func(r io.Reader) (lfs.Pointer, error)) (lfsPointer lfs.Pointer, err error) {
|
||||
r, err := oldEntry.Blob(t.gitRepo).DataAsync()
|
||||
r, err := oldEntry.Blob(t.gitRepo).DataAsync(ctx)
|
||||
if err != nil {
|
||||
return lfsPointer, err
|
||||
}
|
||||
@@ -645,7 +645,7 @@ func writeRepoObjectForRename(ctx context.Context, t *TemporaryUploadRepository,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret.LfsContent, err = oldEntry.Blob(t.gitRepo).DataAsync()
|
||||
ret.LfsContent, err = oldEntry.Blob(t.gitRepo).DataAsync(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
|
||||
|
||||
// 6 - Sync the repository branches and tags
|
||||
var gitRepo *git.Repository
|
||||
gitRepo, err = gitrepo.OpenRepository(ctx, repo)
|
||||
gitRepo, err = gitrepo.OpenRepository(repo)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("OpenRepository: %w", err)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package gitgraph
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/git/gitcmd"
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
// GetCommitGraph return a list of commit (GraphItems) from all branches
|
||||
func GetCommitGraph(r *git.Repository, page, maxAllowedColors int, hidePRRefs bool, branches, files []string) (*Graph, error) {
|
||||
func GetCommitGraph(ctx context.Context, r *git.Repository, page, maxAllowedColors int, hidePRRefs bool, branches, files []string) (*Graph, error) {
|
||||
format := "DATA:%D|%H|%ad|%h|%s"
|
||||
|
||||
if page == 0 {
|
||||
@@ -97,7 +98,7 @@ func GetCommitGraph(r *git.Repository, page, maxAllowedColors int, hidePRRefs bo
|
||||
}
|
||||
return scanner.Err()
|
||||
}).
|
||||
RunWithStderr(r.Ctx); err != nil {
|
||||
RunWithStderr(ctx); err != nil {
|
||||
return graph, err
|
||||
}
|
||||
return graph, nil
|
||||
|
||||
@@ -102,7 +102,7 @@ func (graph *Graph) LoadAndProcessCommits(ctx context.Context, repository *repo_
|
||||
if len(c.Rev) == 0 {
|
||||
continue
|
||||
}
|
||||
c.Commit, err = gitRepo.GetCommit(c.Rev)
|
||||
c.Commit, err = gitRepo.GetCommit(ctx, c.Rev)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetCommit: %s Error: %w", c.Rev, err)
|
||||
}
|
||||
|
||||
@@ -16,14 +16,14 @@ import (
|
||||
)
|
||||
|
||||
func BenchmarkGetCommitGraph(b *testing.B) {
|
||||
currentRepo, err := git.OpenRepository(b.Context(), ".")
|
||||
currentRepo, err := git.OpenRepository(".")
|
||||
if err != nil || currentRepo == nil {
|
||||
b.Error("Could not open repository")
|
||||
}
|
||||
defer currentRepo.Close()
|
||||
|
||||
for b.Loop() {
|
||||
graph, err := GetCommitGraph(currentRepo, 1, 0, false, nil, nil)
|
||||
graph, err := GetCommitGraph(b.Context(), currentRepo, 1, 0, false, nil, nil)
|
||||
if err != nil {
|
||||
b.Error("Could get commit graph")
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ func SyncRepositoryHooks(ctx context.Context) error {
|
||||
|
||||
// GenerateGitHooks generates git hooks from a template repository
|
||||
func GenerateGitHooks(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error {
|
||||
generateGitRepo, err := gitrepo.OpenRepository(ctx, generateRepo)
|
||||
generateGitRepo, err := gitrepo.OpenRepository(generateRepo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer generateGitRepo.Close()
|
||||
|
||||
templateGitRepo, err := gitrepo.OpenRepository(ctx, templateRepo)
|
||||
templateGitRepo, err := gitrepo.OpenRepository(templateRepo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.R
|
||||
}
|
||||
}()
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
if err != nil {
|
||||
log.Error("Unable to open git repository %-v: %v", repo, err)
|
||||
return err
|
||||
@@ -88,7 +88,7 @@ func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.R
|
||||
total++
|
||||
pointerSha := git.ComputeBlobHash(objectFormat, []byte(metaObject.Pointer.StringContent()))
|
||||
|
||||
if gitRepo.IsObjectExist(pointerSha.String()) {
|
||||
if gitRepo.IsObjectExist(ctx, pointerSha.String()) {
|
||||
return git_model.MarkLFSMetaObject(ctx, metaObject.ID)
|
||||
}
|
||||
orphaned++
|
||||
|
||||
@@ -72,14 +72,14 @@ func repoLicenseUpdater(items ...*LicenseUpdaterOptions) []*LicenseUpdaterOption
|
||||
continue
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
if err != nil {
|
||||
log.Error("repoLicenseUpdater [%d] failed: OpenRepository: %v", opts.RepoID, err)
|
||||
continue
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
commit, err := gitRepo.GetBranchCommit(repo.DefaultBranch)
|
||||
commit, err := gitRepo.GetBranchCommit(ctx, repo.DefaultBranch)
|
||||
if err != nil {
|
||||
log.Error("repoLicenseUpdater [%d] failed: GetBranchCommit: %v", opts.RepoID, err)
|
||||
continue
|
||||
@@ -131,7 +131,7 @@ func UpdateRepoLicenses(ctx context.Context, repo *repo_model.Repository, gitRep
|
||||
|
||||
licenses := make([]string, 0)
|
||||
if b != nil {
|
||||
r, err := b.DataAsync()
|
||||
r, err := b.DataAsync(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -122,13 +122,13 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
|
||||
return nil, fmt.Errorf("updateGitRepoAfterCreate: %w", err)
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
if err != nil {
|
||||
return repo, fmt.Errorf("OpenRepository: %w", err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
repo.IsEmpty, err = gitRepo.IsEmpty()
|
||||
repo.IsEmpty, err = gitRepo.IsEmpty(ctx)
|
||||
if err != nil {
|
||||
return repo, fmt.Errorf("git.IsEmpty: %w", err)
|
||||
}
|
||||
|
||||
+12
-12
@@ -74,7 +74,7 @@ func pushQueueHandleUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
return fmt.Errorf("GetRepositoryByOwnerAndName failed: %w", err)
|
||||
}
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
|
||||
gitRepo, err := gitrepo.OpenRepository(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenRepository[%s]: %w", repo.FullName(), err)
|
||||
}
|
||||
@@ -120,11 +120,11 @@ func pushQueueHandleUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
delTags = append(delTags, tagName)
|
||||
notify_service.DeleteRef(ctx, pusher, repo, opts.RefFullName)
|
||||
} else { // is new tag
|
||||
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
|
||||
newCommit, err := gitRepo.GetCommit(ctx, opts.NewCommitID)
|
||||
if err != nil {
|
||||
// in case there is dirty data, for example, the "github.com/git/git" repository has tags pointing to non-existing commits
|
||||
if !errors.Is(err, util.ErrNotExist) {
|
||||
log.Error("Unable to get tag commit: gitRepo.GetCommit(%s) in %s/%s[%d]: %v", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
|
||||
log.Error("Unable to get tag commit: gitRepo.GetCommit(ctx, %s) in %s/%s[%d]: %v", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
|
||||
}
|
||||
} else {
|
||||
commits := repo_module.NewPushCommits()
|
||||
@@ -160,9 +160,9 @@ func pushQueueHandleUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
|
||||
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
|
||||
|
||||
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
|
||||
newCommit, err := gitRepo.GetCommit(ctx, opts.NewCommitID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gitRepo.GetCommit(%s) in %s/%s[%d]: %w", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
|
||||
return fmt.Errorf("gitRepo.GetCommit(ctx, %s) in %s/%s[%d]: %w", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
|
||||
}
|
||||
|
||||
// Push new branch.
|
||||
@@ -197,7 +197,7 @@ func pushQueueHandleUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
log.Error("updateIssuesCommit: %v", err)
|
||||
}
|
||||
|
||||
commits.CompareURL = getCompareURL(repo, gitRepo, objectFormat, commits.Commits, opts)
|
||||
commits.CompareURL = getCompareURL(ctx, repo, gitRepo, objectFormat, commits.Commits, opts)
|
||||
|
||||
if len(commits.Commits) > setting.UI.FeedMaxCommitNum {
|
||||
commits.Commits = commits.Commits[:setting.UI.FeedMaxCommitNum]
|
||||
@@ -236,10 +236,10 @@ func pushQueueHandleUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getCompareURL(repo *repo_model.Repository, gitRepo *git.Repository, objectFormat git.ObjectFormat, commits []*repo_module.PushCommit, opts *repo_module.PushUpdateOptions) string {
|
||||
func getCompareURL(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, objectFormat git.ObjectFormat, commits []*repo_module.PushCommit, opts *repo_module.PushUpdateOptions) string {
|
||||
oldCommitID := opts.OldCommitID
|
||||
if oldCommitID == objectFormat.EmptyObjectID().String() && len(commits) > 0 {
|
||||
oldCommit, err := gitRepo.GetCommit(commits[len(commits)-1].Sha1)
|
||||
oldCommit, err := gitRepo.GetCommit(ctx, commits[len(commits)-1].Sha1)
|
||||
if err != nil && !git.IsErrNotExist(err) {
|
||||
log.Error("unable to GetCommit %s from %-v: %v", oldCommitID, repo, err)
|
||||
}
|
||||
@@ -279,7 +279,7 @@ func pushNewBranch(ctx context.Context, repo *repo_model.Repository, gitRepo *gi
|
||||
}
|
||||
}
|
||||
|
||||
l, err := newCommit.CommitsBeforeLimit(gitRepo, 10)
|
||||
l, err := newCommit.CommitsBeforeLimit(ctx, gitRepo, 10)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("newCommit.CommitsBeforeLimit: %w", err)
|
||||
}
|
||||
@@ -288,7 +288,7 @@ func pushNewBranch(ctx context.Context, repo *repo_model.Repository, gitRepo *gi
|
||||
}
|
||||
|
||||
func pushUpdateBranch(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, pusher *user_model.User, opts *repo_module.PushUpdateOptions, newCommit *git.Commit) ([]*git.Commit, error) {
|
||||
l, err := newCommit.CommitsBeforeUntil(gitRepo, git.RefNameFromCommit(opts.OldCommitID))
|
||||
l, err := newCommit.CommitsBeforeUntil(ctx, gitRepo, git.RefNameFromCommit(opts.OldCommitID))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("newCommit.CommitsBeforeUntil: %w", err)
|
||||
}
|
||||
@@ -370,11 +370,11 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
|
||||
newReleases := make([]*repo_model.Release, 0, len(lowerTags)-len(relMap))
|
||||
|
||||
for i, lowerTag := range lowerTags {
|
||||
tag, err := gitRepo.GetTag(tags[i])
|
||||
tag, err := gitRepo.GetTag(ctx, tags[i])
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetTag: %w", err)
|
||||
}
|
||||
commit, err := gitRepo.GetTagCommit(tag.Name)
|
||||
commit, err := gitRepo.GetTagCommit(ctx, tag.Name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Commit: %w", err)
|
||||
}
|
||||
|
||||
+18
-18
@@ -52,12 +52,12 @@ func InitWiki(ctx context.Context, repo *repo_model.Repository) error {
|
||||
|
||||
// prepareGitPath try to find a suitable file path with file name by the given raw wiki name.
|
||||
// return: existence, prepared file path with name, error
|
||||
func prepareGitPath(gitRepo *git.Repository, defaultWikiBranch string, wikiPath WebPath) (bool, string, error) {
|
||||
func prepareGitPath(ctx context.Context, gitRepo *git.Repository, defaultWikiBranch string, wikiPath WebPath) (bool, string, error) {
|
||||
unescaped := string(wikiPath) + ".md"
|
||||
gitPath := WebPathToGitPath(wikiPath)
|
||||
|
||||
// Look for both files
|
||||
filesInIndex, err := gitRepo.LsTree(defaultWikiBranch, unescaped, gitPath)
|
||||
filesInIndex, err := gitRepo.LsTree(ctx, defaultWikiBranch, unescaped, gitPath)
|
||||
if err != nil {
|
||||
if gitcmd.IsStderr(err, gitcmd.StderrNotValidObjectName) {
|
||||
return false, gitPath, nil // branch doesn't exist
|
||||
@@ -123,7 +123,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
return fmt.Errorf("failed to clone repository: %s (%w)", repo.FullName(), err)
|
||||
}
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx, basePath)
|
||||
gitRepo, err := git.OpenRepository(basePath)
|
||||
if err != nil {
|
||||
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
|
||||
return fmt.Errorf("failed to open new temporary repository in: %s %w", basePath, err)
|
||||
@@ -131,13 +131,13 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
defer gitRepo.Close()
|
||||
|
||||
if hasDefaultBranch {
|
||||
if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil {
|
||||
if err := gitRepo.ReadTreeToIndex(ctx, "HEAD"); err != nil {
|
||||
log.Error("Unable to read HEAD tree to index in: %s %v", basePath, err)
|
||||
return fmt.Errorf("unable to read HEAD tree to index in: %s %w", basePath, err)
|
||||
}
|
||||
}
|
||||
|
||||
isWikiExist, newWikiPath, err := prepareGitPath(gitRepo, repo.DefaultWikiBranch, newWikiName)
|
||||
isWikiExist, newWikiPath, err := prepareGitPath(ctx, gitRepo, repo.DefaultWikiBranch, newWikiName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -153,14 +153,14 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
isOldWikiExist := true
|
||||
oldWikiPath := newWikiPath
|
||||
if oldWikiName != newWikiName {
|
||||
isOldWikiExist, oldWikiPath, err = prepareGitPath(gitRepo, repo.DefaultWikiBranch, oldWikiName)
|
||||
isOldWikiExist, oldWikiPath, err = prepareGitPath(ctx, gitRepo, repo.DefaultWikiBranch, oldWikiName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if isOldWikiExist {
|
||||
err := gitRepo.RemoveFilesFromIndex(oldWikiPath)
|
||||
err := gitRepo.RemoveFilesFromIndex(ctx, oldWikiPath)
|
||||
if err != nil {
|
||||
log.Error("RemoveFilesFromIndex failed: %v", err)
|
||||
return err
|
||||
@@ -170,18 +170,18 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
|
||||
// FIXME: The wiki doesn't have lfs support at present - if this changes need to check attributes here
|
||||
|
||||
objectHash, err := gitRepo.HashObjectBytes([]byte(content))
|
||||
objectHash, err := gitRepo.HashObjectBytes(ctx, []byte(content))
|
||||
if err != nil {
|
||||
log.Error("HashObject failed: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := gitRepo.AddObjectToIndex("100644", objectHash, newWikiPath); err != nil {
|
||||
if err := gitRepo.AddObjectToIndex(ctx, "100644", objectHash, newWikiPath); err != nil {
|
||||
log.Error("AddObjectToIndex failed: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
tree, err := gitRepo.WriteTree()
|
||||
tree, err := gitRepo.WriteTree(ctx)
|
||||
if err != nil {
|
||||
log.Error("WriteTree failed: %v", err)
|
||||
return err
|
||||
@@ -212,7 +212,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
commitTreeOpts.Parents = []string{"HEAD"}
|
||||
}
|
||||
|
||||
commitHash, err := gitRepo.CommitTree(doer.NewGitSig(), committer, tree, commitTreeOpts)
|
||||
commitHash, err := gitRepo.CommitTree(ctx, doer.NewGitSig(), committer, tree, commitTreeOpts)
|
||||
if err != nil {
|
||||
log.Error("CommitTree failed: %v", err)
|
||||
return err
|
||||
@@ -282,24 +282,24 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
return fmt.Errorf("failed to clone repository: %s (%w)", repo.FullName(), err)
|
||||
}
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx, basePath)
|
||||
gitRepo, err := git.OpenRepository(basePath)
|
||||
if err != nil {
|
||||
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
|
||||
return fmt.Errorf("failed to open new temporary repository in: %s %w", basePath, err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil {
|
||||
if err := gitRepo.ReadTreeToIndex(ctx, "HEAD"); err != nil {
|
||||
log.Error("Unable to read HEAD tree to index in: %s %v", basePath, err)
|
||||
return fmt.Errorf("unable to read HEAD tree to index in: %s %w", basePath, err)
|
||||
}
|
||||
|
||||
found, wikiPath, err := prepareGitPath(gitRepo, repo.DefaultWikiBranch, wikiName)
|
||||
found, wikiPath, err := prepareGitPath(ctx, gitRepo, repo.DefaultWikiBranch, wikiName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if found {
|
||||
err := gitRepo.RemoveFilesFromIndex(wikiPath)
|
||||
err := gitRepo.RemoveFilesFromIndex(ctx, wikiPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -309,7 +309,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
|
||||
// FIXME: The wiki doesn't have lfs support at present - if this changes need to check attributes here
|
||||
|
||||
tree, err := gitRepo.WriteTree()
|
||||
tree, err := gitRepo.WriteTree(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -337,12 +337,12 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
commitTreeOpts.NoGPGSign = true
|
||||
}
|
||||
|
||||
commitHash, err := gitRepo.CommitTree(doer.NewGitSig(), committer, tree, commitTreeOpts)
|
||||
commitHash, err := gitRepo.CommitTree(ctx, doer.NewGitSig(), committer, tree, commitTreeOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := gitrepo.PushFromLocal(gitRepo.Ctx, basePath, repo.WikiStorageRepo(), git.PushOptions{
|
||||
if err := gitrepo.PushFromLocal(ctx, basePath, repo.WikiStorageRepo(), git.PushOptions{
|
||||
Branch: fmt.Sprintf("%s:%s%s", commitHash.String(), git.BranchPrefix, repo.DefaultWikiBranch),
|
||||
Env: repo_module.FullPushingEnvironment(
|
||||
doer,
|
||||
|
||||
+10
-10
@@ -167,11 +167,11 @@ func TestRepository_AddWikiPage(t *testing.T) {
|
||||
webPath := UserTitleToWebPath("", userTitle)
|
||||
assert.NoError(t, AddWikiPage(t.Context(), doer, repo, webPath, wikiContent, commitMsg))
|
||||
// Now need to show that the page has been added:
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo.WikiStorageRepo())
|
||||
gitRepo, err := gitrepo.OpenRepository(repo.WikiStorageRepo())
|
||||
require.NoError(t, err)
|
||||
|
||||
defer gitRepo.Close()
|
||||
masterTree, err := gitRepo.GetTree(repo.DefaultWikiBranch)
|
||||
masterTree, err := gitRepo.GetTree(t.Context(), repo.DefaultWikiBranch)
|
||||
assert.NoError(t, err)
|
||||
gitPath := WebPathToGitPath(webPath)
|
||||
entry, err := masterTree.GetTreeEntryByPath(t.Context(), gitRepo, gitPath)
|
||||
@@ -214,9 +214,9 @@ func TestRepository_EditWikiPage(t *testing.T) {
|
||||
assert.NoError(t, EditWikiPage(t.Context(), doer, repo, "Home", webPath, newWikiContent, commitMsg))
|
||||
|
||||
// Now need to show that the page has been added:
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo.WikiStorageRepo())
|
||||
gitRepo, err := gitrepo.OpenRepository(repo.WikiStorageRepo())
|
||||
assert.NoError(t, err)
|
||||
masterTree, err := gitRepo.GetTree(repo.DefaultWikiBranch)
|
||||
masterTree, err := gitRepo.GetTree(t.Context(), repo.DefaultWikiBranch)
|
||||
assert.NoError(t, err)
|
||||
gitPath := WebPathToGitPath(webPath)
|
||||
entry, err := masterTree.GetTreeEntryByPath(t.Context(), gitRepo, gitPath)
|
||||
@@ -238,11 +238,11 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
|
||||
assert.NoError(t, DeleteWikiPage(t.Context(), doer, repo, "Home"))
|
||||
|
||||
// Now need to show that the page has been added:
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo.WikiStorageRepo())
|
||||
gitRepo, err := gitrepo.OpenRepository(repo.WikiStorageRepo())
|
||||
require.NoError(t, err)
|
||||
|
||||
defer gitRepo.Close()
|
||||
masterTree, err := gitRepo.GetTree(repo.DefaultWikiBranch)
|
||||
masterTree, err := gitRepo.GetTree(t.Context(), repo.DefaultWikiBranch)
|
||||
assert.NoError(t, err)
|
||||
gitPath := WebPathToGitPath("Home")
|
||||
_, err = masterTree.GetTreeEntryByPath(t.Context(), gitRepo, gitPath)
|
||||
@@ -252,7 +252,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
|
||||
func TestPrepareWikiFileName(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo.WikiStorageRepo())
|
||||
gitRepo, err := gitrepo.OpenRepository(repo.WikiStorageRepo())
|
||||
require.NoError(t, err)
|
||||
|
||||
defer gitRepo.Close()
|
||||
@@ -279,7 +279,7 @@ func TestPrepareWikiFileName(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
webPath := UserTitleToWebPath("", tt.arg)
|
||||
existence, newWikiPath, err := prepareGitPath(gitRepo, repo.DefaultWikiBranch, webPath)
|
||||
existence, newWikiPath, err := prepareGitPath(t.Context(), gitRepo, repo.DefaultWikiBranch, webPath)
|
||||
if (err != nil) != tt.wantErr {
|
||||
assert.NoError(t, err)
|
||||
return
|
||||
@@ -305,12 +305,12 @@ func TestPrepareWikiFileName_FirstPage(t *testing.T) {
|
||||
err := git.InitRepository(t.Context(), tmpDir, true, git.Sha1ObjectFormat.Name())
|
||||
assert.NoError(t, err)
|
||||
|
||||
gitRepo, err := git.OpenRepository(t.Context(), tmpDir)
|
||||
gitRepo, err := git.OpenRepository(tmpDir)
|
||||
require.NoError(t, err)
|
||||
|
||||
defer gitRepo.Close()
|
||||
|
||||
existence, newWikiPath, err := prepareGitPath(gitRepo, "master", "Home")
|
||||
existence, newWikiPath, err := prepareGitPath(t.Context(), gitRepo, "master", "Home")
|
||||
assert.False(t, existence)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Home.md", newWikiPath)
|
||||
|
||||
Reference in New Issue
Block a user