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:
Michael Käufl 2015-06-14 01:13:58 +02:00
parent d3b9eaa160
commit 790d2b2306
4 changed files with 16 additions and 5 deletions

@ -20,6 +20,7 @@ type Configuration struct {
httpClient *http.Client httpClient *http.Client
redirectingHttpClient *http.Client redirectingHttpClient *http.Client
isTracingHttp bool isTracingHttp bool
envVars map[string]string
loading sync.Mutex // guards initialization of gitConfig and remotes loading sync.Mutex // guards initialization of gitConfig and remotes
gitConfig map[string]string gitConfig map[string]string
@ -41,11 +42,22 @@ var (
func NewConfig() *Configuration { func NewConfig() *Configuration {
c := &Configuration{ c := &Configuration{
CurrentRemote: defaultRemote, 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 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 { func (c *Configuration) Endpoint() Endpoint {
if url, ok := c.GitConfig("lfs.url"); ok { if url, ok := c.GitConfig("lfs.url"); ok {
return Endpoint{Url: url} return Endpoint{Url: url}

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"net/url" "net/url"
"os"
"os/exec" "os/exec"
"strings" "strings"
) )
@ -92,7 +91,7 @@ func init() {
} }
if exitErr, ok := err.(*exec.ExitError); ok { 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.", 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"]) input["protocol"], input["host"])
} }

@ -39,7 +39,7 @@ func (c *Configuration) HttpClient() *http.Client {
} }
sslVerify, _ := c.GitConfig("http.sslverify") 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} 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) { 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 { if len(logPath) == 0 || len(filename) == 0 || len(event) == 0 {
return nil, nil, nil return nil, nil, nil
} }