Skip to content

Commit 95c8978

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated licenses and gitignores Fix bug for generated repository object format (go-gitea#28969) Fixing small space missing in sample config file (go-gitea#28967) Fix inconsistent naming of OAuth 2.0 `ENABLE` setting (go-gitea#28951) Add screenshot for "Profile Readmes" to docs (go-gitea#28964) Simplify how git repositories are opened (go-gitea#28937) Preserve BOM in web editor (go-gitea#28935) Make loading animation less aggressive (go-gitea#28955) Fix SSPI user creation (go-gitea#28948) Strip `/` from relative links (go-gitea#28932) Fix non-alphabetic sorting of repo topics (go-gitea#28938) Don't remove all mirror repository's releases when mirroring (go-gitea#28817) Use new RPM constants (go-gitea#28931) Check for sha256 support to use --object-format flag (go-gitea#28928) fix: update enable_prune even if mirror_interval is not provided (go-gitea#28905) Implement `MigrateRepository` for the actions notifier (go-gitea#28920) Respect branch info for relative links (go-gitea#28909)
2 parents 40a7eb6 + 2a50d78 commit 95c8978

File tree

115 files changed

+751
-467
lines changed

Some content is hidden

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

115 files changed

+751
-467
lines changed

cmd/admin.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/models/db"
1212
repo_model "code.gitea.io/gitea/models/repo"
1313
"code.gitea.io/gitea/modules/git"
14+
"code.gitea.io/gitea/modules/gitrepo"
1415
"code.gitea.io/gitea/modules/log"
1516
repo_module "code.gitea.io/gitea/modules/repository"
1617

@@ -122,7 +123,7 @@ func runRepoSyncReleases(_ *cli.Context) error {
122123
log.Trace("Processing next %d repos of %d", len(repos), count)
123124
for _, repo := range repos {
124125
log.Trace("Synchronizing repo %s with path %s", repo.FullName(), repo.RepoPath())
125-
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
126+
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
126127
if err != nil {
127128
log.Warn("OpenRepository: %v", err)
128129
continue

custom/conf/app.example.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ SECRET_KEY =
431431
;SECRET_KEY_URI = file:/etc/gitea/secret_key
432432
;;
433433
;; Secret used to validate communication within Gitea binary.
434-
INTERNAL_TOKEN=
434+
INTERNAL_TOKEN =
435435
;;
436436
;; Alternative location to specify internal token, instead of this file; you cannot specify both this and INTERNAL_TOKEN, and must pick one
437437
;INTERNAL_TOKEN_URI = file:/etc/gitea/internal_token
@@ -524,7 +524,7 @@ INTERNAL_TOKEN=
524524
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
525525
;;
526526
;; Enables OAuth2 provider
527-
ENABLE = true
527+
ENABLED = true
528528
;;
529529
;; Algorithm used to sign OAuth2 tokens. Valid values: HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512, EdDSA
530530
;JWT_SIGNING_ALGORITHM = RS256

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ This section only does "set" config, a removed config key from this section won'
11071107

11081108
## OAuth2 (`oauth2`)
11091109

1110-
- `ENABLE`: **true**: Enables OAuth2 provider.
1110+
- `ENABLED`: **true**: Enables OAuth2 provider.
11111111
- `ACCESS_TOKEN_EXPIRATION_TIME`: **3600**: Lifetime of an OAuth2 access token in seconds
11121112
- `REFRESH_TOKEN_EXPIRATION_TIME`: **730**: Lifetime of an OAuth2 refresh token in hours
11131113
- `INVALIDATE_REFRESH_TOKENS`: **false**: Check if refresh token has already been used

docs/content/administration/config-cheat-sheet.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ Gitea 创建以下非唯一队列:
10431043

10441044
## OAuth2 (`oauth2`)
10451045

1046-
- `ENABLE`: **true**:启用OAuth2提供者。
1046+
- `ENABLED`: **true**:启用OAuth2提供者。
10471047
- `ACCESS_TOKEN_EXPIRATION_TIME`**3600**:OAuth2访问令牌的生命周期,以秒为单位。
10481048
- `REFRESH_TOKEN_EXPIRATION_TIME`**730**:OAuth2刷新令牌的生命周期,以小时为单位。
10491049
- `INVALIDATE_REFRESH_TOKENS`**false**:检查刷新令牌是否已被使用。

docs/content/usage/profile-readme.en-us.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ To display a Markdown file in your Gitea user or organization profile page, crea
1919
Gitea will automatically display the contents of the file on your profile, in a new "Overview" above your repositories.
2020

2121
Making the `.profile` repository private will hide the Profile README.
22+
23+
Example of user with `.profile/README.md`:
24+
25+
![profile readme screenshot](./profile-readme.png)

docs/content/usage/profile-readme.png

32.9 KB
Loading

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ require (
9292
github.com/redis/go-redis/v9 v9.4.0
9393
github.com/robfig/cron/v3 v3.0.1
9494
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
95-
github.com/sassoftware/go-rpmutils v0.2.0
95+
github.com/sassoftware/go-rpmutils v0.2.1-0.20240124161140-277b154961dd
9696
github.com/sergi/go-diff v1.3.1
9797
github.com/shurcooL/vfsgen v0.0.0-20230704071429-0000e147ea92
9898
github.com/stretchr/testify v1.8.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,8 @@ github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6g
781781
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
782782
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
783783
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
784-
github.com/sassoftware/go-rpmutils v0.2.0 h1:pKW0HDYMFWQ5b4JQPiI3WI12hGsVoW0V8+GMoZiI/JE=
785-
github.com/sassoftware/go-rpmutils v0.2.0/go.mod h1:TJJQYtLe/BeEmEjelI3b7xNZjzAukEkeWKmoakvaOoI=
784+
github.com/sassoftware/go-rpmutils v0.2.1-0.20240124161140-277b154961dd h1:KpbqRPDwcAQTyaP+L+YudTRb3CnJlQ64Hfn1SF/zHBA=
785+
github.com/sassoftware/go-rpmutils v0.2.1-0.20240124161140-277b154961dd/go.mod h1:TJJQYtLe/BeEmEjelI3b7xNZjzAukEkeWKmoakvaOoI=
786786
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
787787
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
788788
github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs=

models/activities/repo_activity.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
repo_model "code.gitea.io/gitea/models/repo"
1515
user_model "code.gitea.io/gitea/models/user"
1616
"code.gitea.io/gitea/modules/git"
17+
"code.gitea.io/gitea/modules/gitrepo"
1718

1819
"xorm.io/xorm"
1920
)
@@ -65,7 +66,7 @@ func GetActivityStats(ctx context.Context, repo *repo_model.Repository, timeFrom
6566
return nil, fmt.Errorf("FillUnresolvedIssues: %w", err)
6667
}
6768
if code {
68-
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
69+
gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
6970
if err != nil {
7071
return nil, fmt.Errorf("OpenRepository: %w", err)
7172
}
@@ -82,7 +83,7 @@ func GetActivityStats(ctx context.Context, repo *repo_model.Repository, timeFrom
8283

8384
// GetActivityStatsTopAuthors returns top author stats for git commits for all branches
8485
func GetActivityStatsTopAuthors(ctx context.Context, repo *repo_model.Repository, timeFrom time.Time, count int) ([]*ActivityAuthorData, error) {
85-
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
86+
gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
8687
if err != nil {
8788
return nil, fmt.Errorf("OpenRepository: %w", err)
8889
}

models/issues/comment.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
repo_model "code.gitea.io/gitea/models/repo"
1919
user_model "code.gitea.io/gitea/models/user"
2020
"code.gitea.io/gitea/modules/container"
21-
"code.gitea.io/gitea/modules/git"
21+
"code.gitea.io/gitea/modules/gitrepo"
2222
"code.gitea.io/gitea/modules/json"
2323
"code.gitea.io/gitea/modules/log"
2424
"code.gitea.io/gitea/modules/references"
@@ -762,8 +762,7 @@ func (c *Comment) LoadPushCommits(ctx context.Context) (err error) {
762762
c.OldCommit = data.CommitIDs[0]
763763
c.NewCommit = data.CommitIDs[1]
764764
} else {
765-
repoPath := c.Issue.Repo.RepoPath()
766-
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repoPath)
765+
gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, c.Issue.Repo)
767766
if err != nil {
768767
return err
769768
}

models/issues/pull.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
repo_model "code.gitea.io/gitea/models/repo"
2020
user_model "code.gitea.io/gitea/models/user"
2121
"code.gitea.io/gitea/modules/git"
22+
"code.gitea.io/gitea/modules/gitrepo"
2223
"code.gitea.io/gitea/modules/log"
2324
"code.gitea.io/gitea/modules/setting"
2425
"code.gitea.io/gitea/modules/timeutil"
@@ -865,7 +866,7 @@ func PullRequestCodeOwnersReview(ctx context.Context, pull *Issue, pr *PullReque
865866
return err
866867
}
867868

868-
repo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
869+
repo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
869870
if err != nil {
870871
return err
871872
}

models/repo/repo.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ func init() {
196196
db.RegisterModel(new(Repository))
197197
}
198198

199+
func (repo *Repository) GetName() string {
200+
return repo.Name
201+
}
202+
203+
func (repo *Repository) GetOwnerName() string {
204+
return repo.OwnerName
205+
}
206+
199207
// SanitizedOriginalURL returns a sanitized OriginalURL
200208
func (repo *Repository) SanitizedOriginalURL() string {
201209
if repo.OriginalURL == "" {

models/repo/topic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func syncTopicsInRepository(sess db.Engine, repoID int64) error {
366366
topicNames := make([]string, 0, 25)
367367
if err := sess.Table("topic").Cols("name").
368368
Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id").
369-
Where("repo_topic.repo_id = ?", repoID).Desc("topic.repo_count").Find(&topicNames); err != nil {
369+
Where("repo_topic.repo_id = ?", repoID).Asc("topic.name").Find(&topicNames); err != nil {
370370
return err
371371
}
372372

modules/charset/charset.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,21 @@ import (
2222
// UTF8BOM is the utf-8 byte-order marker
2323
var UTF8BOM = []byte{'\xef', '\xbb', '\xbf'}
2424

25+
type ConvertOpts struct {
26+
KeepBOM bool
27+
}
28+
2529
// ToUTF8WithFallbackReader detects the encoding of content and converts to UTF-8 reader if possible
26-
func ToUTF8WithFallbackReader(rd io.Reader) io.Reader {
30+
func ToUTF8WithFallbackReader(rd io.Reader, opts ConvertOpts) io.Reader {
2731
buf := make([]byte, 2048)
2832
n, err := util.ReadAtMost(rd, buf)
2933
if err != nil {
30-
return io.MultiReader(bytes.NewReader(RemoveBOMIfPresent(buf[:n])), rd)
34+
return io.MultiReader(bytes.NewReader(MaybeRemoveBOM(buf[:n], opts)), rd)
3135
}
3236

3337
charsetLabel, err := DetectEncoding(buf[:n])
3438
if err != nil || charsetLabel == "UTF-8" {
35-
return io.MultiReader(bytes.NewReader(RemoveBOMIfPresent(buf[:n])), rd)
39+
return io.MultiReader(bytes.NewReader(MaybeRemoveBOM(buf[:n], opts)), rd)
3640
}
3741

3842
encoding, _ := charset.Lookup(charsetLabel)
@@ -42,20 +46,20 @@ func ToUTF8WithFallbackReader(rd io.Reader) io.Reader {
4246

4347
return transform.NewReader(
4448
io.MultiReader(
45-
bytes.NewReader(RemoveBOMIfPresent(buf[:n])),
49+
bytes.NewReader(MaybeRemoveBOM(buf[:n], opts)),
4650
rd,
4751
),
4852
encoding.NewDecoder(),
4953
)
5054
}
5155

52-
// ToUTF8WithErr converts content to UTF8 encoding
53-
func ToUTF8WithErr(content []byte) (string, error) {
56+
// ToUTF8 converts content to UTF8 encoding
57+
func ToUTF8(content []byte, opts ConvertOpts) (string, error) {
5458
charsetLabel, err := DetectEncoding(content)
5559
if err != nil {
5660
return "", err
5761
} else if charsetLabel == "UTF-8" {
58-
return string(RemoveBOMIfPresent(content)), nil
62+
return string(MaybeRemoveBOM(content, opts)), nil
5963
}
6064

6165
encoding, _ := charset.Lookup(charsetLabel)
@@ -70,28 +74,22 @@ func ToUTF8WithErr(content []byte) (string, error) {
7074
result = append(result, content[n:]...)
7175
}
7276

73-
result = RemoveBOMIfPresent(result)
77+
result = MaybeRemoveBOM(result, opts)
7478

7579
return string(result), err
7680
}
7781

7882
// ToUTF8WithFallback detects the encoding of content and converts to UTF-8 if possible
79-
func ToUTF8WithFallback(content []byte) []byte {
80-
bs, _ := io.ReadAll(ToUTF8WithFallbackReader(bytes.NewReader(content)))
83+
func ToUTF8WithFallback(content []byte, opts ConvertOpts) []byte {
84+
bs, _ := io.ReadAll(ToUTF8WithFallbackReader(bytes.NewReader(content), opts))
8185
return bs
8286
}
8387

84-
// ToUTF8 converts content to UTF8 encoding and ignore error
85-
func ToUTF8(content string) string {
86-
res, _ := ToUTF8WithErr([]byte(content))
87-
return res
88-
}
89-
9088
// ToUTF8DropErrors makes sure the return string is valid utf-8; attempts conversion if possible
91-
func ToUTF8DropErrors(content []byte) []byte {
89+
func ToUTF8DropErrors(content []byte, opts ConvertOpts) []byte {
9290
charsetLabel, err := DetectEncoding(content)
9391
if err != nil || charsetLabel == "UTF-8" {
94-
return RemoveBOMIfPresent(content)
92+
return MaybeRemoveBOM(content, opts)
9593
}
9694

9795
encoding, _ := charset.Lookup(charsetLabel)
@@ -117,11 +115,14 @@ func ToUTF8DropErrors(content []byte) []byte {
117115
}
118116
}
119117

120-
return RemoveBOMIfPresent(decoded)
118+
return MaybeRemoveBOM(decoded, opts)
121119
}
122120

123-
// RemoveBOMIfPresent removes a UTF-8 BOM from a []byte
124-
func RemoveBOMIfPresent(content []byte) []byte {
121+
// MaybeRemoveBOM removes a UTF-8 BOM from a []byte when opts.KeepBOM is false
122+
func MaybeRemoveBOM(content []byte, opts ConvertOpts) []byte {
123+
if opts.KeepBOM {
124+
return content
125+
}
125126
if len(content) > 2 && bytes.Equal(content[0:3], UTF8BOM) {
126127
return content[3:]
127128
}

0 commit comments

Comments
 (0)