Use commands.Config instead of config.Config

This commit is contained in:
risk danger olson 2016-07-21 15:27:30 -06:00
parent 7baff5624d
commit ed01a95449
12 changed files with 38 additions and 47 deletions

@ -6,7 +6,6 @@ import (
"os/exec"
"sync"
"github.com/github/git-lfs/config"
"github.com/github/git-lfs/errutil"
"github.com/github/git-lfs/git"
"github.com/github/git-lfs/lfs"
@ -119,7 +118,7 @@ func checkoutWithIncludeExclude(include []string, exclude []string) {
for _, pointer := range pointers {
totalBytes += pointer.Size
}
progress := progress.NewProgressMeter(len(pointers), totalBytes, false, config.Config.Getenv("GIT_LFS_PROGRESS"))
progress := progress.NewProgressMeter(len(pointers), totalBytes, false, Config.Getenv("GIT_LFS_PROGRESS"))
progress.Start()
totalBytes = 0
for _, pointer := range pointers {

@ -8,7 +8,6 @@ import (
"github.com/github/git-lfs/subprocess"
"github.com/github/git-lfs/config"
"github.com/github/git-lfs/git"
"github.com/github/git-lfs/localstorage"
"github.com/github/git-lfs/tools"
@ -70,12 +69,12 @@ func cloneCommand(cmd *cobra.Command, args []string) {
// Now just call pull with default args
// Support --origin option to clone
if len(cloneFlags.Origin) > 0 {
config.Config.CurrentRemote = cloneFlags.Origin
Config.CurrentRemote = cloneFlags.Origin
} else {
config.Config.CurrentRemote = "origin"
Config.CurrentRemote = "origin"
}
include, exclude := determineIncludeExcludePaths(config.Config, cloneIncludeArg, cloneExcludeArg)
include, exclude := determineIncludeExcludePaths(Config, cloneIncludeArg, cloneExcludeArg)
if cloneFlags.NoCheckout || cloneFlags.Bare {
// If --no-checkout or --bare then we shouldn't check out, just fetch instead
fetchRef("HEAD", include, exclude)

@ -16,8 +16,7 @@ var (
func envCommand(cmd *cobra.Command, args []string) {
config.ShowConfigWarnings = true
cfg := config.Config
endpoint := cfg.Endpoint("download")
endpoint := Config.Endpoint("download")
gitV, err := git.Config.Version()
if err != nil {
@ -29,15 +28,15 @@ func envCommand(cmd *cobra.Command, args []string) {
Print("")
if len(endpoint.Url) > 0 {
Print("Endpoint=%s (auth=%s)", endpoint.Url, cfg.EndpointAccess(endpoint))
Print("Endpoint=%s (auth=%s)", endpoint.Url, Config.EndpointAccess(endpoint))
if len(endpoint.SshUserAndHost) > 0 {
Print(" SSH=%s:%s", endpoint.SshUserAndHost, endpoint.SshPath)
}
}
for _, remote := range cfg.Remotes() {
remoteEndpoint := cfg.RemoteEndpoint(remote, "download")
Print("Endpoint (%s)=%s (auth=%s)", remote, remoteEndpoint.Url, cfg.EndpointAccess(remoteEndpoint))
for _, remote := range Config.Remotes() {
remoteEndpoint := Config.RemoteEndpoint(remote, "download")
Print("Endpoint (%s)=%s (auth=%s)", remote, remoteEndpoint.Url, Config.EndpointAccess(remoteEndpoint))
if len(remoteEndpoint.SshUserAndHost) > 0 {
Print(" SSH=%s:%s", remoteEndpoint.SshUserAndHost, remoteEndpoint.SshPath)
}
@ -48,7 +47,7 @@ func envCommand(cmd *cobra.Command, args []string) {
}
for _, key := range []string{"filter.lfs.smudge", "filter.lfs.clean"} {
value, _ := cfg.GitConfig(key)
value, _ := Config.GitConfig(key)
Print("git config %s = %q", key, value)
}
}

@ -31,17 +31,14 @@ func extListCommand(cmd *cobra.Command, args []string) {
return
}
cfg := config.Config
for _, key := range args {
ext := cfg.Extensions()[key]
ext := Config.Extensions()[key]
printExt(ext)
}
}
func printAllExts() {
cfg := config.Config
extensions, err := cfg.SortedExtensions()
extensions, err := Config.SortedExtensions()
if err != nil {
fmt.Println(err)
return

@ -4,7 +4,6 @@ import (
"fmt"
"time"
"github.com/github/git-lfs/config"
"github.com/github/git-lfs/git"
"github.com/github/git-lfs/lfs"
"github.com/github/git-lfs/progress"
@ -34,14 +33,14 @@ func fetchCommand(cmd *cobra.Command, args []string) {
if err := git.ValidateRemote(args[0]); err != nil {
Exit("Invalid remote name %q", args[0])
}
config.Config.CurrentRemote = args[0]
Config.CurrentRemote = args[0]
} else {
// Actively find the default remote, don't just assume origin
defaultRemote, err := git.DefaultRemote()
if err != nil {
Exit("No default remote")
}
config.Config.CurrentRemote = defaultRemote
Config.CurrentRemote = defaultRemote
}
if len(args) > 1 {
@ -66,13 +65,13 @@ func fetchCommand(cmd *cobra.Command, args []string) {
if fetchIncludeArg != "" || fetchExcludeArg != "" {
Exit("Cannot combine --all with --include or --exclude")
}
if len(config.Config.FetchIncludePaths()) > 0 || len(config.Config.FetchExcludePaths()) > 0 {
if len(Config.FetchIncludePaths()) > 0 || len(Config.FetchExcludePaths()) > 0 {
Print("Ignoring global include / exclude paths to fulfil --all")
}
success = fetchAll()
} else { // !all
includePaths, excludePaths := determineIncludeExcludePaths(config.Config, fetchIncludeArg, fetchExcludeArg)
includePaths, excludePaths := determineIncludeExcludePaths(Config, fetchIncludeArg, fetchExcludeArg)
// Fetch refs sequentially per arg order; duplicates in later refs will be ignored
for _, ref := range refs {
@ -81,14 +80,14 @@ func fetchCommand(cmd *cobra.Command, args []string) {
success = success && s
}
if fetchRecentArg || config.Config.FetchPruneConfig().FetchRecentAlways {
if fetchRecentArg || Config.FetchPruneConfig().FetchRecentAlways {
s := fetchRecent(refs, includePaths, excludePaths)
success = success && s
}
}
if fetchPruneArg {
verify := config.Config.FetchPruneConfig().PruneVerifyRemoteAlways
verify := Config.FetchPruneConfig().PruneVerifyRemoteAlways
// no dry-run or verbose options in fetch, assume false
prune(verify, false, false)
}
@ -148,7 +147,7 @@ func fetchPreviousVersions(ref string, since time.Time, include, exclude []strin
// Fetch recent objects based on config
func fetchRecent(alreadyFetchedRefs []*git.Ref, include, exclude []string) bool {
fetchconf := config.Config.FetchPruneConfig()
fetchconf := Config.FetchPruneConfig()
if fetchconf.FetchRecentRefsDays == 0 && fetchconf.FetchRecentCommitsDays == 0 {
return true
@ -164,7 +163,7 @@ func fetchRecent(alreadyFetchedRefs []*git.Ref, include, exclude []string) bool
if fetchconf.FetchRecentRefsDays > 0 {
Print("Fetching recent branches within %v days", fetchconf.FetchRecentRefsDays)
refsSince := time.Now().AddDate(0, 0, -fetchconf.FetchRecentRefsDays)
refs, err := git.RecentBranches(refsSince, fetchconf.FetchRecentRefsIncludeRemotes, config.Config.CurrentRemote)
refs, err := git.RecentBranches(refsSince, fetchconf.FetchRecentRefsIncludeRemotes, Config.CurrentRemote)
if err != nil {
Panic(err, "Could not scan for recent refs")
}

@ -30,7 +30,7 @@ var (
)
func lockCommand(cmd *cobra.Command, args []string) {
setLockRemoteFor(config.Config)
setLockRemoteFor(Config)
if len(args) == 0 {
Print("Usage: git lfs lock <path>")
@ -107,9 +107,9 @@ func lockPath(file string) (string, error) {
}
func init() {
lockCmd.Flags().StringVarP(&lockRemote, "remote", "r", config.Config.CurrentRemote, lockRemoteHelp)
lockCmd.Flags().StringVarP(&lockRemote, "remote", "r", Config.CurrentRemote, lockRemoteHelp)
if isCommandEnabled(config.Config, "locks") {
if isCommandEnabled(Config, "locks") {
RootCmd.AddCommand(lockCmd)
}
}

@ -2,7 +2,6 @@ package commands
import (
"github.com/github/git-lfs/api"
"github.com/github/git-lfs/config"
"github.com/spf13/cobra"
)
@ -15,7 +14,7 @@ var (
)
func locksCommand(cmd *cobra.Command, args []string) {
setLockRemoteFor(config.Config)
setLockRemoteFor(Config)
filters, err := locksCmdFlags.Filters()
if err != nil {
@ -57,13 +56,13 @@ func locksCommand(cmd *cobra.Command, args []string) {
}
func init() {
locksCmd.Flags().StringVarP(&lockRemote, "remote", "r", config.Config.CurrentRemote, lockRemoteHelp)
locksCmd.Flags().StringVarP(&lockRemote, "remote", "r", Config.CurrentRemote, lockRemoteHelp)
locksCmd.Flags().StringVarP(&locksCmdFlags.Path, "path", "p", "", "filter locks results matching a particular path")
locksCmd.Flags().StringVarP(&locksCmdFlags.Id, "id", "i", "", "filter locks results matching a particular ID")
locksCmd.Flags().IntVarP(&locksCmdFlags.Limit, "limit", "l", 0, "optional limit for number of results to return")
if isCommandEnabled(config.Config, "locks") {
if isCommandEnabled(Config, "locks") {
RootCmd.AddCommand(locksCmd)
}
}

@ -5,7 +5,6 @@ import (
"os"
"strings"
"github.com/github/git-lfs/config"
"github.com/github/git-lfs/git"
"github.com/github/git-lfs/lfs"
"github.com/spf13/cobra"
@ -53,12 +52,12 @@ func prePushCommand(cmd *cobra.Command, args []string) {
Exit("Invalid remote name %q", args[0])
}
config.Config.CurrentRemote = args[0]
Config.CurrentRemote = args[0]
ctx := newUploadContext(prePushDryRun)
scanOpt := lfs.NewScanRefsOptions()
scanOpt.ScanMode = lfs.ScanLeftToRemoteMode
scanOpt.RemoteName = config.Config.CurrentRemote
scanOpt.RemoteName = Config.CurrentRemote
// We can be passed multiple lines of refs
scanner := bufio.NewScanner(os.Stdin)

@ -37,7 +37,7 @@ func pruneCommand(cmd *cobra.Command, args []string) {
}
verify := !pruneDoNotVerifyArg &&
(config.Config.FetchPruneConfig().PruneVerifyRemoteAlways || pruneVerifyArg)
(Config.FetchPruneConfig().PruneVerifyRemoteAlways || pruneVerifyArg)
prune(verify, pruneDryRunArg, pruneVerboseArg)
@ -123,7 +123,7 @@ func prune(verifyRemote, dryRun, verbose bool) {
var verifyc chan string
if verifyRemote {
config.Config.CurrentRemote = config.Config.FetchPruneConfig().PruneRemoteName
Config.CurrentRemote = Config.FetchPruneConfig().PruneRemoteName
// build queue now, no estimates or progress output
verifyQueue = lfs.NewDownloadCheckQueue(0, 0)
verifiedObjects = tools.NewStringSetWithCapacity(len(localObjects) / 2)
@ -365,7 +365,7 @@ func pruneTaskGetRetainedCurrentAndRecentRefs(retainChan chan string, errorChan
go pruneTaskGetRetainedAtRef(ref.Sha, retainChan, errorChan, waitg)
// Now recent
fetchconf := config.Config.FetchPruneConfig()
fetchconf := Config.FetchPruneConfig()
if fetchconf.FetchRecentRefsDays > 0 {
pruneRefDays := fetchconf.FetchRecentRefsDays + fetchconf.PruneOffsetDays
tracerx.Printf("PRUNE: Retaining non-HEAD refs within %d (%d+%d) days", pruneRefDays, fetchconf.FetchRecentRefsDays, fetchconf.PruneOffsetDays)
@ -406,7 +406,7 @@ func pruneTaskGetRetainedCurrentAndRecentRefs(retainChan chan string, errorChan
func pruneTaskGetRetainedUnpushed(retainChan chan string, errorChan chan error, waitg *sync.WaitGroup) {
defer waitg.Done()
remoteName := config.Config.FetchPruneConfig().PruneRemoteName
remoteName := Config.FetchPruneConfig().PruneRemoteName
refchan, err := lfs.ScanUnpushedToChan(remoteName)
if err != nil {

@ -35,7 +35,7 @@ func pullCommand(cmd *cobra.Command, args []string) {
config.Config.CurrentRemote = defaultRemote
}
pull(determineIncludeExcludePaths(config.Config, pullIncludeArg, pullExcludeArg))
pull(determineIncludeExcludePaths(Config, pullIncludeArg, pullExcludeArg))
}

@ -4,7 +4,6 @@ import (
"io/ioutil"
"os"
"github.com/github/git-lfs/config"
"github.com/github/git-lfs/git"
"github.com/github/git-lfs/lfs"
"github.com/rubyist/tracerx"
@ -29,7 +28,7 @@ func uploadsBetweenRefs(ctx *uploadContext, left string, right string) {
scanOpt := lfs.NewScanRefsOptions()
scanOpt.ScanMode = lfs.ScanRefsMode
scanOpt.RemoteName = config.Config.CurrentRemote
scanOpt.RemoteName = Config.CurrentRemote
pointers, err := lfs.ScanRefs(left, right, scanOpt)
if err != nil {
@ -40,11 +39,11 @@ func uploadsBetweenRefs(ctx *uploadContext, left string, right string) {
}
func uploadsBetweenRefAndRemote(ctx *uploadContext, refnames []string) {
tracerx.Printf("Upload refs %v to remote %v", refnames, config.Config.CurrentRemote)
tracerx.Printf("Upload refs %v to remote %v", refnames, Config.CurrentRemote)
scanOpt := lfs.NewScanRefsOptions()
scanOpt.ScanMode = lfs.ScanLeftToRemoteMode
scanOpt.RemoteName = config.Config.CurrentRemote
scanOpt.RemoteName = Config.CurrentRemote
if pushAll {
scanOpt.ScanMode = lfs.ScanRefsMode
@ -123,7 +122,7 @@ func pushCommand(cmd *cobra.Command, args []string) {
Exit("Invalid remote name %q", args[0])
}
config.Config.CurrentRemote = args[0]
Config.CurrentRemote = args[0]
ctx := newUploadContext(pushDryRun)
if useStdin {

@ -40,6 +40,7 @@ var (
},
}
ManPages = make(map[string]string, 20)
Config = config.Config
)
// Error prints a formatted message to Stderr. It also gets printed to the