Skip to content

Commit bc6f257

Browse files
authored
Merge branch 'main' into lunny/remove_repo_ref_in_commit
2 parents 2f1a01d + c5332fd commit bc6f257

33 files changed

+385
-234
lines changed

.github/workflows/pull-db-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ jobs:
7272
go-version-file: go.mod
7373
check-latest: true
7474
- run: make deps-backend
75-
- run: make backend
75+
- run: GOEXPERIMENT='' make backend
7676
env:
7777
TAGS: bindata gogit sqlite sqlite_unlock_notify
7878
- name: run migration tests
7979
run: make test-sqlite-migration
8080
- name: run tests
81-
run: make test-sqlite
81+
run: GOEXPERIMENT='' make test-sqlite
8282
timeout-minutes: 50
8383
env:
8484
TAGS: bindata gogit sqlite sqlite_unlock_notify
@@ -142,7 +142,7 @@ jobs:
142142
RACE_ENABLED: true
143143
GITHUB_READ_TOKEN: ${{ secrets.GITHUB_READ_TOKEN }}
144144
- name: unit-tests-gogit
145-
run: make unit-test-coverage test-check
145+
run: GOEXPERIMENT='' make unit-test-coverage test-check
146146
env:
147147
TAGS: bindata gogit
148148
RACE_ENABLED: true

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ DIST := dist
1818
DIST_DIRS := $(DIST)/binaries $(DIST)/release
1919
IMPORT := code.gitea.io/gitea
2020

21+
# By default use go's 1.25 experimental json v2 library when building
22+
# TODO: remove when no longer experimental
23+
export GOEXPERIMENT ?= jsonv2
24+
2125
GO ?= go
2226
SHASUM ?= shasum -a 256
2327
HAS_GO := $(shell hash $(GO) > /dev/null 2>&1 && echo yes)
@@ -766,7 +770,7 @@ generate-go: $(TAGS_PREREQ)
766770

767771
.PHONY: security-check
768772
security-check:
769-
go run $(GOVULNCHECK_PACKAGE) -show color ./...
773+
GOEXPERIMENT= go run $(GOVULNCHECK_PACKAGE) -show color ./...
770774

771775
$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
772776
ifneq ($(and $(STATIC),$(findstring pam,$(TAGS))),)

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed
1717
gitea.com/go-chi/cache v0.2.1
1818
gitea.com/go-chi/captcha v0.0.0-20240315150714-fb487f629098
19-
gitea.com/go-chi/session v0.0.0-20240316035857-16768d98ec96
19+
gitea.com/go-chi/session v0.0.0-20250926004215-636cadd82e15
2020
gitea.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96
2121
gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4
2222
github.com/42wim/httpsig v1.2.3
@@ -61,6 +61,7 @@ require (
6161
github.com/go-redsync/redsync/v4 v4.13.0
6262
github.com/go-sql-driver/mysql v1.9.3
6363
github.com/go-webauthn/webauthn v0.13.4
64+
github.com/goccy/go-json v0.10.5
6465
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f
6566
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
6667
github.com/golang-jwt/jwt/v5 v5.3.0
@@ -75,7 +76,6 @@ require (
7576
github.com/huandu/xstrings v1.5.0
7677
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056
7778
github.com/jhillyerd/enmime v1.3.0
78-
github.com/json-iterator/go v1.1.12
7979
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
8080
github.com/klauspost/compress v1.18.0
8181
github.com/klauspost/cpuid/v2 v2.3.0
@@ -200,7 +200,6 @@ require (
200200
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
201201
github.com/go-ini/ini v1.67.0 // indirect
202202
github.com/go-webauthn/x v0.1.24 // indirect
203-
github.com/goccy/go-json v0.10.5 // indirect
204203
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
205204
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
206205
github.com/golang-sql/sqlexp v0.1.0 // indirect
@@ -220,6 +219,7 @@ require (
220219
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
221220
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
222221
github.com/josharian/intern v1.0.0 // indirect
222+
github.com/json-iterator/go v1.1.12 // indirect
223223
github.com/kevinburke/ssh_config v1.4.0 // indirect
224224
github.com/klauspost/pgzip v1.2.6 // indirect
225225
github.com/libdns/libdns v1.1.1 // indirect
@@ -277,7 +277,7 @@ require (
277277
go.uber.org/zap v1.27.0 // indirect
278278
go.uber.org/zap/exp v0.3.0 // indirect
279279
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
280-
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
280+
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b // indirect
281281
golang.org/x/mod v0.27.0 // indirect
282282
golang.org/x/time v0.12.0 // indirect
283283
golang.org/x/tools v0.36.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ gitea.com/go-chi/cache v0.2.1 h1:bfAPkvXlbcZxPCpcmDVCWoHgiBSBmZN/QosnZvEC0+g=
4343
gitea.com/go-chi/cache v0.2.1/go.mod h1:Qic0HZ8hOHW62ETGbonpwz8WYypj9NieU9659wFUJ8Q=
4444
gitea.com/go-chi/captcha v0.0.0-20240315150714-fb487f629098 h1:p2ki+WK0cIeNQuqjR98IP2KZQKRzJJiV7aTeMAFwaWo=
4545
gitea.com/go-chi/captcha v0.0.0-20240315150714-fb487f629098/go.mod h1:LjzIOHlRemuUyO7WR12fmm18VZIlCAaOt9L3yKw40pk=
46-
gitea.com/go-chi/session v0.0.0-20240316035857-16768d98ec96 h1:IFDiMBObsP6CZIRaDLd54SR6zPYAffPXiXck5Xslu0Q=
47-
gitea.com/go-chi/session v0.0.0-20240316035857-16768d98ec96/go.mod h1:0iEpFKnwO5dG0aF98O4eq6FMsAiXkNBaDIlUOlq4BtM=
46+
gitea.com/go-chi/session v0.0.0-20250926004215-636cadd82e15 h1:qFYmz05u/s9664o7+XEgrlHXSPQ4uHO8/ccZGUb1uxA=
47+
gitea.com/go-chi/session v0.0.0-20250926004215-636cadd82e15/go.mod h1:0iEpFKnwO5dG0aF98O4eq6FMsAiXkNBaDIlUOlq4BtM=
4848
gitea.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96 h1:+wWBi6Qfruqu7xJgjOIrKVQGiLUZdpKYCZewJ4clqhw=
4949
gitea.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96/go.mod h1:VyMQP6ue6MKHM8UsOXfNfuMKD0oSAWZdXVcpHIN2yaY=
5050
gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4 h1:IFT+hup2xejHqdhS7keYWioqfmxdnfblFDTGoOwcZ+o=
@@ -848,8 +848,8 @@ golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE
848848
golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
849849
golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
850850
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
851-
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw=
852-
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM=
851+
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b h1:DXr+pvt3nC887026GRP39Ej11UATqWDmWuS99x26cD0=
852+
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b/go.mod h1:4QTo5u+SEIbbKW1RacMZq1YEfOBqeXa19JeshGi+zc4=
853853
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
854854
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
855855
golang.org/x/image v0.30.0 h1:jD5RhkmVAnjqaCUXfbGBrn3lpxbknfN9w2UhHHU+5B4=

modules/assetfs/embed.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,11 @@ func GenerateEmbedBindata(fsRootPath, outputFile string) error {
365365
if err = embedFiles(meta.Root, fsRootPath, ""); err != nil {
366366
return err
367367
}
368-
jsonBuf, err := json.Marshal(meta) // can't use json.NewEncoder here because it writes extra EOL
368+
jsonBuf, err := json.Marshal(meta)
369369
if err != nil {
370370
return err
371371
}
372372
_, _ = output.Write([]byte{'\n'})
373-
_, err = output.Write(jsonBuf)
373+
_, err = output.Write(bytes.TrimSpace(jsonBuf))
374374
return err
375375
}

modules/json/json.go

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"encoding/binary"
99
"encoding/json" //nolint:depguard // this package wraps it
1010
"io"
11-
12-
jsoniter "github.com/json-iterator/go"
1311
)
1412

1513
// Encoder represents an encoder for json
@@ -31,71 +29,7 @@ type Interface interface {
3129
Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error
3230
}
3331

34-
var (
35-
// DefaultJSONHandler default json handler
36-
DefaultJSONHandler Interface = JSONiter{jsoniter.ConfigCompatibleWithStandardLibrary}
37-
38-
_ Interface = StdJSON{}
39-
_ Interface = JSONiter{}
40-
)
41-
42-
// StdJSON implements Interface via encoding/json
43-
type StdJSON struct{}
44-
45-
// Marshal implements Interface
46-
func (StdJSON) Marshal(v any) ([]byte, error) {
47-
return json.Marshal(v)
48-
}
49-
50-
// Unmarshal implements Interface
51-
func (StdJSON) Unmarshal(data []byte, v any) error {
52-
return json.Unmarshal(data, v)
53-
}
54-
55-
// NewEncoder implements Interface
56-
func (StdJSON) NewEncoder(writer io.Writer) Encoder {
57-
return json.NewEncoder(writer)
58-
}
59-
60-
// NewDecoder implements Interface
61-
func (StdJSON) NewDecoder(reader io.Reader) Decoder {
62-
return json.NewDecoder(reader)
63-
}
64-
65-
// Indent implements Interface
66-
func (StdJSON) Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
67-
return json.Indent(dst, src, prefix, indent)
68-
}
69-
70-
// JSONiter implements Interface via jsoniter
71-
type JSONiter struct {
72-
jsoniter.API
73-
}
74-
75-
// Marshal implements Interface
76-
func (j JSONiter) Marshal(v any) ([]byte, error) {
77-
return j.API.Marshal(v)
78-
}
79-
80-
// Unmarshal implements Interface
81-
func (j JSONiter) Unmarshal(data []byte, v any) error {
82-
return j.API.Unmarshal(data, v)
83-
}
84-
85-
// NewEncoder implements Interface
86-
func (j JSONiter) NewEncoder(writer io.Writer) Encoder {
87-
return j.API.NewEncoder(writer)
88-
}
89-
90-
// NewDecoder implements Interface
91-
func (j JSONiter) NewDecoder(reader io.Reader) Decoder {
92-
return j.API.NewDecoder(reader)
93-
}
94-
95-
// Indent implements Interface, since jsoniter don't support Indent, just use encoding/json's
96-
func (j JSONiter) Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
97-
return json.Indent(dst, src, prefix, indent)
98-
}
32+
var DefaultJSONHandler = getDefaultJSONHandler()
9933

10034
// Marshal converts object as bytes
10135
func Marshal(v any) ([]byte, error) {

modules/json/json_test.go

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

66
import (
7+
"bytes"
78
"testing"
89

910
"github.com/stretchr/testify/assert"
@@ -16,3 +17,12 @@ func TestGiteaDBJSONUnmarshal(t *testing.T) {
1617
err = UnmarshalHandleDoubleEncode([]byte(""), &m)
1718
assert.NoError(t, err)
1819
}
20+
21+
func TestIndent(t *testing.T) {
22+
buf := &bytes.Buffer{}
23+
err := Indent(buf, []byte(`{"a":1}`), ">", " ")
24+
assert.NoError(t, err)
25+
assert.Equal(t, `{
26+
> "a": 1
27+
>}`, buf.String())
28+
}

modules/json/jsongoccy.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package json
5+
6+
import (
7+
"bytes"
8+
"io"
9+
10+
"github.com/goccy/go-json"
11+
)
12+
13+
var _ Interface = jsonGoccy{}
14+
15+
type jsonGoccy struct{}
16+
17+
func (jsonGoccy) Marshal(v any) ([]byte, error) {
18+
return json.Marshal(v)
19+
}
20+
21+
func (jsonGoccy) Unmarshal(data []byte, v any) error {
22+
return json.Unmarshal(data, v)
23+
}
24+
25+
func (jsonGoccy) NewEncoder(writer io.Writer) Encoder {
26+
return json.NewEncoder(writer)
27+
}
28+
29+
func (jsonGoccy) NewDecoder(reader io.Reader) Decoder {
30+
return json.NewDecoder(reader)
31+
}
32+
33+
func (jsonGoccy) Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
34+
return json.Indent(dst, src, prefix, indent)
35+
}

modules/json/jsonlegacy.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
//go:build !goexperiment.jsonv2
5+
6+
package json
7+
8+
import (
9+
"io"
10+
)
11+
12+
func getDefaultJSONHandler() Interface {
13+
return jsonGoccy{}
14+
}
15+
16+
func MarshalKeepOptionalEmpty(v any) ([]byte, error) {
17+
return DefaultJSONHandler.Marshal(v)
18+
}
19+
20+
func NewDecoderCaseInsensitive(reader io.Reader) Decoder {
21+
return DefaultJSONHandler.NewDecoder(reader)
22+
}

modules/json/jsonv1.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package json
5+
6+
import (
7+
"bytes"
8+
"encoding/json" //nolint:depguard // this package wraps it
9+
"io"
10+
)
11+
12+
type jsonV1 struct{}
13+
14+
var _ Interface = jsonV1{}
15+
16+
func (jsonV1) Marshal(v any) ([]byte, error) {
17+
return json.Marshal(v)
18+
}
19+
20+
func (jsonV1) Unmarshal(data []byte, v any) error {
21+
return json.Unmarshal(data, v)
22+
}
23+
24+
func (jsonV1) NewEncoder(writer io.Writer) Encoder {
25+
return json.NewEncoder(writer)
26+
}
27+
28+
func (jsonV1) NewDecoder(reader io.Reader) Decoder {
29+
return json.NewDecoder(reader)
30+
}
31+
32+
func (jsonV1) Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
33+
return json.Indent(dst, src, prefix, indent)
34+
}

0 commit comments

Comments
 (0)