Skip to content

Commit 428797e

Browse files
authored
Merge branch 'main' into patch-header-navbar
2 parents 70def83 + 0fb3be7 commit 428797e

File tree

28 files changed

+288
-163
lines changed

28 files changed

+288
-163
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ require (
117117
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
118118
github.com/yuin/goldmark-meta v1.1.0
119119
gitlab.com/gitlab-org/api/client-go v0.142.4
120-
golang.org/x/crypto v0.42.0
120+
golang.org/x/crypto v0.43.0
121121
golang.org/x/image v0.30.0
122-
golang.org/x/net v0.44.0
122+
golang.org/x/net v0.45.0
123123
golang.org/x/oauth2 v0.30.0
124124
golang.org/x/sync v0.17.0
125125
golang.org/x/sys v0.37.0

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,8 @@ golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDf
840840
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
841841
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
842842
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
843-
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
844-
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
843+
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
844+
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
845845
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
846846
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
847847
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -908,8 +908,8 @@ golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
908908
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
909909
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
910910
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
911-
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
912-
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
911+
golang.org/x/net v0.45.0 h1:RLBg5JKixCy82FtLJpeNlVM0nrSqpCRYzVU1n8kj0tM=
912+
golang.org/x/net v0.45.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
913913
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
914914
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
915915
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -987,8 +987,8 @@ golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
987987
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
988988
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
989989
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
990-
golang.org/x/term v0.35.0 h1:bZBVKBudEyhRcajGcNc3jIfWPqV4y/Kt2XcoigOWtDQ=
991-
golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA=
990+
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
991+
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
992992
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
993993
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
994994
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

modules/repository/env.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
EnvKeyID = "GITEA_KEY_ID" // public key ID
2626
EnvDeployKeyID = "GITEA_DEPLOY_KEY_ID"
2727
EnvPRID = "GITEA_PR_ID"
28+
EnvPRIndex = "GITEA_PR_INDEX" // not used by Gitea at the moment, it is for custom git hooks
2829
EnvPushTrigger = "GITEA_PUSH_TRIGGER"
2930
EnvIsInternal = "GITEA_INTERNAL_PUSH"
3031
EnvAppURL = "GITEA_ROOT_URL"
@@ -50,11 +51,11 @@ func InternalPushingEnvironment(doer *user_model.User, repo *repo_model.Reposito
5051

5152
// PushingEnvironment returns an os environment to allow hooks to work on push
5253
func PushingEnvironment(doer *user_model.User, repo *repo_model.Repository) []string {
53-
return FullPushingEnvironment(doer, doer, repo, repo.Name, 0)
54+
return FullPushingEnvironment(doer, doer, repo, repo.Name, 0, 0)
5455
}
5556

5657
// FullPushingEnvironment returns an os environment to allow hooks to work on push
57-
func FullPushingEnvironment(author, committer *user_model.User, repo *repo_model.Repository, repoName string, prID int64) []string {
58+
func FullPushingEnvironment(author, committer *user_model.User, repo *repo_model.Repository, repoName string, prID, prIndex int64) []string {
5859
isWiki := "false"
5960
if strings.HasSuffix(repoName, ".wiki") {
6061
isWiki = "true"
@@ -75,6 +76,7 @@ func FullPushingEnvironment(author, committer *user_model.User, repo *repo_model
7576
EnvPusherID+"="+strconv.FormatInt(committer.ID, 10),
7677
EnvRepoID+"="+strconv.FormatInt(repo.ID, 10),
7778
EnvPRID+"="+strconv.FormatInt(prID, 10),
79+
EnvPRIndex+"="+strconv.FormatInt(prIndex, 10),
7880
EnvAppURL+"="+setting.AppURL,
7981
"SSH_ORIGINAL_COMMAND=gitea-internal",
8082
)

routers/api/packages/container/manifest.go

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"io"
1111
"os"
1212
"strings"
13-
"time"
1413

1514
"code.gitea.io/gitea/models/db"
1615
packages_model "code.gitea.io/gitea/models/packages"
@@ -260,6 +259,13 @@ func createPackageAndVersion(ctx context.Context, mci *manifestCreationInfo, met
260259
return nil, err
261260
}
262261

262+
// "docker buildx imagetools create" multi-arch operations:
263+
// {"type":"oci","is_tagged":false,"platform":"unknown/unknown"}
264+
// {"type":"oci","is_tagged":false,"platform":"linux/amd64","layer_creation":["ADD file:9233f6f2237d79659a9521f7e390df217cec49f1a8aa3a12147bbca1956acdb9 in /","CMD [\"/bin/sh\"]"]}
265+
// {"type":"oci","is_tagged":false,"platform":"unknown/unknown"}
266+
// {"type":"oci","is_tagged":false,"platform":"linux/arm64","layer_creation":["ADD file:df53811312284306901fdaaff0a357a4bf40d631e662fe9ce6d342442e494b6c in /","CMD [\"/bin/sh\"]"]}
267+
// {"type":"oci","is_tagged":true,"manifests":[{"platform":"linux/amd64","digest":"sha256:72bb73e706c0dec424d00a1febb21deaf1175a70ead009ad8b159729cfcf5769","size":2819478},{"platform":"linux/arm64","digest":"sha256:9e1426dd084a3221663b85ca1ee99d140c50b153917a5c5604c1f9b78229fd24","size":2716499},{"platform":"unknown/unknown","digest":"sha256:b93f03d0ae11b988243e1b2cd8d29accf5b9670547b7bd8c7d96abecc7283e6e","size":1798},{"platform":"unknown/unknown","digest":"sha256:f034b182ba66366c63a5d195c6dfcd3333c027409c0ac98e55ade36aaa3b2963","size":1798}]}
268+
263269
_pv := &packages_model.PackageVersion{
264270
PackageID: p.ID,
265271
CreatorID: mci.Creator.ID,
@@ -273,25 +279,16 @@ func createPackageAndVersion(ctx context.Context, mci *manifestCreationInfo, met
273279
log.Error("Error inserting package: %v", err)
274280
return nil, err
275281
}
276-
277-
if container_module.IsMediaTypeImageIndex(mci.MediaType) {
278-
if pv.CreatedUnix.AsTime().Before(time.Now().Add(-24 * time.Hour)) {
279-
if err = packages_service.DeletePackageVersionAndReferences(ctx, pv); err != nil {
280-
return nil, err
281-
}
282-
// keep download count on overwriting
283-
_pv.DownloadCount = pv.DownloadCount
284-
if pv, err = packages_model.GetOrInsertVersion(ctx, _pv); err != nil {
285-
if !errors.Is(err, packages_model.ErrDuplicatePackageVersion) {
286-
log.Error("Error inserting package: %v", err)
287-
return nil, err
288-
}
289-
}
290-
} else {
291-
err = packages_model.UpdateVersion(ctx, &packages_model.PackageVersion{ID: pv.ID, MetadataJSON: _pv.MetadataJSON})
292-
if err != nil {
293-
return nil, err
294-
}
282+
if err = packages_service.DeletePackageVersionAndReferences(ctx, pv); err != nil {
283+
return nil, err
284+
}
285+
// keep download count on overwriting
286+
_pv.DownloadCount = pv.DownloadCount
287+
pv, err = packages_model.GetOrInsertVersion(ctx, _pv)
288+
if err != nil {
289+
if !errors.Is(err, packages_model.ErrDuplicatePackageVersion) {
290+
log.Error("Error inserting package: %v", err)
291+
return nil, err
295292
}
296293
}
297294
}

routers/web/repo/compare.go

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"encoding/csv"
1010
"errors"
1111
"fmt"
12-
"html"
1312
"io"
1413
"net/http"
1514
"net/url"
@@ -957,30 +956,26 @@ func ExcerptBlob(ctx *context.Context) {
957956
ctx.HTTPError(http.StatusInternalServerError, "getExcerptLines")
958957
return
959958
}
960-
if idxRight > lastRight {
961-
lineText := " "
962-
if rightHunkSize > 0 || leftHunkSize > 0 {
963-
lineText = fmt.Sprintf("@@ -%d,%d +%d,%d @@\n", idxLeft, leftHunkSize, idxRight, rightHunkSize)
964-
}
965-
lineText = html.EscapeString(lineText)
966-
lineSection := &gitdiff.DiffLine{
967-
Type: gitdiff.DiffLineSection,
968-
Content: lineText,
969-
SectionInfo: &gitdiff.DiffLineSectionInfo{
970-
Path: filePath,
971-
LastLeftIdx: lastLeft,
972-
LastRightIdx: lastRight,
973-
LeftIdx: idxLeft,
974-
RightIdx: idxRight,
975-
LeftHunkSize: leftHunkSize,
976-
RightHunkSize: rightHunkSize,
977-
},
978-
}
959+
960+
newLineSection := &gitdiff.DiffLine{
961+
Type: gitdiff.DiffLineSection,
962+
SectionInfo: &gitdiff.DiffLineSectionInfo{
963+
Path: filePath,
964+
LastLeftIdx: lastLeft,
965+
LastRightIdx: lastRight,
966+
LeftIdx: idxLeft,
967+
RightIdx: idxRight,
968+
LeftHunkSize: leftHunkSize,
969+
RightHunkSize: rightHunkSize,
970+
},
971+
}
972+
if newLineSection.GetExpandDirection() != "" {
973+
newLineSection.Content = fmt.Sprintf("@@ -%d,%d +%d,%d @@\n", idxLeft, leftHunkSize, idxRight, rightHunkSize)
979974
switch direction {
980975
case "up":
981-
section.Lines = append([]*gitdiff.DiffLine{lineSection}, section.Lines...)
976+
section.Lines = append([]*gitdiff.DiffLine{newLineSection}, section.Lines...)
982977
case "down":
983-
section.Lines = append(section.Lines, lineSection)
978+
section.Lines = append(section.Lines, newLineSection)
984979
}
985980
}
986981

routers/web/repo/view_file.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ func handleFileViewRenderMarkup(ctx *context.Context, filename string, sniffedTy
9292
ctx.ServerError("Render", err)
9393
return true
9494
}
95-
// to prevent iframe from loading third-party url
96-
ctx.Resp.Header().Add("Content-Security-Policy", "frame-src 'self'")
9795
return true
9896
}
9997

@@ -241,14 +239,17 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) {
241239
// * IsRenderableXxx: some files are rendered by backend "markup" engine, some are rendered by frontend (pdf, 3d)
242240
// * DefaultViewMode: when there is no "display" query parameter, which view mode should be used by default, source or rendered
243241

244-
utf8Reader := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc), charset.ConvertOpts{})
242+
contentReader := io.MultiReader(bytes.NewReader(buf), dataRc)
243+
if fInfo.st.IsRepresentableAsText() {
244+
contentReader = charset.ToUTF8WithFallbackReader(contentReader, charset.ConvertOpts{})
245+
}
245246
switch {
246247
case fInfo.blobOrLfsSize >= setting.UI.MaxDisplayFileSize:
247248
ctx.Data["IsFileTooLarge"] = true
248-
case handleFileViewRenderMarkup(ctx, entry.Name(), fInfo.st, buf, utf8Reader):
249+
case handleFileViewRenderMarkup(ctx, entry.Name(), fInfo.st, buf, contentReader):
249250
// it also sets ctx.Data["FileContent"] and more
250251
ctx.Data["IsMarkup"] = true
251-
case handleFileViewRenderSource(ctx, entry.Name(), attrs, fInfo, utf8Reader):
252+
case handleFileViewRenderSource(ctx, entry.Name(), attrs, fInfo, contentReader):
252253
// it also sets ctx.Data["FileContent"] and more
253254
ctx.Data["IsDisplayingSource"] = true
254255
case handleFileViewRenderImage(ctx, fInfo, buf):

services/gitdiff/gitdiff.go

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,34 @@ type DiffLine struct {
8282

8383
// DiffLineSectionInfo represents diff line section meta data
8484
type DiffLineSectionInfo struct {
85-
Path string
86-
LastLeftIdx int
87-
LastRightIdx int
88-
LeftIdx int
89-
RightIdx int
85+
Path string
86+
87+
// These line "idx" are 1-based line numbers
88+
// Left/Right refer to the left/right side of the diff:
89+
//
90+
// LastLeftIdx | LastRightIdx
91+
// [up/down expander] @@ hunk info @@
92+
// LeftIdx | RightIdx
93+
94+
LastLeftIdx int
95+
LastRightIdx int
96+
LeftIdx int
97+
RightIdx int
98+
99+
// Hunk sizes of the hidden lines
90100
LeftHunkSize int
91101
RightHunkSize int
92102

103+
// For example:
104+
// 17 | 31
105+
// [up/down] @@ -40,23 +54,9 @@ ....
106+
// 40 | 54
107+
//
108+
// In this case:
109+
// LastLeftIdx = 17, LastRightIdx = 31
110+
// LeftHunkSize = 23, RightHunkSize = 9
111+
// LeftIdx = 40, RightIdx = 54
112+
93113
HiddenCommentIDs []int64 // IDs of hidden comments in this section
94114
}
95115

@@ -158,13 +178,13 @@ func (d *DiffLine) getBlobExcerptQuery() string {
158178
return query
159179
}
160180

161-
func (d *DiffLine) getExpandDirection() string {
181+
func (d *DiffLine) GetExpandDirection() string {
162182
if d.Type != DiffLineSection || d.SectionInfo == nil || d.SectionInfo.LeftIdx-d.SectionInfo.LastLeftIdx <= 1 || d.SectionInfo.RightIdx-d.SectionInfo.LastRightIdx <= 1 {
163183
return ""
164184
}
165185
if d.SectionInfo.LastLeftIdx <= 0 && d.SectionInfo.LastRightIdx <= 0 {
166186
return "up"
167-
} else if d.SectionInfo.RightIdx-d.SectionInfo.LastRightIdx > BlobExcerptChunkSize && d.SectionInfo.RightHunkSize > 0 {
187+
} else if d.SectionInfo.RightIdx-d.SectionInfo.LastRightIdx-1 > BlobExcerptChunkSize && d.SectionInfo.RightHunkSize > 0 {
168188
return "updown"
169189
} else if d.SectionInfo.LeftHunkSize <= 0 && d.SectionInfo.RightHunkSize <= 0 {
170190
return "down"
@@ -202,13 +222,13 @@ func (d *DiffLine) RenderBlobExcerptButtons(fileNameHash string, data *DiffBlobE
202222
content += htmlutil.HTMLFormat(`<span class="code-comment-more" data-tooltip-content="%s">%d</span>`, tooltip, len(d.SectionInfo.HiddenCommentIDs))
203223
}
204224

205-
expandDirection := d.getExpandDirection()
206-
if expandDirection == "up" || expandDirection == "updown" {
207-
content += makeButton("up", "octicon-fold-up")
208-
}
225+
expandDirection := d.GetExpandDirection()
209226
if expandDirection == "updown" || expandDirection == "down" {
210227
content += makeButton("down", "octicon-fold-down")
211228
}
229+
if expandDirection == "up" || expandDirection == "updown" {
230+
content += makeButton("up", "octicon-fold-up")
231+
}
212232
if expandDirection == "single" {
213233
content += makeButton("single", "octicon-fold")
214234
}

0 commit comments

Comments
 (0)