Skip to content

Commit ede9146

Browse files
committed
Merge branch 'main' into zzc/dev/split_lfs_size
2 parents a5fb15e + ca445cf commit ede9146

File tree

173 files changed

+901
-586
lines changed

Some content is hidden

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

173 files changed

+901
-586
lines changed

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Kim Carlbäcker <[email protected]> (@bkcsoft)
66
LefsFlare <[email protected]> (@LefsFlarey)
77
Lunny Xiao <[email protected]> (@lunny)
88
Matthias Loibl <[email protected]> (@metalmatze)
9-
Morgan Bazalgette <[email protected]> (@thehowl)
109
Rachid Zarouali <[email protected]> (@xinity)
1110
Rémy Boulanouar <[email protected]> (@DblK)
1211
Sandro Santilli <[email protected]> (@strk)

cmd/admin_user_delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func runDeleteUser(c *cli.Context) error {
5757
var err error
5858
var user *user_model.User
5959
if c.IsSet("email") {
60-
user, err = user_model.GetUserByEmail(c.String("email"))
60+
user, err = user_model.GetUserByEmail(ctx, c.String("email"))
6161
} else if c.IsSet("username") {
6262
user, err = user_model.GetUserByName(ctx, c.String("username"))
6363
} else {

contrib/backport/backport.go

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func main() {
7979
Name: "no-xdg-open",
8080
Usage: "Set this flag to not use xdg-open to open the PR URL",
8181
},
82+
cli.BoolFlag{
83+
Name: "continue",
84+
Usage: "Set this flag to continue from a git cherry-pick that has broken",
85+
},
8286
}
8387
cli.AppHelpTemplate = `NAME:
8488
{{.Name}} - {{.Usage}}
@@ -104,7 +108,19 @@ func runBackport(c *cli.Context) error {
104108
ctx, cancel := installSignals()
105109
defer cancel()
106110

111+
continuing := c.Bool("continue")
112+
113+
var pr string
114+
107115
version := c.String("version")
116+
if version == "" && continuing {
117+
// determine version from current branch name
118+
var err error
119+
pr, version, err = readCurrentBranch(ctx)
120+
if err != nil {
121+
return err
122+
}
123+
}
108124
if version == "" {
109125
version = readVersion()
110126
}
@@ -135,13 +151,14 @@ func runBackport(c *cli.Context) error {
135151
localReleaseBranch := path.Join(upstream, upstreamReleaseBranch)
136152

137153
args := c.Args()
138-
if len(args) == 0 {
154+
if len(args) == 0 && pr == "" {
139155
return fmt.Errorf("no PR number provided\nProvide a PR number to backport")
140-
} else if len(args) != 1 {
156+
} else if len(args) != 1 && pr == "" {
141157
return fmt.Errorf("multiple PRs provided %v\nOnly a single PR can be backported at a time", args)
142158
}
143-
144-
pr := args[0]
159+
if pr == "" {
160+
pr = args[0]
161+
}
145162

146163
backportBranch := c.String("backport-branch")
147164
if backportBranch == "" {
@@ -168,8 +185,10 @@ func runBackport(c *cli.Context) error {
168185
}
169186
}
170187

171-
if err := checkoutBackportBranch(ctx, backportBranch, localReleaseBranch); err != nil {
172-
return err
188+
if !continuing {
189+
if err := checkoutBackportBranch(ctx, backportBranch, localReleaseBranch); err != nil {
190+
return err
191+
}
173192
}
174193

175194
if err := cherrypick(ctx, sha); err != nil {
@@ -353,6 +372,22 @@ func determineRemote(ctx context.Context, forkUser string) (string, string, erro
353372
return "", "", fmt.Errorf("unable to find appropriate remote in:\n%s", string(out))
354373
}
355374

375+
func readCurrentBranch(ctx context.Context) (pr, version string, err error) {
376+
out, err := exec.CommandContext(ctx, "git", "branch", "--show-current").Output()
377+
if err != nil {
378+
fmt.Fprintf(os.Stderr, "Unable to read current git branch:\n%s\n", string(out))
379+
return "", "", fmt.Errorf("unable to read current git branch: %w", err)
380+
}
381+
parts := strings.Split(strings.TrimSpace(string(out)), "-")
382+
383+
if len(parts) != 3 || parts[0] != "backport" {
384+
fmt.Fprintf(os.Stderr, "Unable to continue from git branch:\n%s\n", string(out))
385+
return "", "", fmt.Errorf("unable to continue from git branch:\n%s", string(out))
386+
}
387+
388+
return parts[1], parts[2], nil
389+
}
390+
356391
func readVersion() string {
357392
bs, err := os.ReadFile("docs/config.yaml")
358393
if err != nil {

models/activities/repo_activity.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ func GetActivityStatsTopAuthors(ctx context.Context, repo *repo_model.Repository
9797
}
9898
users := make(map[int64]*ActivityAuthorData)
9999
var unknownUserID int64
100-
unknownUserAvatarLink := user_model.NewGhostUser().AvatarLink()
100+
unknownUserAvatarLink := user_model.NewGhostUser().AvatarLink(ctx)
101101
for _, v := range code.Authors {
102102
if len(v.Email) == 0 {
103103
continue
104104
}
105-
u, err := user_model.GetUserByEmail(v.Email)
105+
u, err := user_model.GetUserByEmail(ctx, v.Email)
106106
if u == nil || user_model.IsErrUserNotExist(err) {
107107
unknownUserID--
108108
users[unknownUserID] = &ActivityAuthorData{
@@ -119,7 +119,7 @@ func GetActivityStatsTopAuthors(ctx context.Context, repo *repo_model.Repository
119119
users[u.ID] = &ActivityAuthorData{
120120
Name: u.DisplayName(),
121121
Login: u.LowerName,
122-
AvatarLink: u.AvatarLink(),
122+
AvatarLink: u.AvatarLink(ctx),
123123
HomeLink: u.HomeLink(),
124124
Commits: v.Commits,
125125
}

models/asymkey/gpg_key_commit_verification.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package asymkey
55

66
import (
7+
"context"
78
"fmt"
89
"hash"
910
"strings"
@@ -70,14 +71,14 @@ const (
7071
)
7172

7273
// ParseCommitsWithSignature checks if signaute of commits are corresponding to users gpg keys.
73-
func ParseCommitsWithSignature(oldCommits []*user_model.UserCommit, repoTrustModel repo_model.TrustModelType, isOwnerMemberCollaborator func(*user_model.User) (bool, error)) []*SignCommit {
74+
func ParseCommitsWithSignature(ctx context.Context, oldCommits []*user_model.UserCommit, repoTrustModel repo_model.TrustModelType, isOwnerMemberCollaborator func(*user_model.User) (bool, error)) []*SignCommit {
7475
newCommits := make([]*SignCommit, 0, len(oldCommits))
7576
keyMap := map[string]bool{}
7677

7778
for _, c := range oldCommits {
7879
signCommit := &SignCommit{
7980
UserCommit: c,
80-
Verification: ParseCommitWithSignature(c.Commit),
81+
Verification: ParseCommitWithSignature(ctx, c.Commit),
8182
}
8283

8384
_ = CalculateTrustStatus(signCommit.Verification, repoTrustModel, isOwnerMemberCollaborator, &keyMap)
@@ -88,13 +89,13 @@ func ParseCommitsWithSignature(oldCommits []*user_model.UserCommit, repoTrustMod
8889
}
8990

9091
// ParseCommitWithSignature check if signature is good against keystore.
91-
func ParseCommitWithSignature(c *git.Commit) *CommitVerification {
92+
func ParseCommitWithSignature(ctx context.Context, c *git.Commit) *CommitVerification {
9293
var committer *user_model.User
9394
if c.Committer != nil {
9495
var err error
9596
// Find Committer account
96-
committer, err = user_model.GetUserByEmail(c.Committer.Email) // This finds the user by primary email or activated email so commit will not be valid if email is not
97-
if err != nil { // Skipping not user for committer
97+
committer, err = user_model.GetUserByEmail(ctx, c.Committer.Email) // This finds the user by primary email or activated email so commit will not be valid if email is not
98+
if err != nil { // Skipping not user for committer
9899
committer = &user_model.User{
99100
Name: c.Committer.Name,
100101
Email: c.Committer.Email,

models/asymkey/gpg_key_import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import "code.gitea.io/gitea/models/db"
2323
// GPGKeyImport the original import of key
2424
type GPGKeyImport struct {
2525
KeyID string `xorm:"pk CHAR(16) NOT NULL"`
26-
Content string `xorm:"TEXT NOT NULL"`
26+
Content string `xorm:"MEDIUMTEXT NOT NULL"`
2727
}
2828

2929
func init() {

models/avatars/avatar.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ func generateRecognizedAvatarURL(u url.URL, size int) string {
147147
// generateEmailAvatarLink returns a email avatar link.
148148
// if final is true, it may use a slow path (eg: query DNS).
149149
// if final is false, it always uses a fast path.
150-
func generateEmailAvatarLink(email string, size int, final bool) string {
150+
func generateEmailAvatarLink(ctx context.Context, email string, size int, final bool) string {
151151
email = strings.TrimSpace(email)
152152
if email == "" {
153153
return DefaultAvatarLink()
154154
}
155155

156-
enableFederatedAvatar := system_model.GetSettingBool(system_model.KeyPictureEnableFederatedAvatar)
156+
enableFederatedAvatar := system_model.GetSettingBool(ctx, system_model.KeyPictureEnableFederatedAvatar)
157157

158158
var err error
159159
if enableFederatedAvatar && system_model.LibravatarService != nil {
@@ -174,7 +174,7 @@ func generateEmailAvatarLink(email string, size int, final bool) string {
174174
return urlStr
175175
}
176176

177-
disableGravatar := system_model.GetSettingBool(system_model.KeyPictureDisableGravatar)
177+
disableGravatar := system_model.GetSettingBool(ctx, system_model.KeyPictureDisableGravatar)
178178
if !disableGravatar {
179179
// copy GravatarSourceURL, because we will modify its Path.
180180
avatarURLCopy := *system_model.GravatarSourceURL
@@ -186,11 +186,11 @@ func generateEmailAvatarLink(email string, size int, final bool) string {
186186
}
187187

188188
// GenerateEmailAvatarFastLink returns a avatar link (fast, the link may be a delegated one: "/avatar/${hash}")
189-
func GenerateEmailAvatarFastLink(email string, size int) string {
190-
return generateEmailAvatarLink(email, size, false)
189+
func GenerateEmailAvatarFastLink(ctx context.Context, email string, size int) string {
190+
return generateEmailAvatarLink(ctx, email, size, false)
191191
}
192192

193193
// GenerateEmailAvatarFinalLink returns a avatar final link (maybe slow)
194-
func GenerateEmailAvatarFinalLink(email string, size int) string {
195-
return generateEmailAvatarLink(email, size, true)
194+
func GenerateEmailAvatarFinalLink(ctx context.Context, email string, size int) string {
195+
return generateEmailAvatarLink(ctx, email, size, true)
196196
}

models/avatars/avatar_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
avatars_model "code.gitea.io/gitea/models/avatars"
10+
"code.gitea.io/gitea/models/db"
1011
system_model "code.gitea.io/gitea/models/system"
1112
"code.gitea.io/gitea/modules/setting"
1213

@@ -16,15 +17,15 @@ import (
1617
const gravatarSource = "https://secure.gravatar.com/avatar/"
1718

1819
func disableGravatar(t *testing.T) {
19-
err := system_model.SetSettingNoVersion(system_model.KeyPictureEnableFederatedAvatar, "false")
20+
err := system_model.SetSettingNoVersion(db.DefaultContext, system_model.KeyPictureEnableFederatedAvatar, "false")
2021
assert.NoError(t, err)
21-
err = system_model.SetSettingNoVersion(system_model.KeyPictureDisableGravatar, "true")
22+
err = system_model.SetSettingNoVersion(db.DefaultContext, system_model.KeyPictureDisableGravatar, "true")
2223
assert.NoError(t, err)
2324
system_model.LibravatarService = nil
2425
}
2526

2627
func enableGravatar(t *testing.T) {
27-
err := system_model.SetSettingNoVersion(system_model.KeyPictureDisableGravatar, "false")
28+
err := system_model.SetSettingNoVersion(db.DefaultContext, system_model.KeyPictureDisableGravatar, "false")
2829
assert.NoError(t, err)
2930
setting.GravatarSource = gravatarSource
3031
err = system_model.Init()
@@ -47,11 +48,11 @@ func TestSizedAvatarLink(t *testing.T) {
4748

4849
disableGravatar(t)
4950
assert.Equal(t, "/testsuburl/assets/img/avatar_default.png",
50-
avatars_model.GenerateEmailAvatarFastLink("[email protected]", 100))
51+
avatars_model.GenerateEmailAvatarFastLink(db.DefaultContext, "[email protected]", 100))
5152

5253
enableGravatar(t)
5354
assert.Equal(t,
5455
"https://secure.gravatar.com/avatar/353cbad9b58e69c96154ad99f92bedc7?d=identicon&s=100",
55-
avatars_model.GenerateEmailAvatarFastLink("[email protected]", 100),
56+
avatars_model.GenerateEmailAvatarFastLink(db.DefaultContext, "[email protected]", 100),
5657
)
5758
}

models/git/commit_status.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ func hashCommitStatusContext(context string) string {
351351
func ConvertFromGitCommit(ctx context.Context, commits []*git.Commit, repo *repo_model.Repository) []*SignCommitWithStatuses {
352352
return ParseCommitsWithStatus(ctx,
353353
asymkey_model.ParseCommitsWithSignature(
354-
user_model.ValidateCommitsWithEmails(commits),
354+
ctx,
355+
user_model.ValidateCommitsWithEmails(ctx, commits),
355356
repo.GetTrustModel(),
356357
func(user *user_model.User) (bool, error) {
357358
return repo_model.IsOwnerMemberCollaborator(repo, user.ID)

models/issues/comment.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,3 +1244,8 @@ func FixCommentTypeLabelWithOutsideLabels(ctx context.Context) (int64, error) {
12441244

12451245
return res.RowsAffected()
12461246
}
1247+
1248+
// HasOriginalAuthor returns if a comment was migrated and has an original author.
1249+
func (c *Comment) HasOriginalAuthor() bool {
1250+
return c.OriginalAuthor != "" && c.OriginalAuthorID != 0
1251+
}

models/issues/issue.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,3 +2403,8 @@ func DeleteOrphanedIssues(ctx context.Context) error {
24032403
}
24042404
return nil
24052405
}
2406+
2407+
// HasOriginalAuthor returns if an issue was migrated and has an original author.
2408+
func (issue *Issue) HasOriginalAuthor() bool {
2409+
return issue.OriginalAuthor != "" && issue.OriginalAuthorID != 0
2410+
}

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ var migrations = []Migration{
458458
// v241 -> v242
459459
NewMigration("Add card_type column to project table", v1_19.AddCardTypeToProjectTable),
460460
// v242 -> v243
461+
NewMigration("Alter gpg_key_import content TEXT field to MEDIUMTEXT", v1_19.AlterPublicGPGKeyImportContentFieldToMediumText),
462+
// v243 -> v244
461463
NewMigration("Add lfs_size column to repository table", v1_19.AddLFSSizeToRepositoryTable),
462464
}
463465

models/migrations/v1_19/v242.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@
44
package v1_19 //nolint
55

66
import (
7+
"code.gitea.io/gitea/modules/setting"
8+
79
"xorm.io/xorm"
810
)
911

10-
// AddLFSSizeToRepositoryTable: add LFSSize column to Repository
11-
func AddLFSSizeToRepositoryTable(x *xorm.Engine) error {
12-
type Repository struct {
13-
LFSSize int64 `xorm:"NOT NULL DEFAULT 0"`
12+
// AlterPublicGPGKeyImportContentFieldToMediumText: set GPGKeyImport Content field to MEDIUMTEXT
13+
func AlterPublicGPGKeyImportContentFieldToMediumText(x *xorm.Engine) error {
14+
sess := x.NewSession()
15+
defer sess.Close()
16+
if err := sess.Begin(); err != nil {
17+
return err
1418
}
1519

16-
return x.Sync2(new(Repository))
20+
if setting.Database.UseMySQL {
21+
if _, err := sess.Exec("ALTER TABLE `gpg_key_import` CHANGE `content` `content` MEDIUMTEXT"); err != nil {
22+
return err
23+
}
24+
}
25+
return sess.Commit()
1726
}

models/migrations/v1_19/v243.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_19 //nolint
5+
6+
import (
7+
"xorm.io/xorm"
8+
)
9+
10+
// AddLFSSizeToRepositoryTable: add LFSSize column to Repository
11+
func AddLFSSizeToRepositoryTable(x *xorm.Engine) error {
12+
type Repository struct {
13+
LFSSize int64 `xorm:"NOT NULL DEFAULT 0"`
14+
}
15+
16+
return x.Sync2(new(Repository))
17+
}

models/organization/org.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ func (org *Organization) hasMemberWithUserID(ctx context.Context, userID int64)
156156
}
157157

158158
// AvatarLink returns the full avatar link with http host
159-
func (org *Organization) AvatarLink() string {
160-
return org.AsUser().AvatarLink()
159+
func (org *Organization) AvatarLink(ctx context.Context) string {
160+
return org.AsUser().AvatarLink(ctx)
161161
}
162162

163163
// HTMLURL returns the organization's full link.

models/repo/avatar.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,7 @@ func (repo *Repository) relAvatarLink(ctx context.Context) string {
8585
}
8686

8787
// AvatarLink returns a link to the repository's avatar.
88-
func (repo *Repository) AvatarLink() string {
89-
return repo.avatarLink(db.DefaultContext)
90-
}
91-
92-
// avatarLink returns user avatar absolute link.
93-
func (repo *Repository) avatarLink(ctx context.Context) string {
88+
func (repo *Repository) AvatarLink(ctx context.Context) string {
9489
link := repo.relAvatarLink(ctx)
9590
// we only prepend our AppURL to our known (relative, internal) avatar link to get an absolute URL
9691
if strings.HasPrefix(link, "/") && !strings.HasPrefix(link, "//") {

0 commit comments

Comments
 (0)