Skip to content

Commit 94663f7

Browse files
committed
Merge branch 'main' into feature/filter-branches
2 parents c890e82 + f4b9257 commit 94663f7

File tree

131 files changed

+1207
-531
lines changed

Some content is hidden

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

131 files changed

+1207
-531
lines changed

.stylelintrc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ rules:
9898
at-rule-allowed-list: null
9999
at-rule-disallowed-list: null
100100
at-rule-empty-line-before: null
101-
at-rule-no-unknown: true
101+
at-rule-no-unknown: [true, {ignoreAtRules: [tailwind]}]
102102
at-rule-no-vendor-prefix: true
103103
at-rule-property-required-list: null
104104
block-no-empty: true

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ Rui Chen <[email protected]> (@chenrui333)
5959
Nanguan Lin <[email protected]> (@lng2020)
6060
kerwin612 <[email protected]> (@kerwin612)
6161
Gary Wang <[email protected]> (@BLumia)
62+
Tim-Niclas Oelschläger <[email protected]> (@zokkis)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/m
119119
FOMANTIC_WORK_DIR := web_src/fomantic
120120

121121
WEBPACK_SOURCES := $(shell find web_src/js web_src/css -type f)
122-
WEBPACK_CONFIGS := webpack.config.js
122+
WEBPACK_CONFIGS := webpack.config.js tailwind.config.js
123123
WEBPACK_DEST := public/assets/js/index.js public/assets/css/index.css
124124
WEBPACK_DEST_ENTRIES := public/assets/js public/assets/css public/assets/fonts public/assets/img/webpack
125125

docs/content/administration/mail-templates.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ the messages. Here's a list of some of them:
266266
| `AppDomain` | - | Any | Gitea's host name |
267267
| `EllipsisString` | string, int | Any | Truncates a string to the specified length; adds ellipsis as needed |
268268
| `Str2html` | string | Body only | Sanitizes text by removing any HTML tags from it. |
269-
| `Safe` | string | Body only | Takes the input as HTML; can be used for `.ReviewComments.RenderedContent`. |
269+
| `SafeHTML` | string | Body only | Takes the input as HTML; can be used for `.ReviewComments.RenderedContent`. |
270270

271271
These are _functions_, not metadata, so they have to be used:
272272

docs/content/administration/mail-templates.zh-cn.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ _主题_ 和 _邮件正文_ 由 [Golang的模板引擎](https://go.dev/pkg/text/
242242

243243
模板系统包含一些函数,可用于进一步处理和格式化消息。以下是其中一些函数的列表:
244244

245-
| 函数名 | 参数 | 可用于 | 用法 |
246-
| ----------------- | ----------- | ------------ | --------------------------------------------------------------------------------- |
247-
| `AppUrl` | - | 任何地方 | Gitea 的 URL |
248-
| `AppName` | - | 任何地方 |`app.ini` 中设置,通常为 "Gitea" |
249-
| `AppDomain` | - | 任何地方 | Gitea 的主机名 |
250-
| `EllipsisString` | string, int | 任何地方 | 将字符串截断为指定长度;根据需要添加省略号 |
251-
| `Str2html` | string | 仅正文部分 | 通过删除其中的 HTML 标签对文本进行清理 |
252-
| `Safe` | string | 仅正文部分 | 将输入作为 HTML 处理;可用于 `.ReviewComments.RenderedContent` 等字段 |
245+
| 函数名 | 参数 | 可用于 | 用法 |
246+
|------------------| ----------- | ------------ | --------------------------------------------------------------------------------- |
247+
| `AppUrl` | - | 任何地方 | Gitea 的 URL |
248+
| `AppName` | - | 任何地方 |`app.ini` 中设置,通常为 "Gitea" |
249+
| `AppDomain` | - | 任何地方 | Gitea 的主机名 |
250+
| `EllipsisString` | string, int | 任何地方 | 将字符串截断为指定长度;根据需要添加省略号 |
251+
| `Str2html` | string | 仅正文部分 | 通过删除其中的 HTML 标签对文本进行清理 |
252+
| `SafeHTML` | string | 仅正文部分 | 将输入作为 HTML 处理;可用于 `.ReviewComments.RenderedContent` 等字段 |
253253

254254
这些都是 _函数_,而不是元数据,因此必须按以下方式使用:
255255

docs/content/contributing/guidelines-backend.en-us.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ i.e. `services/user`, `models/repository`.
101101
Since there are some packages which use the same package name, it is possible that you find packages like `modules/user`, `models/user`, and `services/user`. When these packages are imported in one Go file, it's difficult to know which package we are using and if it's a variable name or an import name. So, we always recommend to use import aliases. To differ from package variables which are commonly in camelCase, just use **snake_case** for import aliases.
102102
i.e. `import user_service "code.gitea.io/gitea/services/user"`
103103

104+
### Implementing `io.Closer`
105+
106+
If a type implements `io.Closer`, calling `Close` multiple times must not fail or `panic` but return an error or `nil`.
107+
104108
### Important Gotchas
105109

106110
- Never write `x.Update(exemplar)` without an explicit `WHERE` clause:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ require (
7878
github.com/mholt/archiver/v3 v3.5.1
7979
github.com/microcosm-cc/bluemonday v1.0.26
8080
github.com/minio/minio-go/v7 v7.0.66
81-
github.com/minio/sha256-simd v1.0.1
8281
github.com/msteinert/pam v1.2.0
8382
github.com/nektos/act v0.2.52
8483
github.com/niklasfasching/go-org v1.7.0
@@ -230,6 +229,7 @@ require (
230229
github.com/mholt/acmez v1.2.0 // indirect
231230
github.com/miekg/dns v1.1.58 // indirect
232231
github.com/minio/md5-simd v1.1.2 // indirect
232+
github.com/minio/sha256-simd v1.0.1 // indirect
233233
github.com/mitchellh/copystructure v1.2.0 // indirect
234234
github.com/mitchellh/mapstructure v1.5.0 // indirect
235235
github.com/mitchellh/reflectwalk v1.0.2 // indirect

models/auth/twofactor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package auth
66
import (
77
"context"
88
"crypto/md5"
9+
"crypto/sha256"
910
"crypto/subtle"
1011
"encoding/base32"
1112
"encoding/base64"
@@ -18,7 +19,6 @@ import (
1819
"code.gitea.io/gitea/modules/timeutil"
1920
"code.gitea.io/gitea/modules/util"
2021

21-
"github.com/minio/sha256-simd"
2222
"github.com/pquerna/otp/totp"
2323
"golang.org/x/crypto/pbkdf2"
2424
)

models/issues/comment.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,9 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
855855
// Check comment type.
856856
switch opts.Type {
857857
case CommentTypeCode:
858+
if err = updateAttachments(ctx, opts, comment); err != nil {
859+
return err
860+
}
858861
if comment.ReviewID != 0 {
859862
if comment.Review == nil {
860863
if err := comment.loadReview(ctx); err != nil {
@@ -872,22 +875,9 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
872875
}
873876
fallthrough
874877
case CommentTypeReview:
875-
// Check attachments
876-
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, opts.Attachments)
877-
if err != nil {
878-
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", opts.Attachments, err)
879-
}
880-
881-
for i := range attachments {
882-
attachments[i].IssueID = opts.Issue.ID
883-
attachments[i].CommentID = comment.ID
884-
// No assign value could be 0, so ignore AllCols().
885-
if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Update(attachments[i]); err != nil {
886-
return fmt.Errorf("update attachment [%d]: %w", attachments[i].ID, err)
887-
}
878+
if err = updateAttachments(ctx, opts, comment); err != nil {
879+
return err
888880
}
889-
890-
comment.Attachments = attachments
891881
case CommentTypeReopen, CommentTypeClose:
892882
if err = repo_model.UpdateRepoIssueNumbers(ctx, opts.Issue.RepoID, opts.Issue.IsPull, true); err != nil {
893883
return err
@@ -897,6 +887,23 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
897887
return UpdateIssueCols(ctx, opts.Issue, "updated_unix")
898888
}
899889

890+
func updateAttachments(ctx context.Context, opts *CreateCommentOptions, comment *Comment) error {
891+
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, opts.Attachments)
892+
if err != nil {
893+
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", opts.Attachments, err)
894+
}
895+
for i := range attachments {
896+
attachments[i].IssueID = opts.Issue.ID
897+
attachments[i].CommentID = comment.ID
898+
// No assign value could be 0, so ignore AllCols().
899+
if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Update(attachments[i]); err != nil {
900+
return fmt.Errorf("update attachment [%d]: %w", attachments[i].ID, err)
901+
}
902+
}
903+
comment.Attachments = attachments
904+
return nil
905+
}
906+
900907
func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Issue, newDeadlineUnix timeutil.TimeStamp) (*Comment, error) {
901908
var content string
902909
var commentType CommentType

models/migrations/base/hash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
package base
55

66
import (
7+
"crypto/sha256"
78
"encoding/hex"
89

9-
"github.com/minio/sha256-simd"
1010
"golang.org/x/crypto/pbkdf2"
1111
)
1212

models/migrations/v1_14/v166.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
package v1_14 //nolint
55

66
import (
7+
"crypto/sha256"
78
"encoding/hex"
89

9-
"github.com/minio/sha256-simd"
1010
"golang.org/x/crypto/argon2"
1111
"golang.org/x/crypto/bcrypt"
1212
"golang.org/x/crypto/pbkdf2"

modules/auth/password/hash/pbkdf2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
package hash
55

66
import (
7+
"crypto/sha256"
78
"encoding/hex"
89
"strings"
910

1011
"code.gitea.io/gitea/modules/log"
1112

12-
"github.com/minio/sha256-simd"
1313
"golang.org/x/crypto/pbkdf2"
1414
)
1515

modules/avatar/hash.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
package avatar
55

66
import (
7+
"crypto/sha256"
78
"encoding/hex"
89
"strconv"
9-
10-
"github.com/minio/sha256-simd"
1110
)
1211

1312
// HashAvatar will generate a unique string, which ensures that when there's a

modules/avatar/identicon/identicon.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
package identicon
88

99
import (
10+
"crypto/sha256"
1011
"fmt"
1112
"image"
1213
"image/color"
13-
14-
"github.com/minio/sha256-simd"
1514
)
1615

1716
const minImageSize = 16

modules/base/tool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package base
55

66
import (
77
"crypto/sha1"
8+
"crypto/sha256"
89
"encoding/base64"
910
"encoding/hex"
1011
"errors"
@@ -22,7 +23,6 @@ import (
2223
"code.gitea.io/gitea/modules/setting"
2324

2425
"github.com/dustin/go-humanize"
25-
"github.com/minio/sha256-simd"
2626
)
2727

2828
// EncodeSha1 string to sha1 hex value.

modules/git/blame.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ func (r *BlameReader) NextPart() (*BlamePart, error) {
115115

116116
// Close BlameReader - don't run NextPart after invoking that
117117
func (r *BlameReader) Close() error {
118+
if r.bufferedReader == nil {
119+
return nil
120+
}
121+
118122
err := <-r.done
119123
r.bufferedReader = nil
120124
_ = r.reader.Close()

modules/git/git.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ var (
3333
// DefaultContext is the default context to run git commands in, must be initialized by git.InitXxx
3434
DefaultContext context.Context
3535

36-
SupportProcReceive bool // >= 2.29
37-
SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
36+
DefaultFeatures struct {
37+
GitVersion *version.Version
3838

39-
gitVersion *version.Version
39+
SupportProcReceive bool // >= 2.29
40+
SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
41+
}
4042
)
4143

4244
// loadGitVersion tries to get the current git version and stores it into a global variable
4345
func loadGitVersion() error {
4446
// doesn't need RWMutex because it's executed by Init()
45-
if gitVersion != nil {
47+
if DefaultFeatures.GitVersion != nil {
4648
return nil
4749
}
4850

@@ -53,7 +55,7 @@ func loadGitVersion() error {
5355

5456
ver, err := parseGitVersionLine(strings.TrimSpace(stdout))
5557
if err == nil {
56-
gitVersion = ver
58+
DefaultFeatures.GitVersion = ver
5759
}
5860
return err
5961
}
@@ -93,7 +95,7 @@ func SetExecutablePath(path string) error {
9395
return err
9496
}
9597

96-
if gitVersion.LessThan(versionRequired) {
98+
if DefaultFeatures.GitVersion.LessThan(versionRequired) {
9799
moreHint := "get git: https://git-scm.com/download/"
98100
if runtime.GOOS == "linux" {
99101
// there are a lot of CentOS/RHEL users using old git, so we add a special hint for them
@@ -102,22 +104,22 @@ func SetExecutablePath(path string) error {
102104
moreHint = "get git: https://git-scm.com/download/linux and https://ius.io"
103105
}
104106
}
105-
return fmt.Errorf("installed git version %q is not supported, Gitea requires git version >= %q, %s", gitVersion.Original(), RequiredVersion, moreHint)
107+
return fmt.Errorf("installed git version %q is not supported, Gitea requires git version >= %q, %s", DefaultFeatures.GitVersion.Original(), RequiredVersion, moreHint)
106108
}
107109

108-
if err = checkGitVersionCompatibility(gitVersion); err != nil {
109-
return fmt.Errorf("installed git version %s has a known compatibility issue with Gitea: %w, please upgrade (or downgrade) git", gitVersion.String(), err)
110+
if err = checkGitVersionCompatibility(DefaultFeatures.GitVersion); err != nil {
111+
return fmt.Errorf("installed git version %s has a known compatibility issue with Gitea: %w, please upgrade (or downgrade) git", DefaultFeatures.GitVersion.String(), err)
110112
}
111113
return nil
112114
}
113115

114116
// VersionInfo returns git version information
115117
func VersionInfo() string {
116-
if gitVersion == nil {
118+
if DefaultFeatures.GitVersion == nil {
117119
return "(git not found)"
118120
}
119121
format := "%s"
120-
args := []any{gitVersion.Original()}
122+
args := []any{DefaultFeatures.GitVersion.Original()}
121123
// Since git wire protocol has been released from git v2.18
122124
if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
123125
format += ", Wire Protocol %s Enabled"
@@ -187,9 +189,9 @@ func InitFull(ctx context.Context) (err error) {
187189
if CheckGitVersionAtLeast("2.9") == nil {
188190
globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=")
189191
}
190-
SupportProcReceive = CheckGitVersionAtLeast("2.29") == nil
191-
SupportHashSha256 = CheckGitVersionAtLeast("2.42") == nil && !isGogit
192-
if SupportHashSha256 {
192+
DefaultFeatures.SupportProcReceive = CheckGitVersionAtLeast("2.29") == nil
193+
DefaultFeatures.SupportHashSha256 = CheckGitVersionAtLeast("2.42") == nil && !isGogit
194+
if DefaultFeatures.SupportHashSha256 {
193195
SupportedObjectFormats = append(SupportedObjectFormats, Sha256ObjectFormat)
194196
} else {
195197
log.Warn("sha256 hash support is disabled - requires Git >= 2.42. Gogit is currently unsupported")
@@ -254,7 +256,7 @@ func syncGitConfig() (err error) {
254256
}
255257
}
256258

257-
if SupportProcReceive {
259+
if DefaultFeatures.SupportProcReceive {
258260
// set support for AGit flow
259261
if err := configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil {
260262
return err
@@ -309,15 +311,15 @@ func syncGitConfig() (err error) {
309311

310312
// CheckGitVersionAtLeast check git version is at least the constraint version
311313
func CheckGitVersionAtLeast(atLeast string) error {
312-
if gitVersion == nil {
314+
if DefaultFeatures.GitVersion == nil {
313315
panic("git module is not initialized") // it shouldn't happen
314316
}
315317
atLeastVersion, err := version.NewVersion(atLeast)
316318
if err != nil {
317319
return err
318320
}
319-
if gitVersion.Compare(atLeastVersion) < 0 {
320-
return fmt.Errorf("installed git binary version %s is not at least %s", gitVersion.Original(), atLeast)
321+
if DefaultFeatures.GitVersion.Compare(atLeastVersion) < 0 {
322+
return fmt.Errorf("installed git binary version %s is not at least %s", DefaultFeatures.GitVersion.Original(), atLeast)
321323
}
322324
return nil
323325
}

modules/git/last_commit_cache.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
package git
55

66
import (
7+
"crypto/sha256"
78
"fmt"
89

910
"code.gitea.io/gitea/modules/log"
1011
"code.gitea.io/gitea/modules/setting"
11-
12-
"github.com/minio/sha256-simd"
1312
)
1413

1514
// Cache represents a caching interface

modules/git/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func InitRepository(ctx context.Context, repoPath string, bare bool, objectForma
101101
if !IsValidObjectFormat(objectFormatName) {
102102
return fmt.Errorf("invalid object format: %s", objectFormatName)
103103
}
104-
if SupportHashSha256 {
104+
if DefaultFeatures.SupportHashSha256 {
105105
cmd.AddOptionValues("--object-format", objectFormatName)
106106
}
107107

modules/git/repo_base_gogit.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,17 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
8888
}
8989

9090
// Close this repository, in particular close the underlying gogitStorage if this is not nil
91-
func (repo *Repository) Close() (err error) {
91+
func (repo *Repository) Close() error {
9292
if repo == nil || repo.gogitStorage == nil {
93-
return
93+
return nil
9494
}
9595
if err := repo.gogitStorage.Close(); err != nil {
9696
gitealog.Error("Error closing storage: %v", err)
9797
}
98+
repo.gogitStorage = nil
9899
repo.LastCommitCache = nil
99100
repo.tagCache = nil
100-
return
101+
return nil
101102
}
102103

103104
// GoGitRepo gets the go-git repo representation

0 commit comments

Comments
 (0)