本站源代码
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

89 lines
2.3KB

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