From 0e679c7d98a99613c31fd399aa3c70f3a85f791e Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Wed, 9 Nov 2016 17:46:52 -0700 Subject: [PATCH] add Set(), remove .gitConfig --- config/config.go | 15 +++------------ config/environment.go | 5 +++++ config/fetcher.go | 2 ++ config/git_environment.go | 7 ++++++- config/git_fetcher.go | 6 ++++++ config/map_fetcher.go | 4 ++++ config/os_fetcher.go | 2 ++ 7 files changed, 28 insertions(+), 13 deletions(-) diff --git a/config/config.go b/config/config.go index 5661f00f..95b05f7d 100644 --- a/config/config.go +++ b/config/config.go @@ -57,8 +57,6 @@ type Configuration struct { // configuration. Git Environment - gitConfig map[string]string - CurrentRemote string NtlmSession ntlm.ClientSession envVars map[string]string @@ -106,9 +104,8 @@ type Values struct { // This method should only be used during testing. func NewFrom(v Values) *Configuration { return &Configuration{ - Os: EnvironmentOf(mapFetcher(v.Os)), - Git: EnvironmentOf(mapFetcher(v.Git)), - gitConfig: v.Git, + Os: EnvironmentOf(mapFetcher(v.Os)), + Git: EnvironmentOf(mapFetcher(v.Git)), envVars: make(map[string]string, 0), } @@ -349,16 +346,10 @@ func (c *Configuration) SetEndpointAccess(e Endpoint, authType string) { switch authType { case "", "none": git.Config.UnsetLocalKey("", key) - - c.loading.Lock() c.Git.Del(key) - c.loading.Unlock() default: git.Config.SetLocal("", key, authType) - - c.loading.Lock() - c.gitConfig[strings.ToLower(key)] = authType - c.loading.Unlock() + c.Git.Set(key, authType) } } diff --git a/config/environment.go b/config/environment.go index 379a609b..c31f8267 100644 --- a/config/environment.go +++ b/config/environment.go @@ -39,6 +39,7 @@ type Environment interface { Int(key string, def int) (val int) All() map[string]string + Set(key, value string) Del(key string) } @@ -91,6 +92,10 @@ func (e *environment) All() map[string]string { return e.Fetcher.All() } +func (e *environment) Set(key, value string) { + e.Fetcher.Set(key, value) +} + func (e *environment) Del(key string) { e.Fetcher.Del(key) } diff --git a/config/fetcher.go b/config/fetcher.go index 2584ef07..ca7eed36 100644 --- a/config/fetcher.go +++ b/config/fetcher.go @@ -8,6 +8,8 @@ type Fetcher interface { // determining if the key exists. Get(key string) (val string, ok bool) + Set(key, value string) + All() map[string]string Del(key string) diff --git a/config/git_environment.go b/config/git_environment.go index cbdd7870..4cc04ec0 100644 --- a/config/git_environment.go +++ b/config/git_environment.go @@ -43,6 +43,12 @@ func (g *gitEnvironment) All() map[string]string { return g.git.All() } +func (g *gitEnvironment) Set(key, value string) { + g.loadGitConfig() + + g.git.Set(key, value) +} + func (g *gitEnvironment) Del(key string) { g.loadGitConfig() @@ -68,7 +74,6 @@ func (g *gitEnvironment) loadGitConfig() bool { g.git = EnvironmentOf(gf) - g.config.gitConfig = gf.vals // XXX TERRIBLE g.config.extensions = extensions g.config.remotes = make([]string, 0, len(uniqRemotes)) diff --git a/config/git_fetcher.go b/config/git_fetcher.go index 2158404b..e5b00997 100644 --- a/config/git_fetcher.go +++ b/config/git_fetcher.go @@ -139,6 +139,12 @@ func (g *GitFetcher) All() map[string]string { return newmap } +func (g *GitFetcher) Set(key, value string) { + g.vmu.RLock() + defer g.vmu.RUnlock() + g.vals[strings.ToLower(key)] = value +} + func (g *GitFetcher) Del(key string) { g.vmu.RLock() defer g.vmu.RUnlock() diff --git a/config/map_fetcher.go b/config/map_fetcher.go index 9908e438..eff2c021 100644 --- a/config/map_fetcher.go +++ b/config/map_fetcher.go @@ -22,6 +22,10 @@ func (m mapFetcher) All() map[string]string { return newmap } +func (m mapFetcher) Set(key, value string) { + m[key] = value +} + func (m mapFetcher) Del(key string) { delete(m, key) } diff --git a/config/os_fetcher.go b/config/os_fetcher.go index 6b91af6d..f3f87472 100644 --- a/config/os_fetcher.go +++ b/config/os_fetcher.go @@ -58,4 +58,6 @@ func (o *OsFetcher) All() map[string]string { return nil } +func (o *OsFetcher) Set(key, value string) {} + func (o *OsFetcher) Del(key string) {}