aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo/release.go
diff options
context:
space:
mode:
authoroliverpool <3864879+oliverpool@users.noreply.github.com>2023-04-22 18:30:24 +0200
committerGitHub <noreply@github.com>2023-04-22 12:30:24 -0400
commit077160b8384f100aa1327a86d6d3c08969e679c2 (patch)
tree7f23352a64968fa21fa77b6adb993e076dfc5803 /routers/web/repo/release.go
parentda4448421e30c2a58095a93e2e5cc4da66fc9347 (diff)
downloadgitea-077160b8384f100aa1327a86d6d3c08969e679c2.tar.gz
gitea-077160b8384f100aa1327a86d6d3c08969e679c2.zip
fix calReleaseNumCommitsBehind (#24148) (#24197)
Backport #24148 `repoCtx.CommitsCount` is not reliably the commit count of the default branch (Repository.GetCommitsCount depends on what is currently displayed). _contributed in the context of @forgejo_ --------- Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'routers/web/repo/release.go')
-rw-r--r--routers/web/repo/release.go9
1 files changed, 2 insertions, 7 deletions
diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go
index 63c8797fe5..92b67baff6 100644
--- a/routers/web/repo/release.go
+++ b/routers/web/repo/release.go
@@ -35,15 +35,10 @@ const (
// calReleaseNumCommitsBehind calculates given release has how many commits behind release target.
func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *repo_model.Release, countCache map[string]int64) error {
- // Fast return if release target is same as default branch.
- if repoCtx.BranchName == release.Target {
- release.NumCommitsBehind = repoCtx.CommitsCount - release.NumCommits
- return nil
- }
-
// Get count if not exists
if _, ok := countCache[release.Target]; !ok {
- if repoCtx.GitRepo.IsBranchExist(release.Target) {
+ // short-circuit for the default branch
+ if repoCtx.Repository.DefaultBranch == release.Target || repoCtx.GitRepo.IsBranchExist(release.Target) {
commit, err := repoCtx.GitRepo.GetBranchCommit(release.Target)
if err != nil {
return fmt.Errorf("GetBranchCommit: %w", err)