| 1 | package configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 5 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 6 | "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 8 | "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/" |
| 9 | |
| 10 | "github.com/git-lfs/git-lfs/v3/gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/" |
| 11 | "github.com/git-lfs/git-lfs/v3/trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/" |
| 12 | ) |
| 13 | |
| 14 | type GitFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher# struct { |
| 15 | vmuscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#vmu. syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.RWMutexscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex# |
| 16 | valsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#vals. map[string][]string |
| 17 | } |
| 18 | |
| 19 | func readGitConfigscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/readGitConfig().(configs ...*gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.ConfigurationSourcescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ConfigurationSource#) (gf *GitFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#, extensions map[string]Extensionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Extension#, uniqRemotes map[string]bool) { |
| 20 | vals := make(map[string][]string) |
| 21 | ignored := make([]string, 0) |
| 22 | |
| 23 | extensions = make(map[string]Extensionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Extension#) |
| 24 | uniqRemotes = make(map[string]bool) |
| 25 | |
| 26 | for _, gc := range configs { |
| 27 | uniqKeys := make(map[string]string) |
| 28 | |
| 29 | for _, line := range gc.Linesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ConfigurationSource#Lines. { |
| 30 | pieces := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.SplitNscip-go gomod github.com/golang/go/src go1.25.0 strings/SplitN().(line, "=", 2) |
| 31 | if len(pieces) < 2 { |
| 32 | continue |
| 33 | } |
| 34 | |
| 35 | allowed := !gc.OnlySafeKeysscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ConfigurationSource#OnlySafeKeys. |
| 36 | |
| 37 | // We don't need to change the case of the key here, |
| 38 | // since Git will already have canonicalized it for us. |
| 39 | key, val := pieces[0], pieces[1] |
| 40 | |
| 41 | if origKey, ok := uniqKeys[key]; ok { |
| 42 | if ShowConfigWarningsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/ShowConfigWarnings. && len(vals[key]) > 0 && vals[key][len(vals[key])-1] != val && stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(key, gitConfigWarningPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/gitConfigWarningPrefix.) { |
| 43 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintlnscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprintln().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.25.0 os/Stderr., trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("warning: These `git config` values clash:")) |
| 44 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.25.0 os/Stderr., " git config %q = %q\n", origKey, vals[key]) |
| 45 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.25.0 os/Stderr., " git config %q = %q\n", pieces[0], val) |
| 46 | } |
| 47 | } else { |
| 48 | uniqKeys[key] = pieces[0] |
| 49 | } |
| 50 | |
| 51 | parts := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.0 strings/Split().(key, ".") |
| 52 | if len(parts) == 4 && parts[0] == "lfs" && parts[1] == "extension" { |
| 53 | // prop: lfs.extension.<name>.<prop> |
| 54 | name := parts[2] |
| 55 | prop := parts[3] |
| 56 | |
| 57 | ext := extensions[name] |
| 58 | ext.Namescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Extension#Name. = name |
| 59 | |
| 60 | switch prop { |
| 61 | case "clean": |
| 62 | if gc.OnlySafeKeysscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ConfigurationSource#OnlySafeKeys. { |
| 63 | ignored = append(ignored, key) |
| 64 | continue |
| 65 | } |
| 66 | ext.Cleanscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Extension#Clean. = val |
| 67 | case "smudge": |
| 68 | if gc.OnlySafeKeysscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ConfigurationSource#OnlySafeKeys. { |
| 69 | ignored = append(ignored, key) |
| 70 | continue |
| 71 | } |
| 72 | ext.Smudgescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Extension#Smudge. = val |
| 73 | case "priority": |
| 74 | allowed = true |
| 75 | p, err := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.25.0 strconv/Atoi().(val) |
| 76 | if err == nil && p >= 0 { |
| 77 | ext.Priorityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Extension#Priority. = p |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | extensions[name] = ext |
| 82 | } else if len(parts) > 1 && parts[0] == "remote" { |
| 83 | if gc.OnlySafeKeysscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ConfigurationSource#OnlySafeKeys. && (len(parts) == 3 && parts[2] != "lfsurl") { |
| 84 | ignored = append(ignored, key) |
| 85 | continue |
| 86 | } |
| 87 | |
| 88 | allowed = true |
| 89 | remote := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.0 strings/Join().(parts[1:len(parts)-1], ".") |
| 90 | uniqRemotes[remote] = remote == "origin" |
| 91 | } else if len(parts) > 2 && parts[len(parts)-1] == "access" { |
| 92 | allowed = true |
| 93 | } |
| 94 | |
| 95 | if !allowed && keyIsUnsafescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/keyIsUnsafe().(key) { |
| 96 | ignored = append(ignored, key) |
| 97 | continue |
| 98 | } |
| 99 | |
| 100 | vals[key] = append(vals[key], val) |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if len(ignored) > 0 { |
| 105 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprint().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.25.0 os/Stderr., trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("warning: These unsafe '.lfsconfig' keys were ignored:"), "\n\n") |
| 106 | for _, key := range ignored { |
| 107 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.25.0 os/Stderr., " %s\n", key) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | gf = &GitFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#{valsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#vals.: vals} |
| 112 | |
| 113 | return |
| 114 | } |
| 115 | |
| 116 | // Get implements the Fetcher interface, and returns the value associated with |
| 117 | // a given key and true, signaling that the value was present. Otherwise, an |
| 118 | // empty string and false will be returned, signaling that the value was |
| 119 | // absent. |
| 120 | // |
| 121 | // Map lookup by key is case-insensitive, except for the middle part of a |
| 122 | // three-part key, as per the .gitconfig specification. |
| 123 | // |
| 124 | // Get is safe to call across multiple goroutines. |
| 125 | func (g *GitFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#) Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#Get().(key string) (val string, ok bool) { |
| 126 | all := g.GetAllscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#GetAll().(key) |
| 127 | |
| 128 | if len(all) == 0 { |
| 129 | return "", false |
| 130 | } |
| 131 | return all[len(all)-1], true |
| 132 | } |
| 133 | |
| 134 | func (g *GitFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#) GetAllscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#GetAll().(key string) []string { |
| 135 | g.vmuscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#vmu..RLockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RLock().() |
| 136 | defer g.vmuscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#vmu..RUnlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RUnlock().() |
| 137 | |
| 138 | return g.valsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#vals.[g.caseFoldKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#caseFoldKey().(key)] |
| 139 | } |
| 140 | |
| 141 | func (g *GitFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#) Allscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#All().() map[string][]string { |
| 142 | newmap := make(map[string][]string) |
| 143 | |
| 144 | g.vmuscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#vmu..RLockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RLock().() |
| 145 | defer g.vmuscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#vmu..RUnlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RUnlock().() |
| 146 | |
| 147 | for key, values := range g.valsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#vals. { |
| 148 | for _, value := range values { |
| 149 | newmap[key] = append(newmap[key], value) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | return newmap |
| 154 | } |
| 155 | |
| 156 | func (g *GitFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#) caseFoldKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/GitFetcher#caseFoldKey().(key string) string { |
| 157 | parts := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.0 strings/Split().(key, ".") |
| 158 | last := len(parts) - 1 |
| 159 | |
| 160 | // We check for 3 or more parts here because if the middle part is a |
| 161 | // URL, it may have dots in it. We'll downcase the part before the first |
| 162 | // dot and after the last dot, but preserve the piece in the middle, |
| 163 | // which may be a branch name, remote, or URL, all of which are |
| 164 | // case-sensitive. This is the algorithm Git uses to canonicalize its |
| 165 | // keys. |
| 166 | if len(parts) < 3 { |
| 167 | return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(key) |
| 168 | } |
| 169 | |
| 170 | return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.0 strings/Join().([]string{ |
| 171 | stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(parts[0]), |
| 172 | stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.0 strings/Join().(parts[1:last], "."), |
| 173 | stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(parts[last]), |
| 174 | }, ".") |
| 175 | } |
| 176 | |
| 177 | func keyIsUnsafescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/keyIsUnsafe().(key string) bool { |
| 178 | for _, safe := range safeKeysscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/safeKeys. { |
| 179 | if safe == key { |
| 180 | return false |
| 181 | } |
| 182 | } |
| 183 | return true |
| 184 | } |
| 185 | |
| 186 | var safeKeysscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/safeKeys. = []string{ |
| 187 | "lfs.allowincompletepush", |
| 188 | "lfs.fetchexclude", |
| 189 | "lfs.fetchinclude", |
| 190 | "lfs.gitprotocol", |
| 191 | "lfs.locksverify", |
| 192 | "lfs.pushurl", |
| 193 | "lfs.skipdownloaderrors", |
| 194 | "lfs.url", |
| 195 | } |