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