Commit Graph

11 Commits

Author SHA1 Message Date
Taylor Blau
34d590c52f config,lfsapi: return last element of gitconfig, not first 2017-04-14 13:33:13 -04:00
Taylor Blau
552b955b3f all: expand config.Environment interface to support multiple values per key 2017-04-12 17:29:11 -04:00
risk danger olson
2e213cf9c4 config: remove env mutation funcs, no longer needed! 2017-01-10 13:25:03 -07:00
risk danger olson
b694d64f12 make set() and del() private 2016-11-10 11:16:46 -07:00
risk danger olson
0e679c7d98 add Set(), remove .gitConfig 2016-11-09 17:46:52 -07:00
risk danger olson
e2ca1e5533 add Environment Del(key string) 2016-11-09 17:37:14 -07:00
risk danger olson
9c46443baf remove AllGitConfig() 2016-11-09 17:33:43 -07:00
risk danger olson
9c727d210c change (Environment) Get()'s signature to include ok bool 2016-08-05 15:59:57 -06:00
Taylor Blau
38c452b283 config: remove MockFetcher in tests 2016-08-04 18:58:43 -06:00
Taylor Blau
18cb9257f9 config: demote Fetcher, introduce Environment
Previously, to fetch data out of the `*config.Configuration` type, a reference
to a `Fetcher` was used, a-la:

```
cfg.Env.Get(...)
```

This is quite convenient, however, it forces the LFS client to implement
several methods more than once. Consider the interface:

```
type Fetcher interface {
        Get(key string) (val string)

        Bool(key string, def bool) (val bool)
        // et. al.
}
```

In order to return typed information from a configuration instance, _each_
`Fetcher` must implement its own `N` methods for `Int`, `Bool`, etc.

To remedy this, the `Environment` type was introduced. It instead _has_ a
`Fetcher`, and defines its own type conversions, like so:

```
type Environment struct {
        f Fetcher
}

func (e *Environment) Bool(key string, def bool) (val bool) { }
func (e *Environment) Int(key string, def int)   (val int) { }

// et. al.
```

Now, the `config.Configuration` type holds a reference to an `Environment`, and
all type conversion methods are defined only once, saving time, and enforcing
consistency across multiple sources.
2016-08-04 14:28:19 -06:00
Taylor Blau
8ca4fcbade config: eradicate uses of SetAllEnv
The `SetAllEnv` function is one of two functions that allow for mutable
behavior within the `*config.Configuration` type. It is desirable for us to
remove that function, and all of its uses throughout the LFS codebase.

Unfortunately, a lot of `SetAllEnv` uses are coupled to initializing the
`config.Configuration` instance with custom `.gitconfig` data, a-la
`NewFromValues`. This coupling makes it difficult to write an atomic commit
that *only* removes the usage of `SetAllEnv`.

As a compromise, the signature of `NewFromValues` changed from:

```
func NewFromValues(gitconfig map[string]strimg) *Configuration
```

to...

```
type Values struct {
  Git, Env map[string]string
}

func NewFrom(v Values) *Configuration
```

To support reading fixed data as a part of the `Env` fetcher, a new Fetcher
type was introduced:

```
type mapFetcher map[string]string

func (m mapFetcher) Get(key string) (val string) { ... }
```

and is used in place of the old `*EnvFetcher` to retrieve data from the
"environment".
2016-08-03 17:55:39 -06:00