Skip to content

Commit f563ba9

Browse files
authored
Merge branch 'main' into lunny/add_missed_auto_merge_action
2 parents 361d72f + e663c4a commit f563ba9

File tree

177 files changed

+2890
-1702
lines changed

Some content is hidden

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

177 files changed

+2890
-1702
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ COMMA := ,
2626
XGO_VERSION := go-1.23.x
2727

2828
AIR_PACKAGE ?= github.com/air-verse/air@v1
29-
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.0.3
29+
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.1.2
3030
GOFUMPT_PACKAGE ?= mvdan.cc/[email protected]
31-
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
31+
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.63.4
3232
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
3333
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/[email protected]
3434
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/[email protected]
3535
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
3636
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1
3737
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1
3838
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1
39-
GOPLS_PACKAGE ?= golang.org/x/tools/[email protected].0
39+
GOPLS_PACKAGE ?= golang.org/x/tools/[email protected].1
4040

4141
DOCKER_IMAGE ?= gitea/gitea
4242
DOCKER_TAG ?= latest

cmd/web.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import (
1818

1919
"code.gitea.io/gitea/modules/container"
2020
"code.gitea.io/gitea/modules/graceful"
21+
"code.gitea.io/gitea/modules/gtprof"
2122
"code.gitea.io/gitea/modules/log"
2223
"code.gitea.io/gitea/modules/process"
2324
"code.gitea.io/gitea/modules/public"
2425
"code.gitea.io/gitea/modules/setting"
26+
"code.gitea.io/gitea/modules/util"
2527
"code.gitea.io/gitea/routers"
2628
"code.gitea.io/gitea/routers/install"
2729

@@ -218,6 +220,8 @@ func serveInstalled(ctx *cli.Context) error {
218220
}
219221
}
220222

223+
gtprof.EnableBuiltinTracer(util.Iif(setting.IsProd, 2000*time.Millisecond, 100*time.Millisecond))
224+
221225
// Set up Chi routes
222226
webRoutes := routers.NormalRoutes()
223227
err := listen(webRoutes, true)

custom/conf/app.example.ini

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,10 +790,13 @@ LEVEL = Info
790790
;; Please note that setting this to false will not disable OAuth Basic or Basic authentication using a token
791791
;ENABLE_BASIC_AUTHENTICATION = true
792792
;;
793-
;; Show the password sign-in form (for password-based login), otherwise, only show OAuth2 login methods.
793+
;; Show the password sign-in form (for password-based login), otherwise, only show OAuth2 or passkey login methods if they are enabled.
794794
;; If you set it to false, maybe it also needs to set ENABLE_BASIC_AUTHENTICATION to false to completely disable password-based authentication.
795795
;ENABLE_PASSWORD_SIGNIN_FORM = true
796796
;;
797+
;; Allow users to sign-in with a passkey
798+
;ENABLE_PASSKEY_AUTHENTICATION = true
799+
;;
797800
;; More detail: https://github.com/gogits/gogs/issues/165
798801
;ENABLE_REVERSE_PROXY_AUTHENTICATION = false
799802
; Enable this to allow reverse proxy authentication for API requests, the reverse proxy is responsible for ensuring that no CSRF is possible.
@@ -1126,6 +1129,9 @@ LEVEL = Info
11261129
;; In default merge messages only include approvers who are official
11271130
;DEFAULT_MERGE_MESSAGE_OFFICIAL_APPROVERS_ONLY = true
11281131
;;
1132+
;; In default squash-merge messages include the commit message of all commits comprising the pull request.
1133+
;POPULATE_SQUASH_COMMENT_WITH_COMMIT_MESSAGES = false
1134+
;;
11291135
;; Add co-authored-by and co-committed-by trailers if committer does not match author
11301136
;ADD_CO_COMMITTER_TRAILERS = true
11311137
;;

models/db/engine_hook.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,36 @@ import (
77
"context"
88
"time"
99

10+
"code.gitea.io/gitea/modules/gtprof"
1011
"code.gitea.io/gitea/modules/log"
12+
"code.gitea.io/gitea/modules/setting"
1113

1214
"xorm.io/xorm/contexts"
1315
)
1416

15-
type SlowQueryHook struct {
17+
type EngineHook struct {
1618
Threshold time.Duration
1719
Logger log.Logger
1820
}
1921

20-
var _ contexts.Hook = (*SlowQueryHook)(nil)
22+
var _ contexts.Hook = (*EngineHook)(nil)
2123

22-
func (*SlowQueryHook) BeforeProcess(c *contexts.ContextHook) (context.Context, error) {
23-
return c.Ctx, nil
24+
func (*EngineHook) BeforeProcess(c *contexts.ContextHook) (context.Context, error) {
25+
ctx, _ := gtprof.GetTracer().Start(c.Ctx, gtprof.TraceSpanDatabase)
26+
return ctx, nil
2427
}
2528

26-
func (h *SlowQueryHook) AfterProcess(c *contexts.ContextHook) error {
29+
func (h *EngineHook) AfterProcess(c *contexts.ContextHook) error {
30+
span := gtprof.GetContextSpan(c.Ctx)
31+
if span != nil {
32+
// Do not record SQL parameters here:
33+
// * It shouldn't expose the parameters because they contain sensitive information, end users need to report the trace details safely.
34+
// * Some parameters contain quite long texts, waste memory and are difficult to display.
35+
span.SetAttributeString(gtprof.TraceAttrDbSQL, c.SQL)
36+
span.End()
37+
} else {
38+
setting.PanicInDevOrTesting("span in database engine hook is nil")
39+
}
2740
if c.ExecuteTime >= h.Threshold {
2841
// 8 is the amount of skips passed to runtime.Caller, so that in the log the correct function
2942
// is being displayed (the function that ultimately wants to execute the query in the code)

models/db/engine_init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func InitEngine(ctx context.Context) error {
7272
xe.SetDefaultContext(ctx)
7373

7474
if setting.Database.SlowQueryThreshold > 0 {
75-
xe.AddHook(&SlowQueryHook{
75+
xe.AddHook(&EngineHook{
7676
Threshold: setting.Database.SlowQueryThreshold,
7777
Logger: log.GetLogger("xorm"),
7878
})

models/db/name.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"code.gitea.io/gitea/modules/util"
1212
)
1313

14-
var ErrNameEmpty = util.SilentWrap{Message: "name is empty", Err: util.ErrInvalidArgument}
15-
1614
// ErrNameReserved represents a "reserved name" error.
1715
type ErrNameReserved struct {
1816
Name string
@@ -79,7 +77,7 @@ func (err ErrNameCharsNotAllowed) Unwrap() error {
7977
func IsUsableName(reservedNames, reservedPatterns []string, name string) error {
8078
name = strings.TrimSpace(strings.ToLower(name))
8179
if utf8.RuneCountInString(name) == 0 {
82-
return ErrNameEmpty
80+
return util.SilentWrap{Message: "name is empty", Err: util.ErrInvalidArgument}
8381
}
8482

8583
for i := range reservedNames {

models/git/branch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ func GetBranch(ctx context.Context, repoID int64, branchName string) (*Branch, e
167167
BranchName: branchName,
168168
}
169169
}
170+
// FIXME: this design is not right: it doesn't check `branch.IsDeleted`, it doesn't make sense to make callers to check IsDeleted again and again.
171+
// It causes inconsistency with `GetBranches` and `git.GetBranch`, and will lead to strange bugs
172+
// In the future, there should be 2 functions: `GetBranchExisting` and `GetBranchWithDeleted`
170173
return &branch, nil
171174
}
172175

models/repo/repo.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"regexp"
1515
"strconv"
1616
"strings"
17+
"sync"
1718

1819
"code.gitea.io/gitea/models/db"
1920
"code.gitea.io/gitea/models/unit"
@@ -61,20 +62,30 @@ func (err ErrRepoIsArchived) Error() string {
6162
return fmt.Sprintf("%s is archived", err.Repo.LogString())
6263
}
6364

64-
var (
65-
validRepoNamePattern = regexp.MustCompile(`[-.\w]+`)
66-
invalidRepoNamePattern = regexp.MustCompile(`[.]{2,}`)
67-
reservedRepoNames = []string{".", "..", "-"}
68-
reservedRepoPatterns = []string{"*.git", "*.wiki", "*.rss", "*.atom"}
69-
)
65+
type globalVarsStruct struct {
66+
validRepoNamePattern *regexp.Regexp
67+
invalidRepoNamePattern *regexp.Regexp
68+
reservedRepoNames []string
69+
reservedRepoPatterns []string
70+
}
71+
72+
var globalVars = sync.OnceValue(func() *globalVarsStruct {
73+
return &globalVarsStruct{
74+
validRepoNamePattern: regexp.MustCompile(`[-.\w]+`),
75+
invalidRepoNamePattern: regexp.MustCompile(`[.]{2,}`),
76+
reservedRepoNames: []string{".", "..", "-"},
77+
reservedRepoPatterns: []string{"*.git", "*.wiki", "*.rss", "*.atom"},
78+
}
79+
})
7080

7181
// IsUsableRepoName returns true when name is usable
7282
func IsUsableRepoName(name string) error {
73-
if !validRepoNamePattern.MatchString(name) || invalidRepoNamePattern.MatchString(name) {
83+
vars := globalVars()
84+
if !vars.validRepoNamePattern.MatchString(name) || vars.invalidRepoNamePattern.MatchString(name) {
7485
// Note: usually this error is normally caught up earlier in the UI
7586
return db.ErrNameCharsNotAllowed{Name: name}
7687
}
77-
return db.IsUsableName(reservedRepoNames, reservedRepoPatterns, name)
88+
return db.IsUsableName(vars.reservedRepoNames, vars.reservedRepoPatterns, name)
7889
}
7990

8091
// TrustModelType defines the types of trust model for this repository

models/repo/repo_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,5 @@ func TestIsUsableRepoName(t *testing.T) {
219219
assert.Error(t, IsUsableRepoName("the..repo"))
220220
assert.Error(t, IsUsableRepoName("foo.wiki"))
221221
assert.Error(t, IsUsableRepoName("foo.git"))
222+
assert.Error(t, IsUsableRepoName("foo.RSS"))
222223
}

models/user/user.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,10 @@ func (u *User) IsMailable() bool {
502502
return u.IsActive
503503
}
504504

505-
// IsUserExist checks if given user name exist,
506-
// the user name should be noncased unique.
505+
// IsUserExist checks if given username exist,
506+
// the username should be non-cased unique.
507507
// If uid is presented, then check will rule out that one,
508-
// it is used when update a user name in settings page.
508+
// it is used when update a username in settings page.
509509
func IsUserExist(ctx context.Context, uid int64, name string) (bool, error) {
510510
if len(name) == 0 {
511511
return false, nil
@@ -515,7 +515,7 @@ func IsUserExist(ctx context.Context, uid int64, name string) (bool, error) {
515515
Get(&User{LowerName: strings.ToLower(name)})
516516
}
517517

518-
// Note: As of the beginning of 2022, it is recommended to use at least
518+
// SaltByteLength as of the beginning of 2022, it is recommended to use at least
519519
// 64 bits of salt, but NIST is already recommending to use to 128 bits.
520520
// (16 bytes = 16 * 8 = 128 bits)
521521
const SaltByteLength = 16

0 commit comments

Comments
 (0)