summaryrefslogtreecommitdiffstats
path: root/modules/setting
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-05-28 09:07:14 +0800
committerGitHub <noreply@github.com>2023-05-28 01:07:14 +0000
commit2f149c5c9db97f20fbbc65e32d1f3133048b11a2 (patch)
tree5ba9cbca56fadf9c89ffc0a96172ee335b14a4fb /modules/setting
parent0d54395fb544d52585046bf0424659cec0626e31 (diff)
downloadgitea-2f149c5c9db97f20fbbc65e32d1f3133048b11a2.tar.gz
gitea-2f149c5c9db97f20fbbc65e32d1f3133048b11a2.zip
Use `[git.config]` for reflog cleaning up (#24958)
Follow https://github.com/go-gitea/gitea/pull/24860#discussion_r1200589651 Use `[git.config]` for reflog cleaning up, the new options are more flexible. * https://git-scm.com/docs/git-config#Documentation/git-config.txt-corelogAllRefUpdates * https://git-scm.com/docs/git-config#Documentation/git-config.txt-gcreflogExpire ## :warning: BREAKING The section `[git.reflog]` is now obsolete and its keys have been moved to the following replacements: - `[git.reflog].ENABLED` → `[git.config].core.logAllRefUpdates` - `[git.reflog].EXPIRATION` → `[git.config].gc.reflogExpire`
Diffstat (limited to 'modules/setting')
-rw-r--r--modules/setting/git.go48
-rw-r--r--modules/setting/git_test.go33
2 files changed, 58 insertions, 23 deletions
diff --git a/modules/setting/git.go b/modules/setting/git.go
index 29ec37f866..48a4e7f30d 100644
--- a/modules/setting/git.go
+++ b/modules/setting/git.go
@@ -16,10 +16,7 @@ var Git = struct {
Path string
HomePath string
DisableDiffHighlight bool
- Reflog struct {
- Enabled bool
- Expiration int
- } `ini:"git.reflog"`
+
MaxGitDiffLines int
MaxGitDiffLineCharacters int
MaxGitDiffFiles int
@@ -42,13 +39,6 @@ var Git = struct {
GC int `ini:"GC"`
} `ini:"git.timeout"`
}{
- Reflog: struct {
- Enabled bool
- Expiration int
- }{
- Enabled: true,
- Expiration: 90,
- },
DisableDiffHighlight: false,
MaxGitDiffLines: 1000,
MaxGitDiffLineCharacters: 5000,
@@ -79,9 +69,19 @@ var Git = struct {
},
}
-var GitConfig = struct {
- Options map[string]string
-}{
+type GitConfigType struct {
+ Options map[string]string // git config key is case-insensitive, always use lower-case
+}
+
+func (c *GitConfigType) SetOption(key, val string) {
+ c.Options[strings.ToLower(key)] = val
+}
+
+func (c *GitConfigType) GetOption(key string) string {
+ return c.Options[strings.ToLower(key)]
+}
+
+var GitConfig = GitConfigType{
Options: make(map[string]string),
}
@@ -93,12 +93,22 @@ func loadGitFrom(rootCfg ConfigProvider) {
secGitConfig := rootCfg.Section("git.config")
GitConfig.Options = make(map[string]string)
- for _, key := range secGitConfig.Keys() {
- // git config key is case-insensitive, so always use lower-case
- GitConfig.Options[strings.ToLower(key.Name())] = key.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") {
+ deprecatedSetting(rootCfg, "git.reflog", "ENABLED", "git.config", "core.logAllRefUpdates", "1.21")
+ GitConfig.SetOption("core.logAllRefUpdates", secGitReflog.Key("ENABLED").In("true", []string{"true", "false"}))
}
- if _, ok := GitConfig.Options["diff.algorithm"]; !ok {
- GitConfig.Options["diff.algorithm"] = "histogram"
+ if secGitReflog.HasKey("EXPIRATION") {
+ deprecatedSetting(rootCfg, "git.reflog", "EXPIRATION", "git.config", "core.reflogExpire", "1.21")
+ GitConfig.SetOption("gc.reflogExpire", secGitReflog.Key("EXPIRATION").String())
+ }
+
+ for _, key := range secGitConfig.Keys() {
+ GitConfig.SetOption(key.Name(), key.String())
}
Git.HomePath = sec.Key("HOME_PATH").MustString("home")
diff --git a/modules/setting/git_test.go b/modules/setting/git_test.go
index 1da8c87cc8..441c514d8c 100644
--- a/modules/setting/git_test.go
+++ b/modules/setting/git_test.go
@@ -23,8 +23,6 @@ a.b = 1
`)
assert.NoError(t, err)
loadGitFrom(cfg)
-
- assert.Len(t, GitConfig.Options, 2)
assert.EqualValues(t, "1", GitConfig.Options["a.b"])
assert.EqualValues(t, "histogram", GitConfig.Options["diff.algorithm"])
@@ -34,7 +32,34 @@ diff.algorithm = other
`)
assert.NoError(t, err)
loadGitFrom(cfg)
-
- assert.Len(t, GitConfig.Options, 1)
assert.EqualValues(t, "other", GitConfig.Options["diff.algorithm"])
}
+
+func TestGitReflog(t *testing.T) {
+ oldGit := Git
+ oldGitConfig := GitConfig
+ defer func() {
+ Git = oldGit
+ GitConfig = oldGitConfig
+ }()
+
+ // default reflog config without legacy options
+ cfg, err := NewConfigProviderFromData(``)
+ assert.NoError(t, err)
+ loadGitFrom(cfg)
+
+ assert.EqualValues(t, "true", GitConfig.GetOption("core.logAllRefUpdates"))
+ assert.EqualValues(t, "90", GitConfig.GetOption("gc.reflogExpire"))
+
+ // custom reflog config by legacy options
+ cfg, err = NewConfigProviderFromData(`
+[git.reflog]
+ENABLED = false
+EXPIRATION = 123
+`)
+ assert.NoError(t, err)
+ loadGitFrom(cfg)
+
+ assert.EqualValues(t, "false", GitConfig.GetOption("core.logAllRefUpdates"))
+ assert.EqualValues(t, "123", GitConfig.GetOption("gc.reflogExpire"))
+}