Skip to content

Commit 6df9513

Browse files
authored
Merge branch 'main' into fix-log
2 parents 2bf6fc3 + 1b2dfff commit 6df9513

File tree

17 files changed

+168
-120
lines changed

17 files changed

+168
-120
lines changed

cmd/doctor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"context"
78
"fmt"
89
golog "log"
910
"os"
@@ -130,8 +131,8 @@ func runRecreateTable(ctx *cli.Context) error {
130131
}
131132
recreateTables := migrate_base.RecreateTables(beans...)
132133

133-
return db.InitEngineWithMigration(stdCtx, func(x *xorm.Engine) error {
134-
if err := migrations.EnsureUpToDate(x); err != nil {
134+
return db.InitEngineWithMigration(stdCtx, func(ctx context.Context, x *xorm.Engine) error {
135+
if err := migrations.EnsureUpToDate(ctx, x); err != nil {
135136
return err
136137
}
137138
return recreateTables(x)

cmd/migrate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"context"
88

99
"code.gitea.io/gitea/models/db"
10-
"code.gitea.io/gitea/models/migrations"
1110
"code.gitea.io/gitea/modules/log"
1211
"code.gitea.io/gitea/modules/setting"
12+
"code.gitea.io/gitea/services/versioned_migration"
1313

1414
"github.com/urfave/cli/v2"
1515
)
@@ -36,7 +36,7 @@ func runMigrate(ctx *cli.Context) error {
3636
log.Info("Log path: %s", setting.Log.RootPath)
3737
log.Info("Configuration file: %s", setting.CustomConf)
3838

39-
if err := db.InitEngineWithMigration(context.Background(), migrations.Migrate); err != nil {
39+
if err := db.InitEngineWithMigration(context.Background(), versioned_migration.Migrate); err != nil {
4040
log.Fatal("Failed to initialize ORM engine: %v", err)
4141
return err
4242
}

cmd/migrate_storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import (
1313
actions_model "code.gitea.io/gitea/models/actions"
1414
"code.gitea.io/gitea/models/db"
1515
git_model "code.gitea.io/gitea/models/git"
16-
"code.gitea.io/gitea/models/migrations"
1716
packages_model "code.gitea.io/gitea/models/packages"
1817
repo_model "code.gitea.io/gitea/models/repo"
1918
user_model "code.gitea.io/gitea/models/user"
2019
"code.gitea.io/gitea/modules/log"
2120
packages_module "code.gitea.io/gitea/modules/packages"
2221
"code.gitea.io/gitea/modules/setting"
2322
"code.gitea.io/gitea/modules/storage"
23+
"code.gitea.io/gitea/services/versioned_migration"
2424

2525
"github.com/urfave/cli/v2"
2626
)
@@ -227,7 +227,7 @@ func runMigrateStorage(ctx *cli.Context) error {
227227
log.Info("Log path: %s", setting.Log.RootPath)
228228
log.Info("Configuration file: %s", setting.CustomConf)
229229

230-
if err := db.InitEngineWithMigration(context.Background(), migrations.Migrate); err != nil {
230+
if err := db.InitEngineWithMigration(context.Background(), versioned_migration.Migrate); err != nil {
231231
log.Fatal("Failed to initialize ORM engine: %v", err)
232232
return err
233233
}

cmd/web_acme.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"code.gitea.io/gitea/modules/log"
1717
"code.gitea.io/gitea/modules/process"
1818
"code.gitea.io/gitea/modules/setting"
19+
"code.gitea.io/gitea/modules/util"
1920

2021
"github.com/caddyserver/certmagic"
2122
)
@@ -68,9 +69,15 @@ func runACME(listenAddr string, m http.Handler) error {
6869
// And one more thing, no idea why we should set the global default variables here
6970
// But it seems that the current ACME code needs these global variables to make renew work.
7071
// Otherwise, "renew" will use incorrect storage path
72+
oldDefaultACME := certmagic.DefaultACME
7173
certmagic.Default.Storage = &certmagic.FileStorage{Path: setting.AcmeLiveDirectory}
7274
certmagic.DefaultACME = certmagic.ACMEIssuer{
73-
CA: setting.AcmeURL,
75+
// try to use the default values provided by DefaultACME
76+
CA: util.IfZero(setting.AcmeURL, oldDefaultACME.CA),
77+
TestCA: oldDefaultACME.TestCA,
78+
Logger: oldDefaultACME.Logger,
79+
HTTPProxy: oldDefaultACME.HTTPProxy,
80+
7481
TrustedRoots: certPool,
7582
Email: setting.AcmeEmail,
7683
Agreed: setting.AcmeTOS,

models/db/engine_init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func UnsetDefaultEngine() {
105105
// When called from the "doctor" command, the migration function is a version check
106106
// that prevents the doctor from fixing anything in the database if the migration level
107107
// is different from the expected value.
108-
func InitEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.Engine) error) (err error) {
108+
func InitEngineWithMigration(ctx context.Context, migrateFunc func(context.Context, *xorm.Engine) error) (err error) {
109109
if err = InitEngine(ctx); err != nil {
110110
return err
111111
}
@@ -122,7 +122,7 @@ func InitEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.Engine)
122122
// Installation should only be being re-run if users want to recover an old database.
123123
// However, we should think carefully about should we support re-install on an installed instance,
124124
// as there may be other problems due to secret reinitialization.
125-
if err = migrateFunc(xormEngine); err != nil {
125+
if err = migrateFunc(ctx, xormEngine); err != nil {
126126
return fmt.Errorf("migrate: %w", err)
127127
}
128128

models/migrations/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ func ExpectedDBVersion() int64 {
413413
}
414414

415415
// EnsureUpToDate will check if the db is at the correct version
416-
func EnsureUpToDate(x *xorm.Engine) error {
416+
func EnsureUpToDate(ctx context.Context, x *xorm.Engine) error {
417417
currentDB, err := GetCurrentDBVersion(x)
418418
if err != nil {
419419
return err

routers/common/db.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"code.gitea.io/gitea/modules/log"
1515
"code.gitea.io/gitea/modules/setting"
1616
"code.gitea.io/gitea/modules/setting/config"
17+
"code.gitea.io/gitea/services/versioned_migration"
1718

1819
"xorm.io/xorm"
1920
)
@@ -41,16 +42,16 @@ func InitDBEngine(ctx context.Context) (err error) {
4142
return nil
4243
}
4344

44-
func migrateWithSetting(x *xorm.Engine) error {
45+
func migrateWithSetting(ctx context.Context, x *xorm.Engine) error {
4546
if setting.Database.AutoMigration {
46-
return migrations.Migrate(x)
47+
return versioned_migration.Migrate(ctx, x)
4748
}
4849

4950
if current, err := migrations.GetCurrentDBVersion(x); err != nil {
5051
return err
5152
} else if current < 0 {
5253
// execute migrations when the database isn't initialized even if AutoMigration is false
53-
return migrations.Migrate(x)
54+
return versioned_migration.Migrate(ctx, x)
5455
} else if expected := migrations.ExpectedDBVersion(); current != expected {
5556
log.Fatal(`"database.AUTO_MIGRATION" is disabled, but current database version %d is not equal to the expected version %d.`+
5657
`You can set "database.AUTO_MIGRATION" to true or migrate manually by running "gitea [--config /path/to/app.ini] migrate"`, current, expected)

routers/install/install.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
"code.gitea.io/gitea/models/db"
1919
db_install "code.gitea.io/gitea/models/db/install"
20-
"code.gitea.io/gitea/models/migrations"
2120
system_model "code.gitea.io/gitea/models/system"
2221
user_model "code.gitea.io/gitea/models/user"
2322
"code.gitea.io/gitea/modules/auth/password/hash"
@@ -37,6 +36,7 @@ import (
3736
auth_service "code.gitea.io/gitea/services/auth"
3837
"code.gitea.io/gitea/services/context"
3938
"code.gitea.io/gitea/services/forms"
39+
"code.gitea.io/gitea/services/versioned_migration"
4040

4141
"gitea.com/go-chi/session"
4242
)
@@ -359,7 +359,7 @@ func SubmitInstall(ctx *context.Context) {
359359
}
360360

361361
// Init the engine with migration
362-
if err = db.InitEngineWithMigration(ctx, migrations.Migrate); err != nil {
362+
if err = db.InitEngineWithMigration(ctx, versioned_migration.Migrate); err != nil {
363363
db.UnsetDefaultEngine()
364364
ctx.Data["Err_DbSetting"] = true
365365
ctx.RenderWithErr(ctx.Tr("install.invalid_db_setting", err), tplInstall, &form)

routers/web/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
820820

821821
if !fileOnly {
822822
// note: use mergeBase is set to false because we already have the merge base from the pull request info
823-
diffTree, err := gitdiff.GetDiffTree(ctx, gitRepo, false, pull.MergeBase, headCommitID)
823+
diffTree, err := gitdiff.GetDiffTree(ctx, gitRepo, false, startCommitID, endCommitID)
824824
if err != nil {
825825
ctx.ServerError("GetDiffTree", err)
826826
return

services/doctor/dbversion.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"code.gitea.io/gitea/models/db"
1010
"code.gitea.io/gitea/models/migrations"
1111
"code.gitea.io/gitea/modules/log"
12+
"code.gitea.io/gitea/services/versioned_migration"
1213
)
1314

1415
func checkDBVersion(ctx context.Context, logger log.Logger, autofix bool) error {
@@ -21,7 +22,7 @@ func checkDBVersion(ctx context.Context, logger log.Logger, autofix bool) error
2122
logger.Warn("Got Error: %v during ensure up to date", err)
2223
logger.Warn("Attempting to migrate to the latest DB version to fix this.")
2324

24-
err = db.InitEngineWithMigration(ctx, migrations.Migrate)
25+
err = db.InitEngineWithMigration(ctx, versioned_migration.Migrate)
2526
if err != nil {
2627
logger.Critical("Error: %v during migration", err)
2728
}

0 commit comments

Comments
 (0)