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.2KB

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