Skip to content

Commit 6e43bc5

Browse files
Merge pull request #61 from go-gitea/main
Fork updates from go-gitea/gitea main
2 parents a8eee0b + 9e94346 commit 6e43bc5

Some content is hidden

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

76 files changed

+2110
-1975
lines changed

assets/emoji.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/generate-emoji.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
const (
2727
gemojiURL = "https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json"
28-
maxUnicodeVersion = 12
28+
maxUnicodeVersion = 14
2929
)
3030

3131
var flagOut = flag.String("o", "modules/emoji/emoji_data.go", "out")
@@ -189,6 +189,10 @@ func generate() ([]byte, error) {
189189
}
190190
}
191191

192+
sort.Slice(data, func(i, j int) bool {
193+
return data[i].Aliases[0] < data[j].Aliases[0]
194+
})
195+
192196
// add header
193197
str := replacer.Replace(fmt.Sprintf(hdr, gemojiURL, data))
194198

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,9 @@ and
782782

783783
- `GRAVATAR_SOURCE`: **gravatar**: Can be `gravatar`, `duoshuo` or anything like
784784
`http://cn.gravatar.com/avatar/`.
785-
- `DISABLE_GRAVATAR`: **false**: Enable this to use local avatars only.
785+
- `DISABLE_GRAVATAR`: **false**: Enable this to use local avatars only. **DEPRECATED [v1.18+]** moved to database. Use admin panel to configure.
786786
- `ENABLE_FEDERATED_AVATAR`: **false**: Enable support for federated avatars (see
787-
[http://www.libravatar.org](http://www.libravatar.org)).
787+
[http://www.libravatar.org](http://www.libravatar.org)). **DEPRECATED [v1.18+]** moved to database. Use admin panel to configure.
788788

789789
- `AVATAR_STORAGE_TYPE`: **default**: Storage type defined in `[storage.xxx]`. Default is `default` which will read `[storage]` if no section `[storage]` will be a type `local`.
790790
- `AVATAR_UPLOAD_PATH`: **data/avatars**: Path to store user avatar image files.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,12 @@ replace github.com/hashicorp/go-version => github.com/6543/go-version v1.3.1
303303

304304
replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0
305305

306-
replace github.com/satori/go.uuid v1.2.0 => github.com/gofrs/uuid v4.2.0+incompatible
307-
308306
replace github.com/blevesearch/zapx/v15 v15.3.6 => github.com/zeripath/zapx/v15 v15.3.6-alignment-fix
309307

310308
exclude github.com/gofrs/uuid v3.2.0+incompatible
311309

312310
exclude github.com/gofrs/uuid v4.0.0+incompatible
313311

314312
exclude github.com/goccy/go-json v0.4.11
313+
314+
exclude github.com/satori/go.uuid v1.2.0

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,6 @@ github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
596596
github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
597597
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
598598
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
599-
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
600599
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
601600
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
602601
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=

models/activities/notification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func CountNotifications(ctx context.Context, opts *FindNotificationOptions) (int
141141

142142
// CreateRepoTransferNotification creates notification for the user a repository was transferred to
143143
func CreateRepoTransferNotification(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) error {
144-
return db.AutoTx(ctx, func(ctx context.Context) error {
144+
return db.WithTx(ctx, func(ctx context.Context) error {
145145
var notify []*Notification
146146

147147
if newOwner.IsOrganization() {

models/db/context.go

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,22 @@ type Engined interface {
7171

7272
// GetEngine will get a db Engine from this context or return an Engine restricted to this context
7373
func GetEngine(ctx context.Context) Engine {
74+
if e := getEngine(ctx); e != nil {
75+
return e
76+
}
77+
return x.Context(ctx)
78+
}
79+
80+
// getEngine will get a db Engine from this context or return nil
81+
func getEngine(ctx context.Context) Engine {
7482
if engined, ok := ctx.(Engined); ok {
7583
return engined.Engine()
7684
}
7785
enginedInterface := ctx.Value(enginedContextKey)
7886
if enginedInterface != nil {
7987
return enginedInterface.(Engined).Engine()
8088
}
81-
return x.Context(ctx)
89+
return nil
8290
}
8391

8492
// Committer represents an interface to Commit or Close the Context
@@ -87,10 +95,22 @@ type Committer interface {
8795
Close() error
8896
}
8997

90-
// TxContext represents a transaction Context
98+
// halfCommitter is a wrapper of Committer.
99+
// It can be closed early, but can't be committed early, it is useful for reusing a transaction.
100+
type halfCommitter struct {
101+
Committer
102+
}
103+
104+
func (*halfCommitter) Commit() error {
105+
// do nothing
106+
return nil
107+
}
108+
109+
// TxContext represents a transaction Context,
110+
// it will reuse the existing transaction in the parent context or create a new one.
91111
func TxContext(parentCtx context.Context) (*Context, Committer, error) {
92-
if InTransaction(parentCtx) {
93-
return nil, nil, ErrAlreadyInTransaction
112+
if sess, ok := inTransaction(parentCtx); ok {
113+
return newContext(parentCtx, sess, true), &halfCommitter{Committer: sess}, nil
94114
}
95115

96116
sess := x.NewSession()
@@ -102,20 +122,11 @@ func TxContext(parentCtx context.Context) (*Context, Committer, error) {
102122
return newContext(DefaultContext, sess, true), sess, nil
103123
}
104124

105-
// WithTx represents executing database operations on a transaction
106-
// This function will always open a new transaction, if a transaction exist in parentCtx return an error.
107-
func WithTx(parentCtx context.Context, f func(ctx context.Context) error) error {
108-
if InTransaction(parentCtx) {
109-
return ErrAlreadyInTransaction
110-
}
111-
return txWithNoCheck(parentCtx, f)
112-
}
113-
114-
// AutoTx represents executing database operations on a transaction, if the transaction exist,
125+
// WithTx represents executing database operations on a transaction, if the transaction exist,
115126
// this function will reuse it otherwise will create a new one and close it when finished.
116-
func AutoTx(parentCtx context.Context, f func(ctx context.Context) error) error {
117-
if InTransaction(parentCtx) {
118-
return f(newContext(parentCtx, GetEngine(parentCtx), true))
127+
func WithTx(parentCtx context.Context, f func(ctx context.Context) error) error {
128+
if sess, ok := inTransaction(parentCtx); ok {
129+
return f(newContext(parentCtx, sess, true))
119130
}
120131
return txWithNoCheck(parentCtx, f)
121132
}
@@ -202,25 +213,25 @@ func EstimateCount(ctx context.Context, bean interface{}) (int64, error) {
202213

203214
// InTransaction returns true if the engine is in a transaction otherwise return false
204215
func InTransaction(ctx context.Context) bool {
205-
var e Engine
206-
if engined, ok := ctx.(Engined); ok {
207-
e = engined.Engine()
208-
} else {
209-
enginedInterface := ctx.Value(enginedContextKey)
210-
if enginedInterface != nil {
211-
e = enginedInterface.(Engined).Engine()
212-
}
213-
}
216+
_, ok := inTransaction(ctx)
217+
return ok
218+
}
219+
220+
func inTransaction(ctx context.Context) (*xorm.Session, bool) {
221+
e := getEngine(ctx)
214222
if e == nil {
215-
return false
223+
return nil, false
216224
}
217225

218226
switch t := e.(type) {
219227
case *xorm.Engine:
220-
return false
228+
return nil, false
221229
case *xorm.Session:
222-
return t.IsInTx()
230+
if t.IsInTx() {
231+
return t, true
232+
}
233+
return nil, false
223234
default:
224-
return false
235+
return nil, false
225236
}
226237
}

models/db/context_test.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,62 @@ func TestInTransaction(t *testing.T) {
2525
assert.NoError(t, err)
2626
defer committer.Close()
2727
assert.True(t, db.InTransaction(ctx))
28-
assert.Error(t, db.WithTx(ctx, func(ctx context.Context) error {
28+
assert.NoError(t, db.WithTx(ctx, func(ctx context.Context) error {
2929
assert.True(t, db.InTransaction(ctx))
3030
return nil
3131
}))
3232
}
33+
34+
func TestTxContext(t *testing.T) {
35+
assert.NoError(t, unittest.PrepareTestDatabase())
36+
37+
{ // create new transaction
38+
ctx, committer, err := db.TxContext(db.DefaultContext)
39+
assert.NoError(t, err)
40+
assert.True(t, db.InTransaction(ctx))
41+
assert.NoError(t, committer.Commit())
42+
}
43+
44+
{ // reuse the transaction created by TxContext and commit it
45+
ctx, committer, err := db.TxContext(db.DefaultContext)
46+
engine := db.GetEngine(ctx)
47+
assert.NoError(t, err)
48+
assert.True(t, db.InTransaction(ctx))
49+
{
50+
ctx, committer, err := db.TxContext(ctx)
51+
assert.NoError(t, err)
52+
assert.True(t, db.InTransaction(ctx))
53+
assert.Equal(t, engine, db.GetEngine(ctx))
54+
assert.NoError(t, committer.Commit())
55+
}
56+
assert.NoError(t, committer.Commit())
57+
}
58+
59+
{ // reuse the transaction created by TxContext and close it
60+
ctx, committer, err := db.TxContext(db.DefaultContext)
61+
engine := db.GetEngine(ctx)
62+
assert.NoError(t, err)
63+
assert.True(t, db.InTransaction(ctx))
64+
{
65+
ctx, committer, err := db.TxContext(ctx)
66+
assert.NoError(t, err)
67+
assert.True(t, db.InTransaction(ctx))
68+
assert.Equal(t, engine, db.GetEngine(ctx))
69+
assert.NoError(t, committer.Close())
70+
}
71+
assert.NoError(t, committer.Close())
72+
}
73+
74+
{ // reuse the transaction created by WithTx
75+
assert.NoError(t, db.WithTx(db.DefaultContext, func(ctx context.Context) error {
76+
assert.True(t, db.InTransaction(ctx))
77+
{
78+
ctx, committer, err := db.TxContext(ctx)
79+
assert.NoError(t, err)
80+
assert.True(t, db.InTransaction(ctx))
81+
assert.NoError(t, committer.Commit())
82+
}
83+
return nil
84+
}))
85+
}
86+
}

models/db/error.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
package db
55

66
import (
7-
"errors"
87
"fmt"
98

109
"code.gitea.io/gitea/modules/util"
1110
)
1211

13-
var ErrAlreadyInTransaction = errors.New("database connection has already been in a transaction")
14-
1512
// ErrCancelled represents an error due to context cancellation
1613
type ErrCancelled struct {
1714
Message string

0 commit comments

Comments
 (0)