aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-03-14 13:11:38 +0800
committerGitHub <noreply@github.com>2023-03-14 13:11:38 +0800
commit6ff5400af91aefb02cbc7dd59f6be23cc2bf7865 (patch)
treef16e7e5223ac37bc795a96679309eecc8ce67a12 /routers
parent0efa9d564941e6539df98ed4ddd906a05c1fa7e7 (diff)
downloadgitea-6ff5400af91aefb02cbc7dd59f6be23cc2bf7865.tar.gz
gitea-6ff5400af91aefb02cbc7dd59f6be23cc2bf7865.zip
Make branches list page operations remember current page (#23420)
Close #23411 Always pass "page" query parameter to backend, and make backend respect it. The `ctx.FormInt("limit")` is never used, so removed. --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/branch.go17
1 files changed, 7 insertions, 10 deletions
diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go
index d23367e047..9f26634311 100644
--- a/routers/web/repo/branch.go
+++ b/routers/web/repo/branch.go
@@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"net/http"
+ "net/url"
"strings"
"code.gitea.io/gitea/models"
@@ -65,21 +66,17 @@ func Branches(ctx *context.Context) {
if page <= 1 {
page = 1
}
+ pageSize := setting.Git.BranchesRangeSize
- limit := ctx.FormInt("limit")
- if limit <= 0 || limit > setting.Git.BranchesRangeSize {
- limit = setting.Git.BranchesRangeSize
- }
-
- skip := (page - 1) * limit
- log.Debug("Branches: skip: %d limit: %d", skip, limit)
- defaultBranchBranch, branches, branchesCount := loadBranches(ctx, skip, limit)
+ skip := (page - 1) * pageSize
+ log.Debug("Branches: skip: %d limit: %d", skip, pageSize)
+ defaultBranchBranch, branches, branchesCount := loadBranches(ctx, skip, pageSize)
if ctx.Written() {
return
}
ctx.Data["Branches"] = branches
ctx.Data["DefaultBranchBranch"] = defaultBranchBranch
- pager := context.NewPagination(branchesCount, setting.Git.BranchesRangeSize, page, 5)
+ pager := context.NewPagination(branchesCount, pageSize, page, 5)
pager.SetDefaultParams(ctx)
ctx.Data["Page"] = pager
@@ -165,7 +162,7 @@ func RestoreBranchPost(ctx *context.Context) {
func redirect(ctx *context.Context) {
ctx.JSON(http.StatusOK, map[string]interface{}{
- "redirect": ctx.Repo.RepoLink + "/branches",
+ "redirect": ctx.Repo.RepoLink + "/branches?page=" + url.QueryEscape(ctx.FormString("page")),
})
}