config

package
v2.2.2-example+incompa... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2017 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package config collects together all configuration settings NOTE: Subject to change, do not rely on this package from outside git-lfs source

Index

Constants

View Source
const (
	Version = "2.3.0-pre"
)

Variables

View Source
var (
	Config             = New()
	ShowConfigWarnings = false
)
View Source
var (
	LocalWorkingDir    string
	LocalGitDir        string // parent of index / config / hooks etc
	LocalGitStorageDir string // parent of objects/lfs (may be same as LocalGitDir but may not)
	LocalReferenceDir  string // alternative local media dir (relative to clone reference repo)
	LocalLogDir        string
)
View Source
var (
	GitCommit   string
	VersionDesc string
)

Functions

func ResolveGitBasicDirs

func ResolveGitBasicDirs()

Determins the LocalWorkingDir, LocalGitDir etc

Types

type Configuration

type Configuration struct {
	// Os provides a `*Environment` used to access to the system's
	// environment through os.Getenv. It is the point of entry for all
	// system environment configuration.
	Os Environment

	// Git provides a `*Environment` used to access to the various levels of
	// `.gitconfig`'s. It is the point of entry for all Git environment
	// configuration.
	Git Environment

	CurrentRemote string
	// contains filtered or unexported fields
}

func New added in v1.3.1

func New() *Configuration

func NewFrom added in v1.4.0

func NewFrom(v Values) *Configuration

NewFrom returns a new `*config.Configuration` that reads both its Git and Enviornment-level values from the ones provided instead of the actual `.gitconfig` file or `os.Getenv`, respectively.

This method should only be used during testing.

func (*Configuration) BasicTransfersOnly

func (c *Configuration) BasicTransfersOnly() bool

BasicTransfersOnly returns whether to only allow "basic" HTTP transfers. Default is false, including if the lfs.basictransfersonly is invalid

func (*Configuration) CurrentCommitter

func (c *Configuration) CurrentCommitter() (name, email string)

CurrentCommitter returns the name/email that would be used to author a commit with this configuration. In particular, the "user.name" and "user.email" configuration values are used

func (*Configuration) Extensions

func (c *Configuration) Extensions() map[string]Extension

func (*Configuration) FetchExcludePaths

func (c *Configuration) FetchExcludePaths() []string

func (*Configuration) FetchIncludePaths

func (c *Configuration) FetchIncludePaths() []string

func (*Configuration) FetchPruneConfig

func (c *Configuration) FetchPruneConfig() FetchPruneConfig

func (*Configuration) Remotes

func (c *Configuration) Remotes() []string

func (*Configuration) SetLockableFilesReadOnly

func (c *Configuration) SetLockableFilesReadOnly() bool

func (*Configuration) SkipDownloadErrors

func (c *Configuration) SkipDownloadErrors() bool

func (*Configuration) SortedExtensions

func (c *Configuration) SortedExtensions() ([]Extension, error)

SortedExtensions gets the list of extensions ordered by Priority

func (*Configuration) StorageConfig

func (c *Configuration) StorageConfig() StorageConfig

func (*Configuration) TusTransfersAllowed

func (c *Configuration) TusTransfersAllowed() bool

TusTransfersAllowed returns whether to only use "tus.io" HTTP transfers. Default is false, including if the lfs.tustransfers is invalid

func (*Configuration) Unmarshal added in v1.4.0

func (c *Configuration) Unmarshal(v interface{}) error

Unmarshal unmarshals the *Configuration in context into all of `v`'s fields, according to the following rules:

Values are marshaled according to the given key and environment, as follows:

type T struct {
	Field string `git:"key"`
	Other string `os:"key"`
}

If an unknown environment is given, an error will be returned. If there is no method supporting conversion into a field's type, an error will be returned. If no value is associated with the given key and environment, the field will // only be modified if there is a config value present matching the given key. If the field is already set to a non-zero value of that field's type, then it will be left alone.

Otherwise, the field will be set to the value of calling the appropriately-typed method on the specified environment.

type Environment added in v1.4.0

type Environment interface {
	// Get is shorthand for calling `e.Fetcher.Get(key)`.
	Get(key string) (val string, ok bool)

	// Get is shorthand for calling `e.Fetcher.GetAll(key)`.
	GetAll(key string) (vals []string)

	// Bool returns the boolean state associated with a given key, or the
	// value "def", if no value was associated.
	//
	// The "boolean state associated with a given key" is defined as the
	// case-insensitive string comparison with the following:
	//
	// 1) true if...
	//   "true", "1", "on", "yes", or "t"
	// 2) false if...
	//   "false", "0", "off", "no", "f", or otherwise.
	Bool(key string, def bool) (val bool)

	// Int returns the int value associated with a given key, or the value
	// "def", if no value was associated.
	//
	// To convert from a the string value attached to a given key,
	// `strconv.Atoi(val)` is called. If `Atoi` returned a non-nil error,
	// then the value "def" will be returned instead.
	//
	// Otherwise, if the value was converted `string -> int` successfully,
	// then it will be returned wholesale.
	Int(key string, def int) (val int)

	// All returns a copy of all the key/value pairs for the current
	// environment.
	All() map[string][]string
}

An Environment adds additional behavior to a Fetcher, such a type conversion, and default values.

`Environment`s are the primary way to communicate with various configuration sources, such as the OS environment variables, the `.gitconfig`, and even `map[string]string`s.

func EnvironmentOf added in v1.4.0

func EnvironmentOf(f Fetcher) Environment

EnvironmentOf creates a new `Environment` initialized with the givne `Fetcher`, "f".

type Extension

type Extension struct {
	Name     string
	Clean    string
	Smudge   string
	Priority int
}

An Extension describes how to manipulate files during smudge and clean. Extensions are parsed from the Git config.

func SortExtensions

func SortExtensions(m map[string]Extension) ([]Extension, error)

SortExtensions sorts a map of extensions in ascending order by Priority

type FetchPruneConfig

type FetchPruneConfig struct {
	// The number of days prior to current date for which (local) refs other than HEAD
	// will be fetched with --recent (default 7, 0 = only fetch HEAD)
	FetchRecentRefsDays int `git:"lfs.fetchrecentrefsdays"`
	// Makes the FetchRecentRefsDays option apply to remote refs from fetch source as well (default true)
	FetchRecentRefsIncludeRemotes bool `git:"lfs.fetchrecentremoterefs"`
	// number of days prior to latest commit on a ref that we'll fetch previous
	// LFS changes too (default 0 = only fetch at ref)
	FetchRecentCommitsDays int `git:"lfs.fetchrecentcommitsdays"`
	// Whether to always fetch recent even without --recent
	FetchRecentAlways bool `git:"lfs.fetchrecentalways"`
	// Number of days added to FetchRecent*; data outside combined window will be
	// deleted when prune is run. (default 3)
	PruneOffsetDays int `git:"lfs.pruneoffsetdays"`
	// Always verify with remote before pruning
	PruneVerifyRemoteAlways bool `git:"lfs.pruneverifyremotealways"`
	// Name of remote to check for unpushed and verify checks
	PruneRemoteName string `git:"lfs.pruneremotetocheck"`
}

FetchPruneConfig collects together the config options that control fetching and pruning

type Fetcher added in v1.4.0

type Fetcher interface {
	// Get returns the string value associated with a given key and a bool
	// determining if the key exists.
	//
	// If multiple entries match the given key, the first one will be
	// returned.
	Get(key string) (val string, ok bool)

	// GetAll returns the a set of string values associated with a given
	// key. If no entries matched the given key, an empty slice will be
	// returned instead.
	GetAll(key string) (vals []string)

	// All returns a copy of all the key/value pairs for the current
	// environment.
	All() map[string][]string
}

Fetcher provides an interface to get typed information out of a configuration "source". These sources could be the OS enviornment, a .gitconfig, or even just a `map`.

func MapFetcher added in v1.4.0

func MapFetcher(m map[string][]string) Fetcher

func UniqMapFetcher

func UniqMapFetcher(m map[string]string) Fetcher

type GitConfig added in v1.4.0

type GitConfig struct {
	Lines        []string
	OnlySafeKeys bool
}

func NewGitConfig added in v1.4.0

func NewGitConfig(gitconfiglines string, onlysafe bool) *GitConfig

type GitFetcher added in v1.4.0

type GitFetcher struct {
	// contains filtered or unexported fields
}

func ReadGitConfig added in v1.4.0

func ReadGitConfig(configs ...*GitConfig) (gf *GitFetcher, extensions map[string]Extension, uniqRemotes map[string]bool)

func (*GitFetcher) All added in v1.5.0

func (g *GitFetcher) All() map[string][]string

func (*GitFetcher) Get added in v1.4.0

func (g *GitFetcher) Get(key string) (val string, ok bool)

Get implements the Fetcher interface, and returns the value associated with a given key and true, signaling that the value was present. Otherwise, an empty string and false will be returned, signaling that the value was absent.

Map lookup by key is case-insensitive, as per the .gitconfig specification.

Get is safe to call across multiple goroutines.

func (*GitFetcher) GetAll

func (g *GitFetcher) GetAll(key string) []string

type OsFetcher added in v1.4.0

type OsFetcher struct {
	// contains filtered or unexported fields
}

OsFetcher is an implementation of the Fetcher type for communicating with the system's environment.

It is safe to use across multiple goroutines.

func NewOsFetcher added in v1.4.0

func NewOsFetcher() *OsFetcher

NewOsFetcher returns a new *OsFetcher.

func (*OsFetcher) All added in v1.5.0

func (o *OsFetcher) All() map[string][]string

func (*OsFetcher) Get added in v1.4.0

func (o *OsFetcher) Get(key string) (val string, ok bool)

Get returns the value associated with the given key as stored in the local cache, or in the operating system's environment variables.

If there was a cache-hit, the value will be returned from the cache, skipping a check against os.Getenv. Otherwise, the value will be fetched from the system, stored in the cache, and then returned. If no value was present in the cache or in the system, an empty string will be returned.

Get is safe to call across multiple goroutines.

func (*OsFetcher) GetAll

func (o *OsFetcher) GetAll(key string) []string

GetAll implements the `config.Fetcher.GetAll` method by returning, at most, a 1-ary set containing the result of `config.OsFetcher.Get()`.

type StorageConfig

type StorageConfig struct {
	LfsStorageDir string `git:"lfs.storage"`
}

Storage configuration

type URLConfig

type URLConfig struct {
	// contains filtered or unexported fields
}

func NewURLConfig

func NewURLConfig(git Environment) *URLConfig

func (*URLConfig) Get

func (c *URLConfig) Get(prefix, rawurl, key string) (string, bool)

Get retrieves a `http.{url}.{key}` for the given key and urls, following the rules in https://git-scm.com/docs/git-config#git-config-httplturlgt. The value for `http.{key}` is returned as a fallback if no config keys are set for the given urls.

func (*URLConfig) GetAll

func (c *URLConfig) GetAll(prefix, rawurl, key string) []string

type Values added in v1.4.0

type Values struct {
	// Git and Os are the stand-in maps used to provide values for their
	// respective environments.
	Git, Os map[string][]string
}

Values is a convenience type used to call the NewFromValues function. It specifies `Git` and `Env` maps to use as mock values, instead of calling out to real `.gitconfig`s and the `os.Getenv` function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL