Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. version "github.com/mcuadros/go-version"
  10. )
  11. var (
  12. // Git settings
  13. Git = struct {
  14. Path string
  15. DisableDiffHighlight bool
  16. MaxGitDiffLines int
  17. MaxGitDiffLineCharacters int
  18. MaxGitDiffFiles int
  19. VerbosePush bool
  20. VerbosePushDelay time.Duration
  21. GCArgs []string `ini:"GC_ARGS" delim:" "`
  22. EnableAutoGitWireProtocol bool
  23. Timeout struct {
  24. Default int
  25. Migrate int
  26. Mirror int
  27. Clone int
  28. Pull int
  29. GC int `ini:"GC"`
  30. } `ini:"git.timeout"`
  31. }{
  32. DisableDiffHighlight: false,
  33. MaxGitDiffLines: 1000,
  34. MaxGitDiffLineCharacters: 5000,
  35. MaxGitDiffFiles: 100,
  36. VerbosePush: true,
  37. VerbosePushDelay: 5 * time.Second,
  38. GCArgs: []string{},
  39. EnableAutoGitWireProtocol: true,
  40. Timeout: struct {
  41. Default int
  42. Migrate int
  43. Mirror int
  44. Clone int
  45. Pull int
  46. GC int `ini:"GC"`
  47. }{
  48. Default: int(git.DefaultCommandExecutionTimeout / time.Second),
  49. Migrate: 600,
  50. Mirror: 300,
  51. Clone: 300,
  52. Pull: 300,
  53. GC: 60,
  54. },
  55. }
  56. )
  57. func newGit() {
  58. if err := Cfg.Section("git").MapTo(&Git); err != nil {
  59. log.Fatal("Failed to map Git settings: %v", err)
  60. }
  61. if err := git.SetExecutablePath(Git.Path); err != nil {
  62. log.Fatal("Failed to initialize Git settings", err)
  63. }
  64. git.DefaultCommandExecutionTimeout = time.Duration(Git.Timeout.Default) * time.Second
  65. binVersion, err := git.BinVersion()
  66. if err != nil {
  67. log.Fatal("Error retrieving git version: %v", err)
  68. }
  69. if version.Compare(binVersion, "2.9", ">=") {
  70. // Explicitly disable credential helper, otherwise Git credentials might leak
  71. git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "credential.helper=")
  72. }
  73. var format = "Git Version: %s"
  74. var args = []interface{}{binVersion}
  75. // Since git wire protocol has been released from git v2.18
  76. if Git.EnableAutoGitWireProtocol && version.Compare(binVersion, "2.18", ">=") {
  77. git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "protocol.version=2")
  78. format += ", Wire Protocol %s Enabled"
  79. args = append(args, "Version 2") // for focus color
  80. }
  81. log.Info(format, args...)
  82. }