1
0
Fork 0
forked from forgejo/forgejo

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

## ⚠️ 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`
This commit is contained in:
wxiaoguang 2023-05-28 09:07:14 +08:00 committed by GitHub
parent 0d54395fb5
commit 2f149c5c9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 61 deletions

View file

@ -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")