Skip to content

Commit c92d8e5

Browse files
committed
Merge branch 'release/v1.21' into blender-merged-develop
2 parents 9517fd7 + b56a9f6 commit c92d8e5

File tree

25 files changed

+81
-50
lines changed

25 files changed

+81
-50
lines changed

models/migrations/v1_21/v263.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ func AddGitSizeAndLFSSizeToRepositoryTable(x *xorm.Engine) error {
3232
return err
3333
}
3434

35-
_, err = sess.Exec(`UPDATE repository SET git_size = size - lfs_size`)
35+
_, err = sess.Exec(`UPDATE repository SET size = 0 WHERE size IS NULL`)
36+
if err != nil {
37+
return err
38+
}
39+
40+
_, err = sess.Exec(`UPDATE repository SET git_size = size - lfs_size WHERE size > lfs_size`)
3641
if err != nil {
3742
return err
3843
}

modules/git/commit.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ func (c *Commit) Message() string {
4343
}
4444

4545
// Summary returns first line of commit message.
46+
// The string is forced to be valid UTF8
4647
func (c *Commit) Summary() string {
47-
return strings.Split(strings.TrimSpace(c.CommitMessage), "\n")[0]
48+
return strings.ToValidUTF8(strings.Split(strings.TrimSpace(c.CommitMessage), "\n")[0], "?")
4849
}
4950

5051
// ParentID returns oid of n-th parent (0-based index).

modules/setting/attachment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func loadAttachmentFrom(rootCfg ConfigProvider) (err error) {
2626
}
2727

2828
Attachment.AllowedTypes = sec.Key("ALLOWED_TYPES").MustString(".csv,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip")
29-
Attachment.MaxSize = sec.Key("MAX_SIZE").MustInt64(4)
29+
Attachment.MaxSize = sec.Key("MAX_SIZE").MustInt64(2048)
3030
Attachment.MaxFiles = sec.Key("MAX_FILES").MustInt(5)
3131
Attachment.Enabled = sec.Key("ENABLED").MustBool(true)
3232

modules/setting/database.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net"
1010
"net/url"
1111
"os"
12-
"path"
1312
"path/filepath"
1413
"strings"
1514
"time"
@@ -117,7 +116,7 @@ func DBConnStr() (string, error) {
117116
if !EnableSQLite3 {
118117
return "", errors.New("this Gitea binary was not built with SQLite3 support")
119118
}
120-
if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil {
119+
if err := os.MkdirAll(filepath.Dir(Database.Path), os.ModePerm); err != nil {
121120
return "", fmt.Errorf("Failed to create directories: %w", err)
122121
}
123122
journalMode := ""

routers/api/packages/api.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,10 @@ func CommonRoutes() *web.Route {
520520
r.Get("", rpm.DownloadPackageFile)
521521
r.Delete("", reqPackageAccess(perm.AccessModeWrite), rpm.DeletePackageFile)
522522
})
523-
r.Get("/repodata/{filename}", rpm.GetRepositoryFile)
523+
r.Group("/repodata/{filename}", func() {
524+
r.Head("", rpm.CheckRepositoryFileExistence)
525+
r.Get("", rpm.GetRepositoryFile)
526+
})
524527
}, reqPackageAccess(perm.AccessModeRead))
525528
r.Group("/rubygems", func() {
526529
r.Get("/specs.4.8.gz", rubygems.EnumeratePackages)

routers/api/packages/rpm/rpm.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@ func GetRepositoryKey(ctx *context.Context) {
5757
})
5858
}
5959

60+
func CheckRepositoryFileExistence(ctx *context.Context) {
61+
pv, err := rpm_service.GetOrCreateRepositoryVersion(ctx, ctx.Package.Owner.ID)
62+
if err != nil {
63+
apiError(ctx, http.StatusInternalServerError, err)
64+
return
65+
}
66+
67+
pf, err := packages_model.GetFileForVersionByName(ctx, pv.ID, ctx.Params("filename"), packages_model.EmptyFileKey)
68+
if err != nil {
69+
if errors.Is(err, util.ErrNotExist) {
70+
ctx.Status(http.StatusNotFound)
71+
} else {
72+
apiError(ctx, http.StatusInternalServerError, err)
73+
}
74+
return
75+
}
76+
77+
ctx.SetServeHeaders(&context.ServeHeaderOptions{
78+
Filename: pf.Name,
79+
LastModified: pf.CreatedUnix.AsLocalTime(),
80+
})
81+
ctx.Status(http.StatusOK)
82+
}
83+
6084
// Gets a pre-generated repository metadata file
6185
func GetRepositoryFile(ctx *context.Context) {
6286
pv, err := rpm_service.GetOrCreateRepositoryVersion(ctx, ctx.Package.Owner.ID)

routers/web/repo/actions/actions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func List(ctx *context.Context) {
201201
pager.AddParamString("actor", fmt.Sprint(actorID))
202202
pager.AddParamString("status", fmt.Sprint(status))
203203
ctx.Data["Page"] = pager
204+
ctx.Data["HasWorkflowsOrRuns"] = len(workflows) > 0 || len(runs) > 0
204205

205206
ctx.HTML(http.StatusOK, tplListActions)
206207
}

routers/web/repo/view.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -702,21 +702,14 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) {
702702
}
703703
for _, entry := range allEntries {
704704
if entry.Name() == "CITATION.cff" || entry.Name() == "CITATION.bib" {
705-
ctx.Data["CitiationExist"] = true
706705
// Read Citation file contents
707-
blob := entry.Blob()
708-
dataRc, err := blob.DataAsync()
709-
if err != nil {
710-
ctx.ServerError("DataAsync", err)
711-
return
712-
}
713-
defer dataRc.Close()
714-
ctx.PageData["citationFileContent"], err = blob.GetBlobContent(setting.UI.MaxDisplayFileSize)
715-
if err != nil {
716-
ctx.ServerError("GetBlobContent", err)
717-
return
706+
if content, err := entry.Blob().GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil {
707+
log.Error("checkCitationFile: GetBlobContent: %v", err)
708+
} else {
709+
ctx.Data["CitiationExist"] = true
710+
ctx.PageData["citationFileContent"] = content
711+
break
718712
}
719-
break
720713
}
721714
}
722715
}

services/migrations/gitea_uploader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
862862
line := comment.Line
863863
if line != 0 {
864864
comment.Position = 1
865-
} else {
865+
} else if comment.DiffHunk != "" {
866866
_, _, line, _ = git.ParseDiffHunkString(comment.DiffHunk)
867867
}
868868

services/packages/debian/repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func GetOrCreateKeyPair(ctx context.Context, ownerID int64) (string, string, err
6767
}
6868

6969
func generateKeypair() (string, string, error) {
70-
e, err := openpgp.NewEntity(setting.AppName, "Debian Registry", "", nil)
70+
e, err := openpgp.NewEntity("", "Debian Registry", "", nil)
7171
if err != nil {
7272
return "", "", err
7373
}

services/packages/rpm/repository.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"code.gitea.io/gitea/modules/json"
2323
packages_module "code.gitea.io/gitea/modules/packages"
2424
rpm_module "code.gitea.io/gitea/modules/packages/rpm"
25-
"code.gitea.io/gitea/modules/setting"
2625
"code.gitea.io/gitea/modules/util"
2726
packages_service "code.gitea.io/gitea/services/packages"
2827

@@ -68,7 +67,7 @@ func GetOrCreateKeyPair(ctx context.Context, ownerID int64) (string, string, err
6867
}
6968

7069
func generateKeypair() (string, string, error) {
71-
e, err := openpgp.NewEntity(setting.AppName, "RPM Registry", "", nil)
70+
e, err := openpgp.NewEntity("", "RPM Registry", "", nil)
7271
if err != nil {
7372
return "", "", err
7473
}
@@ -126,7 +125,7 @@ type packageData struct {
126125

127126
type packageCache = map[*packages_model.PackageFile]*packageData
128127

129-
// BuildSpecificRepositoryFiles builds metadata files for the repository
128+
// BuildRepositoryFiles builds metadata files for the repository
130129
func BuildRepositoryFiles(ctx context.Context, ownerID int64) error {
131130
pv, err := GetOrCreateRepositoryVersion(ctx, ownerID)
132131
if err != nil {

templates/repo/actions/list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="ui container">
55
{{template "base/alert" .}}
66

7-
{{if .workflows}}
7+
{{if .HasWorkflowsOrRuns}}
88
<div class="ui stackable grid">
99
<div class="four wide column">
1010
<div class="ui fluid vertical menu">

templates/repo/actions/runs_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="flex-list">
2-
{{if eq (len .Runs) 0}}
2+
{{if not .Runs}}
33
<div class="empty-placeholder">
44
{{svg "octicon-no-entry" 48}}
55
<h2>{{if $.IsFiltered}}{{ctx.Locale.Tr "actions.runs.no_results"}}{{else}}{{ctx.Locale.Tr "actions.runs.no_runs"}}{{end}}</h2>

templates/repo/commit_page.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
{{else}}
202202
<span title="{{ctx.Locale.Tr "gpg.default_key"}}">{{svg "gitea-lock-cog" 16 "gt-mr-3"}}</span>
203203
<span class="ui text gt-mr-3">{{ctx.Locale.Tr "repo.commits.signed_by"}}:</span>
204-
{{ctx.AvatarUtils.AvatarByEmail .Verification.SigningEmail "" 28}}
204+
{{ctx.AvatarUtils.AvatarByEmail .Verification.SigningEmail "" 28 "gt-mr-3"}}
205205
<strong>{{.Verification.SigningUser.GetDisplayName}}</strong>
206206
{{end}}
207207
{{else}}

templates/repo/diff/section_split.tmpl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,39 +108,39 @@
108108
</tr>
109109
{{if and (eq .GetType 3) $hasmatch}}
110110
{{$match := index $section.Lines $line.Match}}
111-
{{if or (gt (len $line.Comments) 0) (gt (len $match.Comments) 0)}}
111+
{{if or $line.Comments $match.Comments}}
112112
<tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
113113
<td class="add-comment-left" colspan="4">
114-
{{if gt (len $line.Comments) 0}}
114+
{{if $line.Comments}}
115115
{{if eq $line.GetCommentSide "previous"}}
116116
{{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}}
117117
{{end}}
118118
{{end}}
119-
{{if gt (len $match.Comments) 0}}
119+
{{if $match.Comments}}
120120
{{if eq $match.GetCommentSide "previous"}}
121121
{{template "repo/diff/conversation" dict "." $.root "comments" $match.Comments}}
122122
{{end}}
123123
{{end}}
124124
</td>
125125
<td class="add-comment-right" colspan="4">
126-
{{if eq $line.GetCommentSide "proposed"}}
127-
{{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}}
126+
{{if $line.Comments}}
127+
{{if eq $line.GetCommentSide "proposed"}}
128+
{{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}}
129+
{{end}}
128130
{{end}}
129-
{{if gt (len $match.Comments) 0}}
131+
{{if $match.Comments}}
130132
{{if eq $match.GetCommentSide "proposed"}}
131133
{{template "repo/diff/conversation" dict "." $.root "comments" $match.Comments}}
132134
{{end}}
133135
{{end}}
134136
</td>
135137
</tr>
136138
{{end}}
137-
{{else if gt (len $line.Comments) 0}}
139+
{{else if $line.Comments}}
138140
<tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
139141
<td class="add-comment-left" colspan="4">
140-
{{if gt (len $line.Comments) 0}}
141-
{{if eq $line.GetCommentSide "previous"}}
142-
{{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}}
143-
{{end}}
142+
{{if eq $line.GetCommentSide "previous"}}
143+
{{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}}
144144
{{end}}
145145
</td>
146146
<td class="add-comment-right" colspan="4">

templates/repo/diff/section_unified.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
*/}}</td>
6161
{{end}}
6262
</tr>
63-
{{if gt (len $line.Comments) 0}}
63+
{{if $line.Comments}}
6464
<tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
6565
<td class="add-comment-left add-comment-right" colspan="5">
6666
{{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}}

templates/repo/header.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@
8181
{{end}}
8282
{{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}
8383
<div class="ui labeled button
84-
{{if or (not $.IsSigned) (and (not $.CanSignedUserFork) (eq (len $.UserAndOrgForks) 0))}}
84+
{{if or (not $.IsSigned) (and (not $.CanSignedUserFork) (not $.UserAndOrgForks))}}
8585
disabled
8686
{{end}}"
8787
{{if not $.IsSigned}}
8888
data-tooltip-content="{{ctx.Locale.Tr "repo.fork_guest_user"}}"
89-
{{else if and (not $.CanSignedUserFork) (eq (len $.UserAndOrgForks) 0)}}
89+
{{else if and (not $.CanSignedUserFork) (not $.UserAndOrgForks)}}
9090
data-tooltip-content="{{ctx.Locale.Tr "repo.fork_from_self"}}"
9191
{{end}}
9292
>
@@ -98,7 +98,7 @@
9898
href="{{AppSubUrl}}/{{(index $.UserAndOrgForks 0).FullName}}"
9999
{{/*else is not required here, because the button shouldn't link to any site if you can't create a fork*/}}
100100
{{end}}
101-
{{else if eq (len $.UserAndOrgForks) 0}}
101+
{{else if not $.UserAndOrgForks}}
102102
href="{{AppSubUrl}}/repo/fork/{{.ID}}"
103103
{{else}}
104104
data-modal="#fork-repo-modal"

templates/repo/issue/filters.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div id="issue-filters" class="issue-list-toolbar">
22
<div class="issue-list-toolbar-left">
3-
{{if and ($.CanWriteIssuesOrPulls) (gt (len .Issues) 0)}}
3+
{{if and $.CanWriteIssuesOrPulls .Issues}}
44
<input type="checkbox" autocomplete="off" class="issue-checkbox-all gt-mr-4" title="{{ctx.Locale.Tr "repo.issues.action_check_all"}}">
55
{{end}}
66
{{template "repo/issue/openclose" .}}

templates/repo/issue/view_content/sidebar.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@
339339
</div>
340340
</div>
341341
{{end}}
342-
{{if gt (len .WorkingUsers) 0}}
342+
{{if .WorkingUsers}}
343343
<div class="divider"></div>
344344
<div class="ui comments">
345345
<span class="text"><strong>{{ctx.Locale.Tr "repo.issues.time_spent_from_all_authors" ($.Issue.TotalTrackedTime | Sec2Time) | Safe}}</strong></span>

templates/shared/issuelist.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
{{ctx.Locale.TrN $waitingOfficial "repo.pulls.waiting_count_1" "repo.pulls.waiting_count_n" $waitingOfficial}}
141141
</span>
142142
{{end}}
143-
{{if and (not .PullRequest.HasMerged) (gt (len .PullRequest.ConflictedFiles) 0)}}
143+
{{if and (not .PullRequest.HasMerged) .PullRequest.ConflictedFiles}}
144144
<span class="conflicting flex-text-inline">
145145
{{svg "octicon-x" 14}}
146146
{{ctx.Locale.TrN (len .PullRequest.ConflictedFiles) "repo.pulls.num_conflicting_files_1" "repo.pulls.num_conflicting_files_n" (len .PullRequest.ConflictedFiles)}}

templates/user/dashboard/feeds.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
{{else if .GetOpType.InActions "comment_issue" "approve_pull_request" "reject_pull_request" "comment_pull"}}
106106
<a href="{{.GetCommentLink ctx}}" class="text truncate issue title">{{(.GetIssueTitle ctx) | RenderEmoji $.Context | RenderCodeBlock}}</a>
107107
{{$comment := index .GetIssueInfos 1}}
108-
{{if gt (len $comment) 0}}
108+
{{if $comment}}
109109
<div class="markup gt-font-14">{{RenderMarkdownToHtml ctx $comment}}</div>
110110
{{end}}
111111
{{else if .GetOpType.InActions "merge_pull_request"}}

templates/user/notification/notification_div.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</div>
2525
<div class="gt-p-0">
2626
<div id="notification_table">
27-
{{if eq (len .Notifications) 0}}
27+
{{if not .Notifications}}
2828
<div class="gt-df gt-ac gt-fc gt-p-4">
2929
{{svg "octicon-inbox" 56 "gt-mb-4"}}
3030
{{if eq .Status 1}}

templates/user/notification/notification_subscriptions.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
</div>
6464
</div>
6565
<div class="divider"></div>
66-
{{if eq (len .Issues) 0}}
66+
{{if not .Issues}}
6767
{{ctx.Locale.Tr "notification.no_subscriptions"}}
6868
{{else}}
6969
{{template "shared/issuelist" dict "." . "listType" "dashboard"}}

templates/user/settings/keys_gpg.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
{{if .Verified}}
5656
<span class="flex-text-block" data-tooltip-content="{{ctx.Locale.Tr "settings.gpg_key_verified_long"}}">{{svg "octicon-verified"}} <strong>{{ctx.Locale.Tr "settings.gpg_key_verified"}}</strong></span>
5757
{{end}}
58-
{{if gt (len .Emails) 0}}
58+
{{if .Emails}}
5959
<span class="flex-text-block" data-tooltip-content="{{ctx.Locale.Tr "settings.gpg_key_matched_identities_long"}}">{{svg "octicon-mail"}} {{ctx.Locale.Tr "settings.gpg_key_matched_identities"}} {{range .Emails}}<strong>{{.Email}} </strong>{{end}}</span>
6060
{{end}}
6161
<div class="flex-item-body">

tests/integration/api_packages_rpm_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,18 @@ gpgkey=%sapi/packages/%s/rpm/repository.key`, user.Name, user.Name, setting.AppN
149149

150150
url := rootURL + "/repodata"
151151

152-
req := NewRequest(t, "GET", url+"/dummy.xml")
152+
req := NewRequest(t, "HEAD", url+"/dummy.xml")
153+
MakeRequest(t, req, http.StatusNotFound)
154+
155+
req = NewRequest(t, "GET", url+"/dummy.xml")
153156
MakeRequest(t, req, http.StatusNotFound)
154157

155158
t.Run("repomd.xml", func(t *testing.T) {
156159
defer tests.PrintCurrentTest(t)()
157160

161+
req = NewRequest(t, "HEAD", url+"/repomd.xml")
162+
MakeRequest(t, req, http.StatusOK)
163+
158164
req = NewRequest(t, "GET", url+"/repomd.xml")
159165
resp := MakeRequest(t, req, http.StatusOK)
160166

0 commit comments

Comments
 (0)