From ed01a95449cb8b018f01cd86ec7644c7773b9ceb Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Thu, 21 Jul 2016 15:27:30 -0600 Subject: [PATCH] Use commands.Config instead of config.Config --- commands/command_checkout.go | 3 +-- commands/command_clone.go | 7 +++---- commands/command_env.go | 13 ++++++------- commands/command_ext.go | 7 ++----- commands/command_fetch.go | 17 ++++++++--------- commands/command_lock.go | 6 +++--- commands/command_locks.go | 7 +++---- commands/command_pre_push.go | 5 ++--- commands/command_prune.go | 8 ++++---- commands/command_pull.go | 2 +- commands/command_push.go | 9 ++++----- commands/commands.go | 1 + 12 files changed, 38 insertions(+), 47 deletions(-) diff --git a/commands/command_checkout.go b/commands/command_checkout.go index dfa9e445..3b715e33 100644 --- a/commands/command_checkout.go +++ b/commands/command_checkout.go @@ -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 { diff --git a/commands/command_clone.go b/commands/command_clone.go index 88e67cc5..76e904b9 100644 --- a/commands/command_clone.go +++ b/commands/command_clone.go @@ -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) diff --git a/commands/command_env.go b/commands/command_env.go index 1d512ea2..dabdcc2f 100644 --- a/commands/command_env.go +++ b/commands/command_env.go @@ -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) } } diff --git a/commands/command_ext.go b/commands/command_ext.go index da934eb5..f8c79fd1 100644 --- a/commands/command_ext.go +++ b/commands/command_ext.go @@ -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 diff --git a/commands/command_fetch.go b/commands/command_fetch.go index bd17ef16..71c79e79 100644 --- a/commands/command_fetch.go +++ b/commands/command_fetch.go @@ -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") } diff --git a/commands/command_lock.go b/commands/command_lock.go index 3583f7cd..3b85208f 100644 --- a/commands/command_lock.go +++ b/commands/command_lock.go @@ -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 ") @@ -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) } } diff --git a/commands/command_locks.go b/commands/command_locks.go index 2111ebb0..2bb6ca82 100644 --- a/commands/command_locks.go +++ b/commands/command_locks.go @@ -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) } } diff --git a/commands/command_pre_push.go b/commands/command_pre_push.go index 58809cf7..7c827f6a 100644 --- a/commands/command_pre_push.go +++ b/commands/command_pre_push.go @@ -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) diff --git a/commands/command_prune.go b/commands/command_prune.go index da466d99..0e561e0c 100644 --- a/commands/command_prune.go +++ b/commands/command_prune.go @@ -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 { diff --git a/commands/command_pull.go b/commands/command_pull.go index 08464639..6e2d6e8b 100644 --- a/commands/command_pull.go +++ b/commands/command_pull.go @@ -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)) } diff --git a/commands/command_push.go b/commands/command_push.go index 2eeb6b22..d3197e92 100644 --- a/commands/command_push.go +++ b/commands/command_push.go @@ -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 { diff --git a/commands/commands.go b/commands/commands.go index b9b946f3..df471691 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -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