Skip to content

Commit bb27838

Browse files
oliverpoolGiteaBotlunny
authored
fix calReleaseNumCommitsBehind (#24148)
`repoCtx.CommitsCount` is not reliably the commit count of the default branch (Repository.GetCommitsCount depends on what is currently displayed). For instance on the releases page the commit count is correct: https://codeberg.org/Codeberg/pages-server/releases ![2023-04-15-215027](https://user-images.githubusercontent.com/3864879/232250500-6c05dc00-7030-4ec9-87f1-18c7797d36bf.png) However it is not on the single page: https://codeberg.org/Codeberg/pages-server/releases/tag/v4.6.2 ![2023-04-15-215036](https://user-images.githubusercontent.com/3864879/232250503-620c8038-7c2c-45a1-b99d-cb994ef955a6.png) This PR fixes this by removing a "fast branch" which was using this field (I think this field should be removed, since it is a bit unpredictable - but this would mean a larger refactoring PR). _contributed in the context of @forgejo_ --------- Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
1 parent 75b9845 commit bb27838

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+933
-21
lines changed

models/db/iterate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestIterate(t *testing.T) {
2525
return nil
2626
})
2727
assert.NoError(t, err)
28-
assert.EqualValues(t, 84, repoCnt)
28+
assert.EqualValues(t, 89, repoCnt)
2929

3030
err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repoUnit *repo_model.RepoUnit) error {
3131
reopUnit2 := repo_model.RepoUnit{ID: repoUnit.ID}

models/db/list_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ func TestFind(t *testing.T) {
3535
var repoUnits []repo_model.RepoUnit
3636
err := db.Find(db.DefaultContext, &opts, &repoUnits)
3737
assert.NoError(t, err)
38-
assert.EqualValues(t, 84, len(repoUnits))
38+
assert.EqualValues(t, 89, len(repoUnits))
3939

4040
cnt, err := db.Count(db.DefaultContext, &opts, new(repo_model.RepoUnit))
4141
assert.NoError(t, err)
42-
assert.EqualValues(t, 84, cnt)
42+
assert.EqualValues(t, 89, cnt)
4343

4444
repoUnits = make([]repo_model.RepoUnit, 0, 10)
4545
newCnt, err := db.FindAndCount(db.DefaultContext, &opts, &repoUnits)

models/fixtures/release.yml

+42
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,45 @@
6666
is_prerelease: true
6767
is_tag: false
6868
created_unix: 946684800
69+
70+
- id: 6
71+
repo_id: 57
72+
publisher_id: 2
73+
tag_name: "v1.0"
74+
lower_tag_name: "v1.0"
75+
target: "main"
76+
title: "v1.0"
77+
sha1: "a8a700e8c644c783ba2c6e742bb81bf91e244bff"
78+
num_commits: 3
79+
is_draft: false
80+
is_prerelease: false
81+
is_tag: false
82+
created_unix: 946684801
83+
84+
- id: 7
85+
repo_id: 57
86+
publisher_id: 2
87+
tag_name: "v1.1"
88+
lower_tag_name: "v1.1"
89+
target: "main"
90+
title: "v1.1"
91+
sha1: "cef06e48f2642cd0dc9597b4bea09f4b3f74aad6"
92+
num_commits: 5
93+
is_draft: false
94+
is_prerelease: false
95+
is_tag: false
96+
created_unix: 946684802
97+
98+
- id: 8
99+
repo_id: 57
100+
publisher_id: 2
101+
tag_name: "v2.0"
102+
lower_tag_name: "v2.0"
103+
target: "main"
104+
title: "v2.0"
105+
sha1: "7197b56fdc75b453f47c9110938cb46a303579fd"
106+
num_commits: 6
107+
is_draft: false
108+
is_prerelease: false
109+
is_tag: false
110+
created_unix: 946684803

models/fixtures/repo_unit.yml

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# See models/unit/unit.go for the meaning of the type
12
-
23
id: 1
34
repo_id: 1
@@ -575,3 +576,28 @@
575576
repo_id: 56
576577
type: 1
577578
created_unix: 946684810
579+
-
580+
id: 85
581+
repo_id: 57
582+
type: 1
583+
created_unix: 946684810
584+
-
585+
id: 86
586+
repo_id: 57
587+
type: 2
588+
created_unix: 946684810
589+
-
590+
id: 87
591+
repo_id: 57
592+
type: 3
593+
created_unix: 946684810
594+
-
595+
id: 88
596+
repo_id: 57
597+
type: 4
598+
created_unix: 946684810
599+
-
600+
id: 89
601+
repo_id: 57
602+
type: 5
603+
created_unix: 946684810

models/fixtures/repository.yml

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# don't forget to add fixtures in repo_unit.yml
12
-
23
id: 1
34
owner_id: 2
@@ -1647,3 +1648,16 @@
16471648
is_private: true
16481649
status: 0
16491650
num_issues: 0
1651+
1652+
-
1653+
id: 57
1654+
owner_id: 2
1655+
owner_name: user2
1656+
lower_name: repo-release
1657+
name: repo-release
1658+
default_branch: main
1659+
is_empty: false
1660+
is_archived: false
1661+
is_private: false
1662+
status: 0
1663+
num_issues: 0

models/fixtures/user.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
num_followers: 2
6767
num_following: 1
6868
num_stars: 2
69-
num_repos: 12
69+
num_repos: 13
7070
num_teams: 0
7171
num_members: 0
7272
visibility: 0

models/repo/repo_list_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ func TestSearchRepository(t *testing.T) {
235235
{
236236
name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
237237
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse},
238-
count: 29,
238+
count: 30,
239239
},
240240
{
241241
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
242242
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse},
243-
count: 34,
243+
count: 35,
244244
},
245245
{
246246
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
@@ -255,7 +255,7 @@ func TestSearchRepository(t *testing.T) {
255255
{
256256
name: "AllPublic/PublicRepositoriesOfOrganization",
257257
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse},
258-
count: 29,
258+
count: 30,
259259
},
260260
{
261261
name: "AllTemplates",

routers/web/repo/release.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@ const (
3535

3636
// calReleaseNumCommitsBehind calculates given release has how many commits behind release target.
3737
func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *repo_model.Release, countCache map[string]int64) error {
38-
// Fast return if release target is same as default branch.
39-
if repoCtx.BranchName == release.Target {
40-
release.NumCommitsBehind = repoCtx.CommitsCount - release.NumCommits
41-
return nil
42-
}
43-
4438
// Get count if not exists
4539
if _, ok := countCache[release.Target]; !ok {
46-
if repoCtx.GitRepo.IsBranchExist(release.Target) {
40+
// short-circuit for the default branch
41+
if repoCtx.Repository.DefaultBranch == release.Target || repoCtx.GitRepo.IsBranchExist(release.Target) {
4742
commit, err := repoCtx.GitRepo.GetBranchCommit(release.Target)
4843
if err != nil {
4944
return fmt.Errorf("GetBranchCommit: %w", err)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/main
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unnamed repository; edit this file 'description' to name the repository.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
#
3+
# An example hook script to check the commit log message taken by
4+
# applypatch from an e-mail message.
5+
#
6+
# The hook should exit with non-zero status after issuing an
7+
# appropriate message if it wants to stop the commit. The hook is
8+
# allowed to edit the commit message file.
9+
#
10+
# To enable this hook, rename this file to "applypatch-msg".
11+
12+
. git-sh-setup
13+
commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
14+
test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
15+
:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
#
3+
# An example hook script to check the commit log message.
4+
# Called by "git commit" with one argument, the name of the file
5+
# that has the commit message. The hook should exit with non-zero
6+
# status after issuing an appropriate message if it wants to stop the
7+
# commit. The hook is allowed to edit the commit message file.
8+
#
9+
# To enable this hook, rename this file to "commit-msg".
10+
11+
# Uncomment the below to add a Signed-off-by line to the message.
12+
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
13+
# hook is more suited to it.
14+
#
15+
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
16+
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
17+
18+
# This example catches duplicate Signed-off-by lines.
19+
20+
test "" = "$(grep '^Signed-off-by: ' "$1" |
21+
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
22+
echo >&2 Duplicate Signed-off-by lines.
23+
exit 1
24+
}

0 commit comments

Comments
 (0)