From 254c11d179c323a7c2d643c88d2811ff5ad6b5b3 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Wed, 10 Aug 2016 14:23:03 -0600 Subject: [PATCH] config.etc: remove Getenv utility method --- auth/ssh.go | 5 +++-- commands/command_checkout.go | 4 +++- config/config.go | 6 ------ config/config_netrc.go | 2 +- httputil/certs.go | 4 ++-- httputil/proxy.go | 12 ++++++------ lfs/transfer_queue.go | 4 +++- lfs/util.go | 2 +- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/auth/ssh.go b/auth/ssh.go index 30b27220..be3b0a4b 100644 --- a/auth/ssh.go +++ b/auth/ssh.go @@ -69,8 +69,9 @@ func sshGetExeAndArgs(cfg *config.Configuration, endpoint config.Endpoint) (exe isPlink := false isTortoise := false - ssh := cfg.Getenv("GIT_SSH") - cmdArgs := strings.Fields(cfg.Getenv("GIT_SSH_COMMAND")) + ssh, _ := cfg.Os.Get("GIT_SSH") + sshCmd, _ := cfg.Os.Get("GIT_SSH_COMMAND") + cmdArgs := strings.Fields(sshCmd) if len(cmdArgs) > 0 { ssh = cmdArgs[0] cmdArgs = cmdArgs[1:] diff --git a/commands/command_checkout.go b/commands/command_checkout.go index b6113820..048c5763 100644 --- a/commands/command_checkout.go +++ b/commands/command_checkout.go @@ -120,7 +120,9 @@ func checkoutWithIncludeExclude(include []string, exclude []string) { for _, pointer := range pointers { totalBytes += pointer.Size } - progress := progress.NewProgressMeter(len(pointers), totalBytes, false, cfg.Getenv("GIT_LFS_PROGRESS")) + + logPath, _ := cfg.Os.Get("GIT_LFS_PROGRESS") + progress := progress.NewProgressMeter(len(pointers), totalBytes, false, logPath) progress.Start() totalBytes = 0 for _, pointer := range pointers { diff --git a/config/config.go b/config/config.go index 0932bbf1..05ed0a36 100644 --- a/config/config.go +++ b/config/config.go @@ -202,12 +202,6 @@ func (c *Configuration) parseTag(tag reflect.StructTag) (key string, env *Enviro return } -// Getenv is shorthand for `c.Os.Get(key)`. -func (c *Configuration) Getenv(key string) string { - v, _ := c.Os.Get(key) - return v -} - // GitRemoteUrl returns the git clone/push url for a given remote (blank if not found) // the forpush argument is to cater for separate remote.name.pushurl settings func (c *Configuration) GitRemoteUrl(remote string, forpush bool) string { diff --git a/config/config_netrc.go b/config/config_netrc.go index 4c3ff19b..27156459 100644 --- a/config/config_netrc.go +++ b/config/config_netrc.go @@ -18,7 +18,7 @@ func (n *noNetrc) FindMachine(host string) *netrc.Machine { } func (c *Configuration) parseNetrc() (netrcfinder, error) { - home := c.Getenv("HOME") + home, _ := c.Os.Get("HOME") if len(home) == 0 { return &noNetrc{}, nil } diff --git a/httputil/certs.go b/httputil/certs.go index dc1dd675..ad3f5df6 100644 --- a/httputil/certs.go +++ b/httputil/certs.go @@ -48,7 +48,7 @@ func appendRootCAsForHostFromGitconfig(cfg *config.Configuration, pool *x509.Cer // Accumulate certs from all these locations: // GIT_SSL_CAINFO first - if cafile := cfg.Getenv("GIT_SSL_CAINFO"); len(cafile) > 0 { + if cafile, _ := cfg.Os.Get("GIT_SSL_CAINFO"); len(cafile) > 0 { return appendCertsFromFile(pool, cafile) } // http./.sslcainfo or http..sslcainfo @@ -66,7 +66,7 @@ func appendRootCAsForHostFromGitconfig(cfg *config.Configuration, pool *x509.Cer return appendCertsFromFile(pool, cafile) } // GIT_SSL_CAPATH - if cadir := cfg.Getenv("GIT_SSL_CAPATH"); len(cadir) > 0 { + if cadir, _ := cfg.Os.Get("GIT_SSL_CAPATH"); len(cadir) > 0 { return appendCertsFromFilesInDir(pool, cadir) } // http.sslcapath diff --git a/httputil/proxy.go b/httputil/proxy.go index 54315700..e717195d 100644 --- a/httputil/proxy.go +++ b/httputil/proxy.go @@ -20,24 +20,24 @@ func ProxyFromGitConfigOrEnvironment(c *config.Configuration) func(req *http.Req } if len(https_proxy) == 0 { - https_proxy = c.Getenv("HTTPS_PROXY") + https_proxy, _ = c.Os.Get("HTTPS_PROXY") } if len(https_proxy) == 0 { - https_proxy = c.Getenv("https_proxy") + https_proxy, _ = c.Os.Get("https_proxy") } if len(http_proxy) == 0 { - http_proxy = c.Getenv("HTTP_PROXY") + http_proxy, _ = c.Os.Get("HTTP_PROXY") } if len(http_proxy) == 0 { - http_proxy = c.Getenv("http_proxy") + http_proxy, _ = c.Os.Get("http_proxy") } - no_proxy := c.Getenv("NO_PROXY") + no_proxy, _ := c.Os.Get("NO_PROXY") if len(no_proxy) == 0 { - no_proxy = c.Getenv("no_proxy") + no_proxy, _ = c.Os.Get("no_proxy") } return func(req *http.Request) (*url.URL, error) { diff --git a/lfs/transfer_queue.go b/lfs/transfer_queue.go index 2aca6979..0cd98937 100644 --- a/lfs/transfer_queue.go +++ b/lfs/transfer_queue.go @@ -58,10 +58,12 @@ type TransferQueue struct { // newTransferQueue builds a TransferQueue, direction and underlying mechanism determined by adapter func newTransferQueue(files int, size int64, dryRun bool, dir transfer.Direction) *TransferQueue { + logPath, _ := config.Config.Os.Get("GIT_LFS_PROGRESS") + q := &TransferQueue{ direction: dir, dryRun: dryRun, - meter: progress.NewProgressMeter(files, size, dryRun, config.Config.Getenv("GIT_LFS_PROGRESS")), + meter: progress.NewProgressMeter(files, size, dryRun, logPath), apic: make(chan Transferable, batchSize), retriesc: make(chan Transferable, batchSize), errorc: make(chan error), diff --git a/lfs/util.go b/lfs/util.go index 64300007..123f5e15 100644 --- a/lfs/util.go +++ b/lfs/util.go @@ -27,7 +27,7 @@ const ( var currentPlatform = PlatformUndetermined func CopyCallbackFile(event, filename string, index, totalFiles int) (progress.CopyCallback, *os.File, error) { - logPath := config.Config.Getenv("GIT_LFS_PROGRESS") + logPath, _ := config.Config.Os.Get("GIT_LFS_PROGRESS") if len(logPath) == 0 || len(filename) == 0 || len(event) == 0 { return nil, nil, nil }