Skip to content

Commit 7204534

Browse files
authored
Merge branch 'main' into noImplicitAny
2 parents 407f395 + 6cc1067 commit 7204534

File tree

27 files changed

+345
-113
lines changed

27 files changed

+345
-113
lines changed

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

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) {

options/gitignore/Node

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ dist
104104
.temp
105105
.cache
106106

107+
# vitepress build output
108+
**/.vitepress/dist
109+
110+
# vitepress cache directory
111+
**/.vitepress/cache
112+
107113
# Docusaurus cache and generated files
108114
.docusaurus
109115

options/gitignore/Python

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,8 @@ cython_debug/
167167
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
168168
#.idea/
169169

170+
# Ruff stuff:
171+
.ruff_cache/
172+
170173
# PyPI configuration file
171174
.pypirc

options/gitignore/Rust

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
debug/
44
target/
55

6-
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7-
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8-
Cargo.lock
9-
106
# These are backup files generated by rustfmt
117
**/*.rs.bk
128

options/locale/locale_en-US.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ pulls.upstream_diverging_prompt_behind_1 = This branch is %[1]d commit behind %[
19531953
pulls.upstream_diverging_prompt_behind_n = This branch is %[1]d commits behind %[2]s
19541954
pulls.upstream_diverging_prompt_base_newer = The base branch %s has new changes
19551955
pulls.upstream_diverging_merge = Sync fork
1956-
pulls.upstream_diverging_merge_confirm = Would you like to merge base repository's default branch onto this repository's branch %s?
1956+
pulls.upstream_diverging_merge_confirm = Would you like to merge "%[1]s" onto "%[2]s"?
19571957

19581958
pull.deleted_branch = (deleted):%s
19591959
pull.agit_documentation = Review documentation about AGit

routers/common/middleware.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ func ProtocolMiddlewares() (handlers []any) {
4343

4444
func RequestContextHandler() func(h http.Handler) http.Handler {
4545
return func(next http.Handler) http.Handler {
46-
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
47-
profDesc := fmt.Sprintf("%s: %s", req.Method, req.RequestURI)
46+
return http.HandlerFunc(func(respOrig http.ResponseWriter, req *http.Request) {
47+
// this response writer might not be the same as the one in context.Base.Resp
48+
// because there might be a "gzip writer" in the middle, so the "written size" here is the compressed size
49+
respWriter := context.WrapResponseWriter(respOrig)
50+
51+
profDesc := fmt.Sprintf("HTTP: %s %s", req.Method, req.RequestURI)
4852
ctx, finished := reqctx.NewRequestContext(req.Context(), profDesc)
4953
defer finished()
5054

5155
defer func() {
5256
if err := recover(); err != nil {
53-
RenderPanicErrorPage(resp, req, err) // it should never panic
57+
RenderPanicErrorPage(respWriter, req, err) // it should never panic
5458
}
5559
}()
5660

@@ -62,7 +66,7 @@ func RequestContextHandler() func(h http.Handler) http.Handler {
6266
_ = req.MultipartForm.RemoveAll() // remove the temp files buffered to tmp directory
6367
}
6468
})
65-
next.ServeHTTP(context.WrapResponseWriter(resp), req)
69+
next.ServeHTTP(respWriter, req)
6670
})
6771
}
6872
}

routers/web/auth/linkaccount.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var tplLinkAccount templates.TplName = "user/auth/link_account"
2929

3030
// LinkAccount shows the page where the user can decide to login or create a new account
3131
func LinkAccount(ctx *context.Context) {
32+
// FIXME: these common template variables should be prepared in one common function, but not just copy-paste again and again.
3233
ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
3334
ctx.Data["Title"] = ctx.Tr("link_account")
3435
ctx.Data["LinkAccountMode"] = true
@@ -43,13 +44,19 @@ func LinkAccount(ctx *context.Context) {
4344
ctx.Data["CfTurnstileSitekey"] = setting.Service.CfTurnstileSitekey
4445
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
4546
ctx.Data["AllowOnlyInternalRegistration"] = setting.Service.AllowOnlyInternalRegistration
47+
ctx.Data["EnablePasswordSignInForm"] = setting.Service.EnablePasswordSignInForm
4648
ctx.Data["ShowRegistrationButton"] = false
4749

4850
// use this to set the right link into the signIn and signUp templates in the link_account template
4951
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
5052
ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
5153

5254
gothUser, ok := ctx.Session.Get("linkAccountGothUser").(goth.User)
55+
56+
// If you'd like to quickly debug the "link account" page layout, just uncomment the blow line
57+
// Don't worry, when the below line exists, the lint won't pass: ineffectual assignment to gothUser (ineffassign)
58+
// gothUser, ok = goth.User{Email: "invalid-email", Name: "."}, true // intentionally use invalid data to avoid pass the registration check
59+
5360
if !ok {
5461
// no account in session, so just redirect to the login page, then the user could restart the process
5562
ctx.Redirect(setting.AppSubURL + "/user/login")
@@ -135,6 +142,8 @@ func LinkAccountPostSignIn(ctx *context.Context) {
135142
ctx.Data["McaptchaURL"] = setting.Service.McaptchaURL
136143
ctx.Data["CfTurnstileSitekey"] = setting.Service.CfTurnstileSitekey
137144
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
145+
ctx.Data["AllowOnlyInternalRegistration"] = setting.Service.AllowOnlyInternalRegistration
146+
ctx.Data["EnablePasswordSignInForm"] = setting.Service.EnablePasswordSignInForm
138147
ctx.Data["ShowRegistrationButton"] = false
139148

140149
// use this to set the right link into the signIn and signUp templates in the link_account template
@@ -223,6 +232,8 @@ func LinkAccountPostRegister(ctx *context.Context) {
223232
ctx.Data["McaptchaURL"] = setting.Service.McaptchaURL
224233
ctx.Data["CfTurnstileSitekey"] = setting.Service.CfTurnstileSitekey
225234
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
235+
ctx.Data["AllowOnlyInternalRegistration"] = setting.Service.AllowOnlyInternalRegistration
236+
ctx.Data["EnablePasswordSignInForm"] = setting.Service.EnablePasswordSignInForm
226237
ctx.Data["ShowRegistrationButton"] = false
227238

228239
// use this to set the right link into the signIn and signUp templates in the link_account template

routers/web/repo/code_frequency.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func CodeFrequency(ctx *context.Context) {
2929

3030
// CodeFrequencyData returns JSON of code frequency data
3131
func CodeFrequencyData(ctx *context.Context) {
32-
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
32+
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {
3333
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
3434
ctx.Status(http.StatusAccepted)
3535
return

0 commit comments

Comments
 (0)