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 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package setting
  5. import (
  6. "time"
  7. "code.gitea.io/gitea/modules/git"
  8. "code.gitea.io/gitea/modules/log"
  9. )
  10. var (
  11. // Git settings
  12. Git = struct {
  13. Path string
  14. DisableDiffHighlight bool
  15. MaxGitDiffLines int
  16. MaxGitDiffLineCharacters int
  17. MaxGitDiffFiles int
  18. CommitsRangeSize int
  19. BranchesRangeSize int
  20. VerbosePush bool
  21. VerbosePushDelay time.Duration
  22. GCArgs []string `ini:"GC_ARGS" delim:" "`
  23. EnableAutoGitWireProtocol bool
  24. PullRequestPushMessage bool
  25. Timeout struct {
  26. Default int
  27. Migrate int
  28. Mirror int
  29. Clone int
  30. Pull int
  31. GC int `ini:"GC"`
  32. } `ini:"git.timeout"`
  33. }{
  34. DisableDiffHighlight: false,
  35. MaxGitDiffLines: 1000,
  36. MaxGitDiffLineCharacters: 5000,
  37. MaxGitDiffFiles: 100,
  38. CommitsRangeSize: 50,
  39. BranchesRangeSize: 20,
  40. VerbosePush: true,
  41. VerbosePushDelay: 5 * time.Second,
  42. GCArgs: []string{},
  43. EnableAutoGitWireProtocol: true,
  44. PullRequestPushMessage: true,
  45. Timeout: struct {
  46. Default int
  47. Migrate int
  48. Mirror int
  49. Clone int
  50. Pull int
  51. GC int `ini:"GC"`
  52. }{
  53. Default: int(git.DefaultCommandExecutionTimeout / time.Second),
  54. Migrate: 600,
  55. Mirror: 300,
  56. Clone: 300,
  57. Pull: 300,
  58. GC: 60,
  59. },
  60. }
  61. )
  62. func newGit() {
  63. if err := Cfg.Section("git").MapTo(&Git); err != nil {
  64. log.Fatal("Failed to map Git settings: %v", err)
  65. }
  66. if err := git.SetExecutablePath(Git.Path); err != nil {
  67. log.Fatal("Failed to initialize Git settings: %v", err)
  68. }
  69. git.DefaultCommandExecutionTimeout = time.Duration(Git.Timeout.Default) * time.Second
  70. version, err := git.LocalVersion()
  71. if err != nil {
  72. log.Fatal("Error retrieving git version: %v", err)
  73. }
  74. // force cleanup args
  75. git.GlobalCommandArgs = []string{}
  76. if git.CheckGitVersionAtLeast("2.9") == nil {
  77. // Explicitly disable credential helper, otherwise Git credentials might leak
  78. git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "credential.helper=")
  79. }
  80. var format = "Git Version: %s"
  81. var args = []interface{}{version.Original()}
  82. // Since git wire protocol has been released from git v2.18
  83. if Git.EnableAutoGitWireProtocol && git.CheckGitVersionAtLeast("2.18") == nil {
  84. git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "protocol.version=2")
  85. format += ", Wire Protocol %s Enabled"
  86. args = append(args, "Version 2") // for focus color
  87. }
  88. git.CommitsRangeSize = Git.CommitsRangeSize
  89. git.BranchesRangeSize = Git.BranchesRangeSize
  90. log.Info(format, args...)
  91. }