Skip to content

Commit 9e53ad7

Browse files
committed
Merge branch 'main' into lunny/refactor_transfer
2 parents 7edb840 + 340d9ec commit 9e53ad7

File tree

144 files changed

+2218
-888
lines changed

Some content is hidden

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

144 files changed

+2218
-888
lines changed

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: 4 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.

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/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/issues/stopwatch.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ func (s Stopwatch) Seconds() int64 {
4646
return int64(timeutil.TimeStampNow() - s.CreatedUnix)
4747
}
4848

49-
// Duration returns a human-readable duration string based on local server time
50-
func (s Stopwatch) Duration() string {
51-
return util.SecToTime(s.Seconds())
52-
}
53-
5449
func getStopwatch(ctx context.Context, userID, issueID int64) (sw *Stopwatch, exists bool, err error) {
5550
sw = new(Stopwatch)
5651
exists, err = db.GetEngine(ctx).
@@ -201,7 +196,7 @@ func FinishIssueStopwatch(ctx context.Context, user *user_model.User, issue *Iss
201196
Doer: user,
202197
Issue: issue,
203198
Repo: issue.Repo,
204-
Content: util.SecToTime(timediff),
199+
Content: util.SecToHours(timediff),
205200
Type: CommentTypeStopTracking,
206201
TimeID: tt.ID,
207202
}); err != nil {

modules/git/command.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"time"
1919

2020
"code.gitea.io/gitea/modules/git/internal" //nolint:depguard // only this file can use the internal type CmdArg, other files and packages should use AddXxx functions
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/util"
@@ -54,7 +55,7 @@ func logArgSanitize(arg string) string {
5455
} else if filepath.IsAbs(arg) {
5556
base := filepath.Base(arg)
5657
dir := filepath.Dir(arg)
57-
return filepath.Join(filepath.Base(dir), base)
58+
return ".../" + filepath.Join(filepath.Base(dir), base)
5859
}
5960
return arg
6061
}
@@ -295,15 +296,20 @@ func (c *Command) run(skip int, opts *RunOpts) error {
295296
timeout = defaultCommandExecutionTimeout
296297
}
297298

298-
var desc string
299+
cmdLogString := c.LogString()
299300
callerInfo := util.CallerFuncName(1 /* util */ + 1 /* this */ + skip /* parent */)
300301
if pos := strings.LastIndex(callerInfo, "/"); pos >= 0 {
301302
callerInfo = callerInfo[pos+1:]
302303
}
303304
// these logs are for debugging purposes only, so no guarantee of correctness or stability
304-
desc = fmt.Sprintf("git.Run(by:%s, repo:%s): %s", callerInfo, logArgSanitize(opts.Dir), c.LogString())
305+
desc := fmt.Sprintf("git.Run(by:%s, repo:%s): %s", callerInfo, logArgSanitize(opts.Dir), cmdLogString)
305306
log.Debug("git.Command: %s", desc)
306307

308+
_, span := gtprof.GetTracer().Start(c.parentContext, gtprof.TraceSpanGitRun)
309+
defer span.End()
310+
span.SetAttributeString(gtprof.TraceAttrFuncCaller, callerInfo)
311+
span.SetAttributeString(gtprof.TraceAttrGitCommand, cmdLogString)
312+
307313
var ctx context.Context
308314
var cancel context.CancelFunc
309315
var finished context.CancelFunc

modules/git/command_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ func TestCommandString(t *testing.T) {
5858
assert.EqualValues(t, cmd.prog+` a "-m msg" "it's a test" "say \"hello\""`, cmd.LogString())
5959

6060
cmd = NewCommandContextNoGlobals(context.Background(), "url: https://a:b@c/", "/root/dir-a/dir-b")
61-
assert.EqualValues(t, cmd.prog+` "url: https://sanitized-credential@c/" dir-a/dir-b`, cmd.LogString())
61+
assert.EqualValues(t, cmd.prog+` "url: https://sanitized-credential@c/" .../dir-a/dir-b`, cmd.LogString())
6262
}

modules/git/diff.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
6464
} else if commit.ParentCount() == 0 {
6565
cmd.AddArguments("show").AddDynamicArguments(endCommit).AddDashesAndList(files...)
6666
} else {
67-
c, _ := commit.Parent(0)
67+
c, err := commit.Parent(0)
68+
if err != nil {
69+
return err
70+
}
6871
cmd.AddArguments("diff", "-M").AddDynamicArguments(c.ID.String(), endCommit).AddDashesAndList(files...)
6972
}
7073
case RawDiffPatch:
@@ -74,7 +77,10 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
7477
} else if commit.ParentCount() == 0 {
7578
cmd.AddArguments("format-patch", "--no-signature", "--stdout", "--root").AddDynamicArguments(endCommit).AddDashesAndList(files...)
7679
} else {
77-
c, _ := commit.Parent(0)
80+
c, err := commit.Parent(0)
81+
if err != nil {
82+
return err
83+
}
7884
query := fmt.Sprintf("%s...%s", endCommit, c.ID.String())
7985
cmd.AddArguments("format-patch", "--no-signature", "--stdout").AddDynamicArguments(query).AddDashesAndList(files...)
8086
}

modules/git/repo_branch_gogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (repo *Repository) IsBranchExist(name string) bool {
5757

5858
// GetBranches returns branches from the repository, skipping "skip" initial branches and
5959
// returning at most "limit" branches, or all branches if "limit" is 0.
60-
// Branches are returned with sort of `-commiterdate` as the nogogit
60+
// Branches are returned with sort of `-committerdate` as the nogogit
6161
// implementation. This requires full fetch, sort and then the
6262
// skip/limit applies later as gogit returns in undefined order.
6363
func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) {

0 commit comments

Comments
 (0)