aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo
diff options
context:
space:
mode:
authorJason Song <i@wolfogre.com>2023-01-09 11:50:54 +0800
committerGitHub <noreply@github.com>2023-01-09 11:50:54 +0800
commit7adc2de46404e32ed33f999d308ed56232cdfea5 (patch)
tree2404a22b5fa8a941eb5bfd16fd717fab29d899e4 /routers/web/repo
parentb878155b8741c2769b6aa50a80609c36822451c9 (diff)
downloadgitea-7adc2de46404e32ed33f999d308ed56232cdfea5.tar.gz
gitea-7adc2de46404e32ed33f999d308ed56232cdfea5.zip
Use context parameter in models/git (#22367)
After #22362, we can feel free to use transactions without `db.DefaultContext`. And there are still lots of models using `db.DefaultContext`, I think we should refactor them carefully and one by one. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'routers/web/repo')
-rw-r--r--routers/web/repo/branch.go6
-rw-r--r--routers/web/repo/commit.go6
-rw-r--r--routers/web/repo/compare.go2
-rw-r--r--routers/web/repo/download.go2
-rw-r--r--routers/web/repo/issue.go4
-rw-r--r--routers/web/repo/lfs.go22
-rw-r--r--routers/web/repo/pull.go2
-rw-r--r--routers/web/repo/setting_protected_branch.go6
-rw-r--r--routers/web/repo/tag.go6
-rw-r--r--routers/web/repo/view.go4
-rw-r--r--routers/web/repo/wiki.go2
11 files changed, 31 insertions, 31 deletions
diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go
index 18bb06ed1a..8b48d3fb00 100644
--- a/routers/web/repo/branch.go
+++ b/routers/web/repo/branch.go
@@ -120,7 +120,7 @@ func RestoreBranchPost(ctx *context.Context) {
branchID := ctx.FormInt64("branch_id")
branchName := ctx.FormString("name")
- deletedBranch, err := git_model.GetDeletedBranchByID(ctx.Repo.Repository.ID, branchID)
+ deletedBranch, err := git_model.GetDeletedBranchByID(ctx, ctx.Repo.Repository.ID, branchID)
if err != nil {
log.Error("GetDeletedBranchByID: %v", err)
ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName))
@@ -189,7 +189,7 @@ func loadBranches(ctx *context.Context, skip, limit int) (*Branch, []*Branch, in
return nil, nil, 0
}
- protectedBranches, err := git_model.GetProtectedBranches(ctx.Repo.Repository.ID)
+ protectedBranches, err := git_model.GetProtectedBranches(ctx, ctx.Repo.Repository.ID)
if err != nil {
ctx.ServerError("GetProtectedBranches", err)
return nil, nil, 0
@@ -331,7 +331,7 @@ func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, p
func getDeletedBranches(ctx *context.Context) ([]*Branch, error) {
branches := []*Branch{}
- deletedBranches, err := git_model.GetDeletedBranches(ctx.Repo.Repository.ID)
+ deletedBranches, err := git_model.GetDeletedBranches(ctx, ctx.Repo.Repository.ID)
if err != nil {
return branches, err
}
diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go
index 6eda3fca10..9f94159d0d 100644
--- a/routers/web/repo/commit.go
+++ b/routers/web/repo/commit.go
@@ -75,7 +75,7 @@ func Commits(ctx *context.Context) {
ctx.ServerError("CommitsByRange", err)
return
}
- ctx.Data["Commits"] = git_model.ConvertFromGitCommit(commits, ctx.Repo.Repository)
+ ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commits, ctx.Repo.Repository)
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
@@ -194,7 +194,7 @@ func SearchCommits(ctx *context.Context) {
return
}
ctx.Data["CommitCount"] = len(commits)
- ctx.Data["Commits"] = git_model.ConvertFromGitCommit(commits, ctx.Repo.Repository)
+ ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commits, ctx.Repo.Repository)
ctx.Data["Keyword"] = query
if all {
@@ -235,7 +235,7 @@ func FileHistory(ctx *context.Context) {
ctx.ServerError("CommitsByFileAndRange", err)
return
}
- ctx.Data["Commits"] = git_model.ConvertFromGitCommit(commits, ctx.Repo.Repository)
+ ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commits, ctx.Repo.Repository)
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index d95eeaecc9..8d45f8d674 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -636,7 +636,7 @@ func PrepareCompareDiff(
return false
}
- commits := git_model.ConvertFromGitCommit(ci.CompareInfo.Commits, ci.HeadRepo)
+ commits := git_model.ConvertFromGitCommit(ctx, ci.CompareInfo.Commits, ci.HeadRepo)
ctx.Data["Commits"] = commits
ctx.Data["CommitCount"] = len(commits)
diff --git a/routers/web/repo/download.go b/routers/web/repo/download.go
index c1e9ba58b9..9e95f9dd0c 100644
--- a/routers/web/repo/download.go
+++ b/routers/web/repo/download.go
@@ -41,7 +41,7 @@ func ServeBlobOrLFS(ctx *context.Context, blob *git.Blob, lastModified time.Time
pointer, _ := lfs.ReadPointer(dataRc)
if pointer.IsValid() {
- meta, _ := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid)
+ meta, _ := git_model.GetLFSMetaObjectByOid(ctx, ctx.Repo.Repository.ID, pointer.Oid)
if meta == nil {
if err = dataRc.Close(); err != nil {
log.Error("ServeBlobOrLFS: Close: %v", err)
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index 100e343de4..07dd98f1a5 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -1604,7 +1604,7 @@ func ViewIssue(ctx *context.Context) {
if perm.CanWrite(unit.TypeCode) {
// Check if branch is not protected
if pull.HeadBranch != pull.HeadRepo.DefaultBranch {
- if protected, err := git_model.IsProtectedBranch(pull.HeadRepo.ID, pull.HeadBranch); err != nil {
+ if protected, err := git_model.IsProtectedBranch(ctx, pull.HeadRepo.ID, pull.HeadBranch); err != nil {
log.Error("IsProtectedBranch: %v", err)
} else if !protected {
canDelete = true
@@ -1688,7 +1688,7 @@ func ViewIssue(ctx *context.Context) {
if pull.ProtectedBranch != nil {
var showMergeInstructions bool
if ctx.Doer != nil {
- showMergeInstructions = pull.ProtectedBranch.CanUserPush(ctx.Doer.ID)
+ showMergeInstructions = pull.ProtectedBranch.CanUserPush(ctx, ctx.Doer.ID)
}
ctx.Data["IsBlockedByApprovals"] = !issues_model.HasEnoughApprovals(ctx, pull.ProtectedBranch, pull)
ctx.Data["IsBlockedByRejection"] = issues_model.MergeBlockedByRejectedReview(ctx, pull.ProtectedBranch, pull)
diff --git a/routers/web/repo/lfs.go b/routers/web/repo/lfs.go
index 82e0055ab2..41d5edcdd8 100644
--- a/routers/web/repo/lfs.go
+++ b/routers/web/repo/lfs.go
@@ -48,7 +48,7 @@ func LFSFiles(ctx *context.Context) {
if page <= 1 {
page = 1
}
- total, err := git_model.CountLFSMetaObjects(ctx.Repo.Repository.ID)
+ total, err := git_model.CountLFSMetaObjects(ctx, ctx.Repo.Repository.ID)
if err != nil {
ctx.ServerError("LFSFiles", err)
return
@@ -58,7 +58,7 @@ func LFSFiles(ctx *context.Context) {
pager := context.NewPagination(int(total), setting.UI.ExplorePagingNum, page, 5)
ctx.Data["Title"] = ctx.Tr("repo.settings.lfs")
ctx.Data["PageIsSettingsLFS"] = true
- lfsMetaObjects, err := git_model.GetLFSMetaObjects(ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum)
+ lfsMetaObjects, err := git_model.GetLFSMetaObjects(ctx, ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum)
if err != nil {
ctx.ServerError("LFSFiles", err)
return
@@ -80,7 +80,7 @@ func LFSLocks(ctx *context.Context) {
if page <= 1 {
page = 1
}
- total, err := git_model.CountLFSLockByRepoID(ctx.Repo.Repository.ID)
+ total, err := git_model.CountLFSLockByRepoID(ctx, ctx.Repo.Repository.ID)
if err != nil {
ctx.ServerError("LFSLocks", err)
return
@@ -90,7 +90,7 @@ func LFSLocks(ctx *context.Context) {
pager := context.NewPagination(int(total), setting.UI.ExplorePagingNum, page, 5)
ctx.Data["Title"] = ctx.Tr("repo.settings.lfs_locks")
ctx.Data["PageIsSettingsLFS"] = true
- lfsLocks, err := git_model.GetLFSLockByRepoID(ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum)
+ lfsLocks, err := git_model.GetLFSLockByRepoID(ctx, ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum)
if err != nil {
ctx.ServerError("LFSLocks", err)
return
@@ -214,7 +214,7 @@ func LFSLockFile(ctx *context.Context) {
return
}
- _, err := git_model.CreateLFSLock(ctx.Repo.Repository, &git_model.LFSLock{
+ _, err := git_model.CreateLFSLock(ctx, ctx.Repo.Repository, &git_model.LFSLock{
Path: lockPath,
OwnerID: ctx.Doer.ID,
})
@@ -236,7 +236,7 @@ func LFSUnlock(ctx *context.Context) {
ctx.NotFound("LFSUnlock", nil)
return
}
- _, err := git_model.DeleteLFSLockByID(ctx.ParamsInt64("lid"), ctx.Repo.Repository, ctx.Doer, true)
+ _, err := git_model.DeleteLFSLockByID(ctx, ctx.ParamsInt64("lid"), ctx.Repo.Repository, ctx.Doer, true)
if err != nil {
ctx.ServerError("LFSUnlock", err)
return
@@ -261,7 +261,7 @@ func LFSFileGet(ctx *context.Context) {
ctx.Data["Title"] = oid
ctx.Data["PageIsSettingsLFS"] = true
- meta, err := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, oid)
+ meta, err := git_model.GetLFSMetaObjectByOid(ctx, ctx.Repo.Repository.ID, oid)
if err != nil {
if err == git_model.ErrLFSObjectNotExist {
ctx.NotFound("LFSFileGet", nil)
@@ -355,7 +355,7 @@ func LFSDelete(ctx *context.Context) {
return
}
- count, err := git_model.RemoveLFSMetaObjectByOid(ctx.Repo.Repository.ID, oid)
+ count, err := git_model.RemoveLFSMetaObjectByOid(ctx, ctx.Repo.Repository.ID, oid)
if err != nil {
ctx.ServerError("LFSDelete", err)
return
@@ -454,7 +454,7 @@ func LFSPointerFiles(ctx *context.Context) {
Size: pointerBlob.Size,
}
- if _, err := git_model.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid); err != nil {
+ if _, err := git_model.GetLFSMetaObjectByOid(ctx, repo.ID, pointerBlob.Oid); err != nil {
if err != git_model.ErrLFSObjectNotExist {
return err
}
@@ -472,7 +472,7 @@ func LFSPointerFiles(ctx *context.Context) {
// Can we fix?
// OK well that's "simple"
// - we need to check whether current user has access to a repo that has access to the file
- result.Associatable, err = git_model.LFSObjectAccessible(ctx.Doer, pointerBlob.Oid)
+ result.Associatable, err = git_model.LFSObjectAccessible(ctx, ctx.Doer, pointerBlob.Oid)
if err != nil {
return err
}
@@ -547,7 +547,7 @@ func LFSAutoAssociate(ctx *context.Context) {
metas[i].Oid = oid[:idx]
// metas[i].RepositoryID = ctx.Repo.Repository.ID
}
- if err := git_model.LFSAutoAssociate(metas, ctx.Doer, ctx.Repo.Repository.ID); err != nil {
+ if err := git_model.LFSAutoAssociate(ctx, metas, ctx.Doer, ctx.Repo.Repository.ID); err != nil {
ctx.ServerError("LFSAutoAssociate", err)
return
}
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index a18f9f6a56..c0fab2cead 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -659,7 +659,7 @@ func ViewPullCommits(ctx *context.Context) {
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
- commits := git_model.ConvertFromGitCommit(prInfo.Commits, ctx.Repo.Repository)
+ commits := git_model.ConvertFromGitCommit(ctx, prInfo.Commits, ctx.Repo.Repository)
ctx.Data["Commits"] = commits
ctx.Data["CommitCount"] = len(commits)
diff --git a/routers/web/repo/setting_protected_branch.go b/routers/web/repo/setting_protected_branch.go
index 975873a9ef..e0467a23e6 100644
--- a/routers/web/repo/setting_protected_branch.go
+++ b/routers/web/repo/setting_protected_branch.go
@@ -31,7 +31,7 @@ func ProtectedBranch(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsBranches"] = true
- protectedBranches, err := git_model.GetProtectedBranches(ctx.Repo.Repository.ID)
+ protectedBranches, err := git_model.GetProtectedBranches(ctx, ctx.Repo.Repository.ID)
if err != nil {
ctx.ServerError("GetProtectedBranches", err)
return
@@ -134,7 +134,7 @@ func SettingsProtectedBranch(c *context.Context) {
c.Data["whitelist_users"] = strings.Join(base.Int64sToStrings(protectBranch.WhitelistUserIDs), ",")
c.Data["merge_whitelist_users"] = strings.Join(base.Int64sToStrings(protectBranch.MergeWhitelistUserIDs), ",")
c.Data["approvals_whitelist_users"] = strings.Join(base.Int64sToStrings(protectBranch.ApprovalsWhitelistUserIDs), ",")
- contexts, _ := git_model.FindRepoRecentCommitStatusContexts(c.Repo.Repository.ID, 7*24*time.Hour) // Find last week status check contexts
+ contexts, _ := git_model.FindRepoRecentCommitStatusContexts(c, c.Repo.Repository.ID, 7*24*time.Hour) // Find last week status check contexts
for _, ctx := range protectBranch.StatusCheckContexts {
var found bool
for i := range contexts {
@@ -281,7 +281,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) {
ctx.Redirect(fmt.Sprintf("%s/settings/branches/%s", ctx.Repo.RepoLink, util.PathEscapeSegments(branch)))
} else {
if protectBranch != nil {
- if err := git_model.DeleteProtectedBranch(ctx.Repo.Repository.ID, protectBranch.ID); err != nil {
+ if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository.ID, protectBranch.ID); err != nil {
ctx.ServerError("DeleteProtectedBranch", err)
return
}
diff --git a/routers/web/repo/tag.go b/routers/web/repo/tag.go
index 26df1dbf6c..aa9edc7375 100644
--- a/routers/web/repo/tag.go
+++ b/routers/web/repo/tag.go
@@ -54,7 +54,7 @@ func NewProtectedTagPost(ctx *context.Context) {
pt.AllowlistTeamIDs, _ = base.StringsToInt64s(strings.Split(form.AllowlistTeams, ","))
}
- if err := git_model.InsertProtectedTag(pt); err != nil {
+ if err := git_model.InsertProtectedTag(ctx, pt); err != nil {
ctx.ServerError("InsertProtectedTag", err)
return
}
@@ -107,7 +107,7 @@ func EditProtectedTagPost(ctx *context.Context) {
pt.AllowlistUserIDs, _ = base.StringsToInt64s(strings.Split(form.AllowlistUsers, ","))
pt.AllowlistTeamIDs, _ = base.StringsToInt64s(strings.Split(form.AllowlistTeams, ","))
- if err := git_model.UpdateProtectedTag(pt); err != nil {
+ if err := git_model.UpdateProtectedTag(ctx, pt); err != nil {
ctx.ServerError("UpdateProtectedTag", err)
return
}
@@ -168,7 +168,7 @@ func selectProtectedTagByContext(ctx *context.Context) *git_model.ProtectedTag {
id = ctx.ParamsInt64(":id")
}
- tag, err := git_model.GetProtectedTagByID(id)
+ tag, err := git_model.GetProtectedTagByID(ctx, id)
if err != nil {
ctx.ServerError("GetProtectedTagByID", err)
return nil
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index 915944e4d5..769e4e895c 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -271,7 +271,7 @@ func getFileReader(repoID int64, blob *git.Blob) ([]byte, io.ReadCloser, *fileIn
return buf, dataRc, &fileInfo{isTextFile, false, blob.Size(), nil, st}, nil
}
- meta, err := git_model.GetLFSMetaObjectByOid(repoID, pointer.Oid)
+ meta, err := git_model.GetLFSMetaObjectByOid(db.DefaultContext, repoID, pointer.Oid)
if err != nil && err != git_model.ErrLFSObjectNotExist { // fallback to plain file
return buf, dataRc, &fileInfo{isTextFile, false, blob.Size(), nil, st}, nil
}
@@ -412,7 +412,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
}
// Check LFS Lock
- lfsLock, err := git_model.GetTreePathLock(ctx.Repo.Repository.ID, ctx.Repo.TreePath)
+ lfsLock, err := git_model.GetTreePathLock(ctx, ctx.Repo.Repository.ID, ctx.Repo.TreePath)
ctx.Data["LFSLock"] = lfsLock
if err != nil {
ctx.ServerError("GetTreePathLock", err)
diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go
index b50a4be802..fe2becb7bb 100644
--- a/routers/web/repo/wiki.go
+++ b/routers/web/repo/wiki.go
@@ -368,7 +368,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
ctx.ServerError("CommitsByFileAndRange", err)
return nil, nil
}
- ctx.Data["Commits"] = git_model.ConvertFromGitCommit(commitsHistory, ctx.Repo.Repository)
+ ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commitsHistory, ctx.Repo.Repository)
pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5)
pager.SetDefaultParams(ctx)