Check environment variables only once per git-lfs process
Picks up an idea by @technoweenie: https://github.com/github/git-lfs/pull/380#discussion_r32227378
This commit is contained in:
parent
d3b9eaa160
commit
790d2b2306
@ -20,6 +20,7 @@ type Configuration struct {
|
||||
httpClient *http.Client
|
||||
redirectingHttpClient *http.Client
|
||||
isTracingHttp bool
|
||||
envVars map[string]string
|
||||
|
||||
loading sync.Mutex // guards initialization of gitConfig and remotes
|
||||
gitConfig map[string]string
|
||||
@ -41,11 +42,22 @@ var (
|
||||
func NewConfig() *Configuration {
|
||||
c := &Configuration{
|
||||
CurrentRemote: defaultRemote,
|
||||
isTracingHttp: len(os.Getenv("GIT_CURL_VERBOSE")) > 0,
|
||||
envVars: make(map[string]string),
|
||||
}
|
||||
c.isTracingHttp = len(c.Getenv("GIT_CURL_VERBOSE")) > 0
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Configuration) Getenv(key string) string {
|
||||
if i, ok := c.envVars[key]; ok {
|
||||
return i
|
||||
}
|
||||
|
||||
v := os.Getenv(key)
|
||||
c.envVars[key] = v
|
||||
return v
|
||||
}
|
||||
|
||||
func (c *Configuration) Endpoint() Endpoint {
|
||||
if url, ok := c.GitConfig("lfs.url"); ok {
|
||||
return Endpoint{Url: url}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
@ -92,7 +91,7 @@ func init() {
|
||||
}
|
||||
|
||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
if exitErr.ProcessState.Success() == false && os.Getenv("GIT_TERMINAL_PROMPT") == "0" {
|
||||
if exitErr.ProcessState.Success() == false && Config.Getenv("GIT_TERMINAL_PROMPT") == "0" {
|
||||
return nil, fmt.Errorf("Change the GIT_TERMINAL_PROMPT env var to be prompted to enter your credentials for %s://%s.",
|
||||
input["protocol"], input["host"])
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func (c *Configuration) HttpClient() *http.Client {
|
||||
}
|
||||
|
||||
sslVerify, _ := c.GitConfig("http.sslverify")
|
||||
if sslVerify == "false" || len(os.Getenv("GIT_SSL_NO_VERIFY")) > 0 {
|
||||
if sslVerify == "false" || len(Config.Getenv("GIT_SSL_NO_VERIFY")) > 0 {
|
||||
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ func CopyWithCallback(writer io.Writer, reader io.Reader, totalSize int64, cb Co
|
||||
}
|
||||
|
||||
func CopyCallbackFile(event, filename string, index, totalFiles int) (CopyCallback, *os.File, error) {
|
||||
logPath := os.Getenv("GIT_LFS_PROGRESS")
|
||||
logPath := Config.Getenv("GIT_LFS_PROGRESS")
|
||||
if len(logPath) == 0 || len(filename) == 0 || len(event) == 0 {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user