Skip to content

Commit f1b3305

Browse files
authored
Merge branch 'main' into lunny/fix-oauth2-disable
2 parents ff56466 + a928739 commit f1b3305

File tree

299 files changed

+5020
-4403
lines changed

Some content is hidden

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

299 files changed

+5020
-4403
lines changed

custom/conf/app.example.ini

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2642,9 +2642,15 @@ LEVEL = Info
26422642
;; override the azure blob base path if storage type is azureblob
26432643
;AZURE_BLOB_BASE_PATH = lfs/
26442644

2645+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2646+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2647+
;; settings for Gitea's LFS client (eg: mirroring an upstream lfs endpoint)
2648+
;;
26452649
;[lfs_client]
2646-
;; When mirroring an upstream lfs endpoint, limit the number of pointers in each batch request to this number
2650+
;; Limit the number of pointers in each batch request to this number
26472651
;BATCH_SIZE = 20
2652+
;; Limit the number of concurrent upload/download operations within a batch
2653+
;BATCH_OPERATION_CONCURRENCY = 8
26482654

26492655
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26502656
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ require (
124124
golang.org/x/image v0.21.0
125125
golang.org/x/net v0.30.0
126126
golang.org/x/oauth2 v0.23.0
127+
golang.org/x/sync v0.8.0
127128
golang.org/x/sys v0.26.0
128129
golang.org/x/text v0.19.0
129130
golang.org/x/tools v0.26.0
@@ -316,7 +317,6 @@ require (
316317
go.uber.org/zap v1.27.0 // indirect
317318
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
318319
golang.org/x/mod v0.21.0 // indirect
319-
golang.org/x/sync v0.8.0 // indirect
320320
golang.org/x/time v0.7.0 // indirect
321321
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
322322
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect

models/actions/schedule_spec_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ import (
77
"testing"
88
"time"
99

10+
"code.gitea.io/gitea/modules/test"
11+
1012
"github.com/stretchr/testify/assert"
1113
"github.com/stretchr/testify/require"
1214
)
1315

1416
func TestActionScheduleSpec_Parse(t *testing.T) {
1517
// Mock the local timezone is not UTC
16-
local := time.Local
1718
tz, err := time.LoadLocation("Asia/Shanghai")
1819
require.NoError(t, err)
19-
defer func() {
20-
time.Local = local
21-
}()
22-
time.Local = tz
20+
defer test.MockVariableValue(&time.Local, tz)()
2321

2422
now, err := time.Parse(time.RFC3339, "2024-07-31T15:47:55+08:00")
2523
require.NoError(t, err)

models/activities/action.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ func (a *Action) TableIndices() []*schemas.Index {
171171
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
172172
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
173173

174-
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex}
174+
cuIndex := schemas.NewIndex("c_u", schemas.IndexType)
175+
cuIndex.AddColumn("user_id", "is_deleted")
176+
177+
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex, cuIndex}
175178

176179
return indices
177180
}

models/issues/milestone.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ func (m *Milestone) BeforeUpdate() {
8484
// this object.
8585
func (m *Milestone) AfterLoad() {
8686
m.NumOpenIssues = m.NumIssues - m.NumClosedIssues
87-
if m.DeadlineUnix.Year() == 9999 {
87+
if m.DeadlineUnix == 0 {
8888
return
8989
}
90-
9190
m.DeadlineString = m.DeadlineUnix.FormatDate()
9291
if m.IsClosed {
9392
m.IsOverdue = m.ClosedDateUnix >= m.DeadlineUnix

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ func prepareMigrationTasks() []*migration {
364364
newMigration(304, "Add index for release sha1", v1_23.AddIndexForReleaseSha1),
365365
newMigration(305, "Add Repository Licenses", v1_23.AddRepositoryLicenses),
366366
newMigration(306, "Add BlockAdminMergeOverride to ProtectedBranch", v1_23.AddBlockAdminMergeOverrideBranchProtection),
367+
newMigration(307, "Fix milestone deadline_unix when there is no due date", v1_23.FixMilestoneNoDueDate),
368+
newMigration(308, "Add index(user_id, is_deleted) for action table", v1_23.AddNewIndexForUserDashboard),
367369
}
368370
return preparedMigrations
369371
}

models/migrations/v1_23/v307.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/timeutil"
8+
9+
"xorm.io/xorm"
10+
)
11+
12+
func FixMilestoneNoDueDate(x *xorm.Engine) error {
13+
type Milestone struct {
14+
DeadlineUnix timeutil.TimeStamp
15+
}
16+
// Wednesday, December 1, 9999 12:00:00 AM GMT+00:00
17+
_, err := x.Table("milestone").Where("deadline_unix > 253399622400").
18+
Cols("deadline_unix").
19+
Update(&Milestone{DeadlineUnix: 0})
20+
return err
21+
}

models/migrations/v1_23/v308.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/timeutil"
8+
9+
"xorm.io/xorm"
10+
"xorm.io/xorm/schemas"
11+
)
12+
13+
type improveActionTableIndicesAction struct {
14+
ID int64 `xorm:"pk autoincr"`
15+
UserID int64 `xorm:"INDEX"` // Receiver user id.
16+
OpType int
17+
ActUserID int64 // Action user id.
18+
RepoID int64
19+
CommentID int64 `xorm:"INDEX"`
20+
IsDeleted bool `xorm:"NOT NULL DEFAULT false"`
21+
RefName string
22+
IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
23+
Content string `xorm:"TEXT"`
24+
CreatedUnix timeutil.TimeStamp `xorm:"created"`
25+
}
26+
27+
// TableName sets the name of this table
28+
func (*improveActionTableIndicesAction) TableName() string {
29+
return "action"
30+
}
31+
32+
func (a *improveActionTableIndicesAction) TableIndices() []*schemas.Index {
33+
repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType)
34+
repoIndex.AddColumn("repo_id", "user_id", "is_deleted")
35+
36+
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
37+
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
38+
39+
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
40+
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
41+
42+
cuIndex := schemas.NewIndex("c_u", schemas.IndexType)
43+
cuIndex.AddColumn("user_id", "is_deleted")
44+
45+
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex, cuIndex}
46+
47+
return indices
48+
}
49+
50+
func AddNewIndexForUserDashboard(x *xorm.Engine) error {
51+
return x.Sync(new(improveActionTableIndicesAction))
52+
}

models/perm/access_mode.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@ func ParseAccessMode(permission string, allowed ...AccessMode) AccessMode {
6060
}
6161
return util.Iif(slices.Contains(allowed, m), m, AccessModeNone)
6262
}
63+
64+
// ErrInvalidAccessMode is returned when an invalid access mode is used
65+
var ErrInvalidAccessMode = util.NewInvalidArgumentErrorf("Invalid access mode")

models/repo/user_repo.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,28 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us
110110
return nil, err
111111
}
112112

113-
additionalUserIDs := make([]int64, 0, 10)
114-
if err = e.Table("team_user").
115-
Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
116-
Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
117-
Where("`team_repo`.repo_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
118-
repo.ID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
119-
Distinct("`team_user`.uid").
120-
Select("`team_user`.uid").
121-
Find(&additionalUserIDs); err != nil {
122-
return nil, err
123-
}
124-
125113
uniqueUserIDs := make(container.Set[int64])
126114
uniqueUserIDs.AddMultiple(userIDs...)
127-
uniqueUserIDs.AddMultiple(additionalUserIDs...)
115+
116+
if repo.Owner.IsOrganization() {
117+
additionalUserIDs := make([]int64, 0, 10)
118+
if err = e.Table("team_user").
119+
Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
120+
Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
121+
Where("`team_repo`.repo_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
122+
repo.ID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
123+
Distinct("`team_user`.uid").
124+
Select("`team_user`.uid").
125+
Find(&additionalUserIDs); err != nil {
126+
return nil, err
127+
}
128+
uniqueUserIDs.AddMultiple(additionalUserIDs...)
129+
}
128130

129131
// Leave a seat for owner itself to append later, but if owner is an organization
130132
// and just waste 1 unit is cheaper than re-allocate memory once.
131133
users := make([]*user_model.User, 0, len(uniqueUserIDs)+1)
132-
if len(userIDs) > 0 {
134+
if len(uniqueUserIDs) > 0 {
133135
if err = e.In("id", uniqueUserIDs.Values()).
134136
Where(builder.Eq{"`user`.is_active": true}).
135137
OrderBy(user_model.GetOrderByName()).

modules/base/tool.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ func StringsToInt64s(strs []string) ([]int64, error) {
147147
}
148148
ints := make([]int64, 0, len(strs))
149149
for _, s := range strs {
150+
if s == "" {
151+
continue
152+
}
150153
n, err := strconv.ParseInt(s, 10, 64)
151154
if err != nil {
152155
return nil, err

modules/base/tool_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func TestStringsToInt64s(t *testing.T) {
152152
}
153153
testSuccess(nil, nil)
154154
testSuccess([]string{}, []int64{})
155+
testSuccess([]string{""}, []int64{})
155156
testSuccess([]string{"-1234"}, []int64{-1234})
156157
testSuccess([]string{"1", "4", "16", "64", "256"}, []int64{1, 4, 16, 64, 256})
157158

modules/container/set.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func (s Set[T]) AddMultiple(values ...T) {
3131
}
3232
}
3333

34-
// Contains determines whether a set contains the specified elements.
35-
// Returns true if the set contains the specified element; otherwise, false.
34+
// Contains determines whether a set contains all these elements.
35+
// Returns true if the set contains all these elements; otherwise, false.
3636
func (s Set[T]) Contains(values ...T) bool {
3737
ret := true
3838
for _, value := range values {

modules/container/set_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ func TestSet(t *testing.T) {
1818

1919
assert.True(t, s.Contains("key1"))
2020
assert.True(t, s.Contains("key2"))
21+
assert.True(t, s.Contains("key1", "key2"))
2122
assert.False(t, s.Contains("key3"))
23+
assert.False(t, s.Contains("key1", "key3"))
2224

2325
assert.True(t, s.Remove("key2"))
2426
assert.False(t, s.Contains("key2"))

modules/gitgraph/graph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func GetCommitGraph(r *git.Repository, page, maxAllowedColors int, hidePRRefs bo
3232
graphCmd.AddArguments("--all")
3333
}
3434

35-
graphCmd.AddArguments("-C", "-M", "--date=iso").
35+
graphCmd.AddArguments("-C", "-M", "--date=iso-strict").
3636
AddOptionFormat("-n %d", setting.UI.GraphMaxCommitNum*page).
3737
AddOptionFormat("--pretty=format:%s", format)
3838

modules/gitgraph/graph_models.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"strings"
11+
"time"
1112

1213
asymkey_model "code.gitea.io/gitea/models/asymkey"
1314
"code.gitea.io/gitea/models/db"
@@ -192,6 +193,14 @@ var RelationCommit = &Commit{
192193
Row: -1,
193194
}
194195

196+
func parseGitTime(timeStr string) time.Time {
197+
t, err := time.Parse(time.RFC3339, timeStr)
198+
if err != nil {
199+
return time.Unix(0, 0)
200+
}
201+
return t
202+
}
203+
195204
// NewCommit creates a new commit from a provided line
196205
func NewCommit(row, column int, line []byte) (*Commit, error) {
197206
data := bytes.SplitN(line, []byte("|"), 5)
@@ -206,7 +215,7 @@ func NewCommit(row, column int, line []byte) (*Commit, error) {
206215
// 1 matches git log --pretty=format:%H => commit hash
207216
Rev: string(data[1]),
208217
// 2 matches git log --pretty=format:%ad => author date (format respects --date= option)
209-
Date: string(data[2]),
218+
Date: parseGitTime(string(data[2])),
210219
// 3 matches git log --pretty=format:%h => abbreviated commit hash
211220
ShortRev: string(data[3]),
212221
// 4 matches git log --pretty=format:%s => subject
@@ -245,7 +254,7 @@ type Commit struct {
245254
Column int
246255
Refs []git.Reference
247256
Rev string
248-
Date string
257+
Date time.Time
249258
ShortRev string
250259
Subject string
251260
}

modules/gitrepo/gitrepo.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"code.gitea.io/gitea/modules/git"
1313
"code.gitea.io/gitea/modules/setting"
14+
"code.gitea.io/gitea/modules/util"
1415
)
1516

1617
type Repository interface {
@@ -59,15 +60,11 @@ func repositoryFromContext(ctx context.Context, repo Repository) *git.Repository
5960
return nil
6061
}
6162

62-
type nopCloser func()
63-
64-
func (nopCloser) Close() error { return nil }
65-
6663
// RepositoryFromContextOrOpen attempts to get the repository from the context or just opens it
6764
func RepositoryFromContextOrOpen(ctx context.Context, repo Repository) (*git.Repository, io.Closer, error) {
6865
gitRepo := repositoryFromContext(ctx, repo)
6966
if gitRepo != nil {
70-
return gitRepo, nopCloser(nil), nil
67+
return gitRepo, util.NopCloser{}, nil
7168
}
7269

7370
gitRepo, err := OpenRepository(ctx, repo)
@@ -95,7 +92,7 @@ func repositoryFromContextPath(ctx context.Context, path string) *git.Repository
9592
func RepositoryFromContextOrOpenPath(ctx context.Context, path string) (*git.Repository, io.Closer, error) {
9693
gitRepo := repositoryFromContextPath(ctx, path)
9794
if gitRepo != nil {
98-
return gitRepo, nopCloser(nil), nil
95+
return gitRepo, util.NopCloser{}, nil
9996
}
10097

10198
gitRepo, err := git.OpenRepository(ctx, path)

modules/indexer/code/bleve/bleve.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/blevesearch/bleve/v2/analysis/token/camelcase"
3232
"github.com/blevesearch/bleve/v2/analysis/token/lowercase"
3333
"github.com/blevesearch/bleve/v2/analysis/token/unicodenorm"
34+
"github.com/blevesearch/bleve/v2/analysis/tokenizer/letter"
3435
"github.com/blevesearch/bleve/v2/analysis/tokenizer/unicode"
3536
"github.com/blevesearch/bleve/v2/mapping"
3637
"github.com/blevesearch/bleve/v2/search/query"
@@ -69,7 +70,7 @@ const (
6970
filenameIndexerAnalyzer = "filenameIndexerAnalyzer"
7071
filenameIndexerTokenizer = "filenameIndexerTokenizer"
7172
repoIndexerDocType = "repoIndexerDocType"
72-
repoIndexerLatestVersion = 7
73+
repoIndexerLatestVersion = 8
7374
)
7475

7576
// generateBleveIndexMapping generates a bleve index mapping for the repo indexer
@@ -105,7 +106,7 @@ func generateBleveIndexMapping() (mapping.IndexMapping, error) {
105106
} else if err := mapping.AddCustomAnalyzer(repoIndexerAnalyzer, map[string]any{
106107
"type": analyzer_custom.Name,
107108
"char_filters": []string{},
108-
"tokenizer": unicode.Name,
109+
"tokenizer": letter.Name,
109110
"token_filters": []string{unicodeNormalizeName, camelcase.Name, lowercase.Name},
110111
}); err != nil {
111112
return nil, err

0 commit comments

Comments
 (0)