From 8a66fea7a04ec9ea3f3347fd18ab6d400046d9ba Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 11 Mar 2023 17:35:40 +0800 Subject: [PATCH 1/4] fix --- routers/web/repo/branch.go | 15 ++++++--------- templates/repo/branch/list.tmpl | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index d23367e04790d..9b43b8a03ba70 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,15 +66,11 @@ 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 } @@ -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")), }) } diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index a093c19deb8cc..ce8c52d804cdf 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -123,13 +123,13 @@ {{end}} {{if and $.IsWriter (not $.IsMirror) (not $.Repository.IsArchived) (not .IsProtected)}} {{if .IsDeleted}} - {{else}} - {{end}} From 7ae5bc037549143379852d55aa8fd9dc5cbb2b98 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 11 Mar 2023 17:42:20 +0800 Subject: [PATCH 2/4] fix variable names --- modules/context/pagination.go | 7 ++++--- routers/web/repo/branch.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/context/pagination.go b/modules/context/pagination.go index 3effd88f109cf..9f139e3aaaa31 100644 --- a/modules/context/pagination.go +++ b/modules/context/pagination.go @@ -18,10 +18,11 @@ type Pagination struct { urlParams []string } -// NewPagination creates a new instance of the Pagination struct -func NewPagination(total, page, issueNum, numPages int) *Pagination { +// NewPagination creates a new instance of the Pagination struct. +// "pagingNum" is "page size / limit", "current" is "page" +func NewPagination(total, pagingNum, current, numPages int) *Pagination { p := &Pagination{} - p.Paginater = paginator.New(total, page, issueNum, numPages) + p.Paginater = paginator.New(total, pagingNum, current, numPages) return p } diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index 9b43b8a03ba70..9f26634311125 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -76,7 +76,7 @@ func Branches(ctx *context.Context) { } 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 From 9e5a9ccdc34934e40a6b9fa95cda74425e7f13df Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 11 Mar 2023 17:46:33 +0800 Subject: [PATCH 3/4] fix wrong tag --- templates/repo/branch/list.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index ce8c52d804cdf..548d328550ce8 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -81,9 +81,9 @@ {{if not .LatestPullRequest}} {{if .IsIncluded}} - + {{svg "octicon-git-pull-request"}} {{$.locale.Tr "repo.branch.included"}} - + {{else if and (not .IsDeleted) $.AllowsPulls (gt .CommitsAhead 0)}} From b4937ab23d5fea511a9f882b9d66cfae9ef3b7e9 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 14 Mar 2023 11:18:15 +0800 Subject: [PATCH 4/4] clarify comment --- modules/context/pagination.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/context/pagination.go b/modules/context/pagination.go index 9f139e3aaaa31..5a88c92053aa7 100644 --- a/modules/context/pagination.go +++ b/modules/context/pagination.go @@ -19,7 +19,7 @@ type Pagination struct { } // NewPagination creates a new instance of the Pagination struct. -// "pagingNum" is "page size / limit", "current" is "page" +// "pagingNum" is "page size" or "limit", "current" is "page" func NewPagination(total, pagingNum, current, numPages int) *Pagination { p := &Pagination{} p.Paginater = paginator.New(total, pagingNum, current, numPages)