You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

git.go 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package setting
  4. import (
  5. "path/filepath"
  6. "strings"
  7. "time"
  8. "code.gitea.io/gitea/modules/log"
  9. )
  10. // Git settings
  11. var Git = struct {
  12. Path string
  13. HomePath string
  14. DisableDiffHighlight bool
  15. MaxGitDiffLines int
  16. MaxGitDiffLineCharacters int
  17. MaxGitDiffFiles int
  18. CommitsRangeSize int // CommitsRangeSize the default commits range size
  19. BranchesRangeSize int // BranchesRangeSize the default branches range size
  20. VerbosePush bool
  21. VerbosePushDelay time.Duration
  22. GCArgs []string `ini:"GC_ARGS" delim:" "`
  23. EnableAutoGitWireProtocol bool
  24. PullRequestPushMessage bool
  25. LargeObjectThreshold int64
  26. DisableCoreProtectNTFS bool
  27. DisablePartialClone bool
  28. Timeout struct {
  29. Default int
  30. Migrate int
  31. Mirror int
  32. Clone int
  33. Pull int
  34. GC int `ini:"GC"`
  35. } `ini:"git.timeout"`
  36. }{
  37. DisableDiffHighlight: false,
  38. MaxGitDiffLines: 1000,
  39. MaxGitDiffLineCharacters: 5000,
  40. MaxGitDiffFiles: 100,
  41. CommitsRangeSize: 50,
  42. BranchesRangeSize: 20,
  43. VerbosePush: true,
  44. VerbosePushDelay: 5 * time.Second,
  45. GCArgs: []string{},
  46. EnableAutoGitWireProtocol: true,
  47. PullRequestPushMessage: true,
  48. LargeObjectThreshold: 1024 * 1024,
  49. DisablePartialClone: false,
  50. Timeout: struct {
  51. Default int
  52. Migrate int
  53. Mirror int
  54. Clone int
  55. Pull int
  56. GC int `ini:"GC"`
  57. }{
  58. Default: 360,
  59. Migrate: 600,
  60. Mirror: 300,
  61. Clone: 300,
  62. Pull: 300,
  63. GC: 60,
  64. },
  65. }
  66. type GitConfigType struct {
  67. Options map[string]string // git config key is case-insensitive, always use lower-case
  68. }
  69. func (c *GitConfigType) SetOption(key, val string) {
  70. c.Options[strings.ToLower(key)] = val
  71. }
  72. func (c *GitConfigType) GetOption(key string) string {
  73. return c.Options[strings.ToLower(key)]
  74. }
  75. var GitConfig = GitConfigType{
  76. Options: make(map[string]string),
  77. }
  78. func loadGitFrom(rootCfg ConfigProvider) {
  79. sec := rootCfg.Section("git")
  80. if err := sec.MapTo(&Git); err != nil {
  81. log.Fatal("Failed to map Git settings: %v", err)
  82. }
  83. secGitConfig := rootCfg.Section("git.config")
  84. GitConfig.Options = make(map[string]string)
  85. GitConfig.SetOption("diff.algorithm", "histogram")
  86. GitConfig.SetOption("core.logAllRefUpdates", "true")
  87. GitConfig.SetOption("gc.reflogExpire", "90")
  88. secGitReflog := rootCfg.Section("git.reflog")
  89. if secGitReflog.HasKey("ENABLED") {
  90. deprecatedSetting(rootCfg, "git.reflog", "ENABLED", "git.config", "core.logAllRefUpdates", "1.21")
  91. GitConfig.SetOption("core.logAllRefUpdates", secGitReflog.Key("ENABLED").In("true", []string{"true", "false"}))
  92. }
  93. if secGitReflog.HasKey("EXPIRATION") {
  94. deprecatedSetting(rootCfg, "git.reflog", "EXPIRATION", "git.config", "core.reflogExpire", "1.21")
  95. GitConfig.SetOption("gc.reflogExpire", secGitReflog.Key("EXPIRATION").String())
  96. }
  97. for _, key := range secGitConfig.Keys() {
  98. GitConfig.SetOption(key.Name(), key.String())
  99. }
  100. Git.HomePath = sec.Key("HOME_PATH").MustString("home")
  101. if !filepath.IsAbs(Git.HomePath) {
  102. Git.HomePath = filepath.Join(AppDataPath, Git.HomePath)
  103. } else {
  104. Git.HomePath = filepath.Clean(Git.HomePath)
  105. }
  106. }