mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-11 05:41:50 +09:00
Backport #39703 by @silverwind Gitea's default `gc.reflogExpire = 90` is parsed by git as `1990-<month>-<day>`, currently `1990-10-09`, so reachable reflog entries never expired. Since git 2.54, auto maintenance runs its reflog-expire task in the foreground of every push, and its trigger ignores reachability, so busy repos rerun `git reflog expire --all` on every push without pruning anything, stalling large repos for over a minute. - Stop setting `gc.reflogExpire` so git's own defaults apply, and remove the `90` written by earlier versions - Treat the legacy `[git.reflog] EXPIRATION` as days, as documented The next push to each repo prunes the accumulated entries once. Fixes: https://github.com/go-gitea/gitea/issues/39693 Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -810,7 +810,6 @@ LEVEL = Info
|
||||
;[git.config]
|
||||
;diff.algorithm = histogram
|
||||
;core.logAllRefUpdates = true
|
||||
;gc.reflogExpire = 90
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
@@ -125,6 +125,11 @@ func syncGitConfig(ctx context.Context) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Gitea used to write "90", which git reads as a date in 1990
|
||||
if err := configUnsetAll(ctx, "gc.reflogExpire", "90"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Apply user's git config options last so they take precedence over builtin defaults
|
||||
for k, v := range setting.GitConfig.Options {
|
||||
if err = configSet(ctx, strings.ToLower(k), v); err != nil {
|
||||
|
||||
@@ -60,8 +60,10 @@ func TestSyncGitConfig(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.GitConfig)()
|
||||
|
||||
assert.Empty(t, setting.GitConfig.Options)
|
||||
assert.NoError(t, configSet(t.Context(), "gc.reflogExpire", "90"))
|
||||
assert.NoError(t, syncGitConfig(t.Context()))
|
||||
assert.True(t, gitConfigContains("commitGraph = true")) // builtin default config
|
||||
assert.False(t, gitConfigContains("reflogExpire"))
|
||||
|
||||
setting.GitConfig.Options["sync-test.cfg-key-a"] = "CfgValA"
|
||||
setting.GitConfig.Options["core.commitgraph"] = "false"
|
||||
|
||||
@@ -89,7 +89,6 @@ func loadGitFrom(rootCfg ConfigProvider) {
|
||||
GitConfig.Options = make(map[string]string)
|
||||
GitConfig.SetOption("diff.algorithm", "histogram")
|
||||
GitConfig.SetOption("core.logAllRefUpdates", "true")
|
||||
GitConfig.SetOption("gc.reflogExpire", "90")
|
||||
|
||||
secGitReflog := rootCfg.Section("git.reflog")
|
||||
if secGitReflog.HasKey("ENABLED") {
|
||||
@@ -97,8 +96,8 @@ func loadGitFrom(rootCfg ConfigProvider) {
|
||||
GitConfig.SetOption("core.logAllRefUpdates", secGitReflog.Key("ENABLED").In("true", []string{"true", "false"}))
|
||||
}
|
||||
if secGitReflog.HasKey("EXPIRATION") {
|
||||
deprecatedSetting(rootCfg, "git.reflog", "EXPIRATION", "git.config", "core.reflogExpire", "1.21")
|
||||
GitConfig.SetOption("gc.reflogExpire", secGitReflog.Key("EXPIRATION").String())
|
||||
deprecatedSetting(rootCfg, "git.reflog", "EXPIRATION", "git.config", "gc.reflogExpire", "1.21")
|
||||
GitConfig.SetOption("gc.reflogExpire", secGitReflog.Key("EXPIRATION").String()+".days")
|
||||
}
|
||||
|
||||
for _, key := range secGitConfig.Keys() {
|
||||
|
||||
@@ -38,8 +38,8 @@ diff.algorithm = other
|
||||
}
|
||||
|
||||
func TestGitReflog(t *testing.T) {
|
||||
defer test.MockVariableValue(&Git)
|
||||
defer test.MockVariableValue(&GitConfig)
|
||||
defer test.MockVariableValue(&Git)()
|
||||
defer test.MockVariableValue(&GitConfig)()
|
||||
|
||||
// default reflog config without legacy options
|
||||
cfg, err := NewConfigProviderFromData(``)
|
||||
@@ -47,7 +47,7 @@ func TestGitReflog(t *testing.T) {
|
||||
loadGitFrom(cfg)
|
||||
|
||||
assert.Equal(t, "true", GitConfig.GetOption("core.logAllRefUpdates"))
|
||||
assert.Equal(t, "90", GitConfig.GetOption("gc.reflogExpire"))
|
||||
assert.Empty(t, GitConfig.GetOption("gc.reflogExpire"))
|
||||
|
||||
// custom reflog config by legacy options
|
||||
cfg, err = NewConfigProviderFromData(`
|
||||
@@ -59,5 +59,5 @@ EXPIRATION = 123
|
||||
loadGitFrom(cfg)
|
||||
|
||||
assert.Equal(t, "false", GitConfig.GetOption("core.logAllRefUpdates"))
|
||||
assert.Equal(t, "123", GitConfig.GetOption("gc.reflogExpire"))
|
||||
assert.Equal(t, "123.days", GitConfig.GetOption("gc.reflogExpire"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user