Skip to content

Commit 9336e09

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix diff blob excerpt expansion (go-gitea#35922) Add GITEA_PR_INDEX env variable to githooks (go-gitea#35938) Fix container push tag overwriting (go-gitea#35936) Upgrade deps golang.org/x/crypto (go-gitea#35952) Fix corrupted external render content (go-gitea#35946) Don't show unnecessary error message to end users for DeleteBranchAfterMerge (go-gitea#35937) Limit reading bytes instead of ReadAll (go-gitea#35928)
2 parents 7597b53 + 0fb3be7 commit 9336e09

File tree

39 files changed

+357
-194
lines changed

39 files changed

+357
-194
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/actions/workflows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ package actions
55

66
import (
77
"bytes"
8-
"io"
98
"slices"
109
"strings"
1110

1211
"code.gitea.io/gitea/modules/git"
1312
"code.gitea.io/gitea/modules/glob"
1413
"code.gitea.io/gitea/modules/log"
1514
api "code.gitea.io/gitea/modules/structs"
15+
"code.gitea.io/gitea/modules/util"
1616
webhook_module "code.gitea.io/gitea/modules/webhook"
1717

1818
"github.com/nektos/act/pkg/jobparser"
@@ -77,7 +77,7 @@ func GetContentFromEntry(entry *git.TreeEntry) ([]byte, error) {
7777
if err != nil {
7878
return nil, err
7979
}
80-
content, err := io.ReadAll(f)
80+
content, err := util.ReadWithLimit(f, 1024*1024)
8181
_ = f.Close()
8282
if err != nil {
8383
return nil, err

modules/issue/template/unmarshal.go

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

66
import (
77
"fmt"
8-
"io"
98
"path"
109
"strconv"
1110

@@ -76,7 +75,7 @@ func unmarshalFromEntry(entry *git.TreeEntry, filename string) (*api.IssueTempla
7675
}
7776
defer r.Close()
7877

79-
content, err := io.ReadAll(r)
78+
content, err := util.ReadWithLimit(r, 1024*1024)
8079
if err != nil {
8180
return nil, fmt.Errorf("read all: %w", err)
8281
}

modules/packages/nuget/metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func ParseNuspecMetaData(archive *zip.Reader, r io.Reader) (*Package, error) {
216216
if p.Metadata.Readme != "" {
217217
f, err := archive.Open(p.Metadata.Readme)
218218
if err == nil {
219-
buf, _ := io.ReadAll(f)
219+
buf, _ := util.ReadWithLimit(f, 1024*1024)
220220
m.Readme = string(buf)
221221
_ = f.Close()
222222
}

modules/packages/pub/metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func ParsePackage(r io.Reader) (*Package, error) {
8989
return nil, err
9090
}
9191
} else if strings.EqualFold(hd.Name, "readme.md") {
92-
data, err := io.ReadAll(tr)
92+
data, err := util.ReadWithLimit(tr, 1024*1024)
9393
if err != nil {
9494
return nil, err
9595
}

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
)

modules/util/io.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func ReadAtMost(r io.Reader, buf []byte) (n int, err error) {
2929
// ReadWithLimit reads at most "limit" bytes from r into buf.
3030
// If EOF or ErrUnexpectedEOF occurs while reading, err will be nil.
3131
func ReadWithLimit(r io.Reader, n int) (buf []byte, err error) {
32-
return readWithLimit(r, 1024, n)
32+
return readWithLimit(r, 4*1024, n)
3333
}
3434

3535
func readWithLimit(r io.Reader, batch, limit int) ([]byte, error) {

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

0 commit comments

Comments
 (0)