Skip to content

Commit 869a13d

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix repository adoption on Windows (go-gitea#21646) Refactor docs (go-gitea#21627) Update "email usage" page to current ver. (1.18) (go-gitea#21649) Fix opaque background on mermaid diagrams (go-gitea#21642) Merge db.Iterate and IterateObjects (go-gitea#21641) Deal with markdown template without metadata (go-gitea#21639) [skip ci] Updated translations via Crowdin
2 parents c79db93 + f211d23 commit 869a13d

37 files changed

+141
-249
lines changed

Diff for: cmd/migrate_storage.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -83,43 +83,43 @@ var CmdMigrateStorage = cli.Command{
8383
}
8484

8585
func migrateAttachments(ctx context.Context, dstStorage storage.ObjectStorage) error {
86-
return db.IterateObjects(ctx, func(attach *repo_model.Attachment) error {
86+
return db.Iterate(ctx, nil, func(ctx context.Context, attach *repo_model.Attachment) error {
8787
_, err := storage.Copy(dstStorage, attach.RelativePath(), storage.Attachments, attach.RelativePath())
8888
return err
8989
})
9090
}
9191

9292
func migrateLFS(ctx context.Context, dstStorage storage.ObjectStorage) error {
93-
return db.IterateObjects(ctx, func(mo *git_model.LFSMetaObject) error {
93+
return db.Iterate(ctx, nil, func(ctx context.Context, mo *git_model.LFSMetaObject) error {
9494
_, err := storage.Copy(dstStorage, mo.RelativePath(), storage.LFS, mo.RelativePath())
9595
return err
9696
})
9797
}
9898

9999
func migrateAvatars(ctx context.Context, dstStorage storage.ObjectStorage) error {
100-
return db.IterateObjects(ctx, func(user *user_model.User) error {
100+
return db.Iterate(ctx, nil, func(ctx context.Context, user *user_model.User) error {
101101
_, err := storage.Copy(dstStorage, user.CustomAvatarRelativePath(), storage.Avatars, user.CustomAvatarRelativePath())
102102
return err
103103
})
104104
}
105105

106106
func migrateRepoAvatars(ctx context.Context, dstStorage storage.ObjectStorage) error {
107-
return db.IterateObjects(ctx, func(repo *repo_model.Repository) error {
107+
return db.Iterate(ctx, nil, func(ctx context.Context, repo *repo_model.Repository) error {
108108
_, err := storage.Copy(dstStorage, repo.CustomAvatarRelativePath(), storage.RepoAvatars, repo.CustomAvatarRelativePath())
109109
return err
110110
})
111111
}
112112

113113
func migrateRepoArchivers(ctx context.Context, dstStorage storage.ObjectStorage) error {
114-
return db.IterateObjects(ctx, func(archiver *repo_model.RepoArchiver) error {
114+
return db.Iterate(ctx, nil, func(ctx context.Context, archiver *repo_model.RepoArchiver) error {
115115
p := archiver.RelativePath()
116116
_, err := storage.Copy(dstStorage, p, storage.RepoArchives, p)
117117
return err
118118
})
119119
}
120120

121121
func migratePackages(ctx context.Context, dstStorage storage.ObjectStorage) error {
122-
return db.IterateObjects(ctx, func(pb *packages_model.PackageBlob) error {
122+
return db.Iterate(ctx, nil, func(ctx context.Context, pb *packages_model.PackageBlob) error {
123123
p := packages_module.KeyToRelativePath(packages_module.BlobHash256Key(pb.HashSHA256))
124124
_, err := storage.Copy(dstStorage, p, storage.Packages, p)
125125
return err

Diff for: docs/content/doc/advanced/hacking-on-gitea.zh-cn.md

-43
This file was deleted.

Diff for: docs/content/doc/advanced/make.fr-fr.md

-44
This file was deleted.

Diff for: docs/content/doc/advanced/make.zh-cn.md

-45
This file was deleted.

Diff for: docs/content/doc/advanced/third-party-tools.zh-cn.md

-39
This file was deleted.

Diff for: docs/content/doc/developers.zh-cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ draft: false
88
menu:
99
sidebar:
1010
name: "开发者"
11-
weight: 50
11+
weight: 55
1212
identifier: "developers"
1313
---

Diff for: docs/content/doc/installation/from-source.en-us.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ To build from source, the following programs must be present on the system:
8787

8888
- `go` {{< min-go-version >}} or higher, see [here](https://golang.org/dl/)
8989
- `node` {{< min-node-version >}} or higher with `npm`, see [here](https://nodejs.org/en/download/)
90-
- `make`, see <a href='{{< relref "doc/developers/hacking-on-gitea.en-us.md" >}}#installing-make'>here</a>
90+
- `make`, see [here]({{< relref "doc/developers/hacking-on-gitea.en-us.md" >}}#installing-make)
9191

9292
Various [make tasks](https://github.com/go-gitea/gitea/blob/main/Makefile)
9393
are provided to keep the build process as simple as possible.

Diff for: docs/content/doc/installation/from-source.fr-fr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ git checkout pr-xyz
5353

5454
## Compilation
5555

56-
Comme nous regroupons déjà toutes les bibliothèques requises pour compiler Gitea, vous pouvez continuer avec le processus de compilation lui-même. Nous fournissons diverses [tâches Make](https://github.com/go-gitea/gitea/blob/master/Makefile) pour rendre le processus de construction aussi simple que possible. <a href='{{< relref "doc/advanced/make.fr-fr.md" >}}'>Voyez ici comment obtenir Make</a>. Selon vos besoins, vous pourrez éventuellement ajouter diverses options de compilation, vous pouvez choisir entre ces options :
56+
Comme nous regroupons déjà toutes les bibliothèques requises pour compiler Gitea, vous pouvez continuer avec le processus de compilation lui-même. Nous fournissons diverses [tâches Make](https://github.com/go-gitea/gitea/blob/master/Makefile) pour rendre le processus de construction aussi simple que possible. [Voyez ici comment obtenir Make]({{< relref "doc/developers/hacking-on-gitea.fr-fr.md" >}}#installing-make). Selon vos besoins, vous pourrez éventuellement ajouter diverses options de compilation, vous pouvez choisir entre ces options :
5757

5858
* `bindata`: Intègre toutes les ressources nécessaires à l'exécution d'une instance de Gitea, ce qui rend un déploiement facile car il n'est pas nécessaire de se préoccuper des fichiers supplémentaires.
5959
* `sqlite sqlite_unlock_notify`: Active la prise en charge d'une base de données [SQLite3](https://sqlite.org/), ceci n'est recommandé que pour les petites installations de Gitea.

Diff for: docs/content/doc/installation/from-source.zh-cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ git checkout v{{< version >}}
5454

5555
- `go` {{< min-go-version >}} 或以上版本, 详见[这里](https://golang.google.cn/doc/install)
5656
- `node` {{< min-node-version >}} 或以上版本,并且安装 `npm`, 详见[这里](https://nodejs.org/zh-cn/download/)
57-
- `make`, 详见[这里]({{< relref "make.zh-cn.md" >}})</a>
57+
- `make`, 详见[这里]({{< relref "doc/developers/hacking-on-gitea.zh-cn.md" >}})</a>
5858

5959
各种可用的 [make 任务](https://github.com/go-gitea/gitea/blob/main/Makefile)
6060
可以用来使编译过程更方便。

Diff for: docs/content/doc/usage/email-setup.en-us.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ Directly use SMTP server as relay. This option is useful if you don't want to se
4747
ENABLED = true
4848
4949
MAILER_TYPE = smtp
50-
HOST = mail.mydomain.com:587
50+
SMTP_ADDR = mail.mydomain.com
51+
SMTP_PORT = 587
5152
IS_TLS_ENABLED = true
5253
5354
PASSWD = `password`
@@ -75,7 +76,8 @@ The following configuration should work with GMail's SMTP server:
7576
```ini
7677
[mailer]
7778
ENABLED = true
78-
HOST = smtp.gmail.com:465
79+
SMTP_ADDR = smtp.gmail.com
80+
SMTP_PORT = 465
7981
8082
8183
PASSWD = ***

Diff for: docs/static/_redirects

+3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ https://gitea-docs.netlify.com/* https://docs.gitea.io/:splat 302!
99

1010
/en-us/ci-cd/ /en-us/integrations/ 302!
1111
/en-us/third-party-tools/ /en-us/integrations/ 302!
12+
/zh-cn/third-party-tools/ /zh-cn/integrations/ 302!
1213
/en-us/make/ /en-us/hacking-on-gitea/ 302!
14+
/zh-cn/make/ /zh-cn/hacking-on-gitea/ 302!
15+
/fr-fr/make/ /fr-fr/hacking-on-gitea/ 302!
1316
/en-us/upgrade/ /en-us/upgrade-from-gitea/ 302!
1417
/fr-fr/upgrade/ /fr-fr/upgrade-from-gitea/ 302!
1518
/zh-cn/upgrade/ /zh-cn/upgrade-from-gitea/ 302!

Diff for: models/db/context.go

-10
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import (
88
"context"
99
"database/sql"
1010

11-
"code.gitea.io/gitea/modules/setting"
12-
13-
"xorm.io/builder"
1411
"xorm.io/xorm/schemas"
1512
)
1613

@@ -121,13 +118,6 @@ func WithTx(f func(ctx context.Context) error, stdCtx ...context.Context) error
121118
return sess.Commit()
122119
}
123120

124-
// Iterate iterates the databases and doing something
125-
func Iterate(ctx context.Context, tableBean interface{}, cond builder.Cond, fun func(idx int, bean interface{}) error) error {
126-
return GetEngine(ctx).Where(cond).
127-
BufferSize(setting.Database.IterateBufferSize).
128-
Iterate(tableBean, fun)
129-
}
130-
131121
// Insert inserts records into database
132122
func Insert(ctx context.Context, beans ...interface{}) error {
133123
_, err := GetEngine(ctx).Insert(beans...)

Diff for: models/db/iterate.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,30 @@ import (
88
"context"
99

1010
"code.gitea.io/gitea/modules/setting"
11+
12+
"xorm.io/builder"
1113
)
1214

13-
// IterateObjects iterate all the Bean object
14-
func IterateObjects[Object any](ctx context.Context, f func(repo *Object) error) error {
15+
// Iterate iterate all the Bean object
16+
func Iterate[Bean any](ctx context.Context, cond builder.Cond, f func(ctx context.Context, bean *Bean) error) error {
1517
var start int
1618
batchSize := setting.Database.IterateBufferSize
1719
sess := GetEngine(ctx)
1820
for {
19-
repos := make([]*Object, 0, batchSize)
20-
if err := sess.Limit(batchSize, start).Find(&repos); err != nil {
21+
beans := make([]*Bean, 0, batchSize)
22+
if cond != nil {
23+
sess = sess.Where(cond)
24+
}
25+
if err := sess.Limit(batchSize, start).Find(&beans); err != nil {
2126
return err
2227
}
23-
if len(repos) == 0 {
28+
if len(beans) == 0 {
2429
return nil
2530
}
26-
start += len(repos)
31+
start += len(beans)
2732

28-
for _, repo := range repos {
29-
if err := f(repo); err != nil {
33+
for _, bean := range beans {
34+
if err := f(ctx, bean); err != nil {
3035
return err
3136
}
3237
}

Diff for: models/db/iterate_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package db_test
6+
7+
import (
8+
"context"
9+
"testing"
10+
11+
"code.gitea.io/gitea/models/db"
12+
repo_model "code.gitea.io/gitea/models/repo"
13+
"code.gitea.io/gitea/models/unittest"
14+
15+
"github.com/stretchr/testify/assert"
16+
)
17+
18+
func TestIterate(t *testing.T) {
19+
assert.NoError(t, unittest.PrepareTestDatabase())
20+
xe := unittest.GetXORMEngine()
21+
assert.NoError(t, xe.Sync(&repo_model.RepoUnit{}))
22+
23+
var repoCnt int
24+
err := db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repo *repo_model.RepoUnit) error {
25+
repoCnt++
26+
return nil
27+
})
28+
assert.NoError(t, err)
29+
assert.EqualValues(t, 79, repoCnt)
30+
31+
err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repoUnit *repo_model.RepoUnit) error {
32+
reopUnit2 := repo_model.RepoUnit{ID: repoUnit.ID}
33+
has, err := db.GetByBean(ctx, &reopUnit2)
34+
if err != nil {
35+
return err
36+
} else if !has {
37+
return db.ErrNotExist{Resource: "repo_unit", ID: repoUnit.ID}
38+
}
39+
assert.EqualValues(t, repoUnit.RepoID, repoUnit.RepoID)
40+
assert.EqualValues(t, repoUnit.CreatedUnix, repoUnit.CreatedUnix)
41+
return nil
42+
})
43+
assert.NoError(t, err)
44+
}

0 commit comments

Comments
 (0)