move config.FetchPruneConfig -> lfs.FetchPruneConfig
This commit is contained in:
parent
c0a5df6e33
commit
d51ef02e59
@ -66,6 +66,7 @@ func fetchCommand(cmd *cobra.Command, args []string) {
|
|||||||
defer gitscanner.Close()
|
defer gitscanner.Close()
|
||||||
|
|
||||||
include, exclude := getIncludeExcludeArgs(cmd)
|
include, exclude := getIncludeExcludeArgs(cmd)
|
||||||
|
fetchPruneCfg := lfs.NewFetchPruneConfig(cfg.Git)
|
||||||
|
|
||||||
if fetchAllArg {
|
if fetchAllArg {
|
||||||
if fetchRecentArg || len(args) > 1 {
|
if fetchRecentArg || len(args) > 1 {
|
||||||
@ -89,17 +90,16 @@ func fetchCommand(cmd *cobra.Command, args []string) {
|
|||||||
success = success && s
|
success = success && s
|
||||||
}
|
}
|
||||||
|
|
||||||
if fetchRecentArg || cfg.FetchPruneConfig().FetchRecentAlways {
|
if fetchRecentArg || fetchPruneCfg.FetchRecentAlways {
|
||||||
s := fetchRecent(refs, filter)
|
s := fetchRecent(fetchPruneCfg, refs, filter)
|
||||||
success = success && s
|
success = success && s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if fetchPruneArg {
|
if fetchPruneArg {
|
||||||
fetchconf := cfg.FetchPruneConfig()
|
verify := fetchPruneCfg.PruneVerifyRemoteAlways
|
||||||
verify := fetchconf.PruneVerifyRemoteAlways
|
|
||||||
// no dry-run or verbose options in fetch, assume false
|
// no dry-run or verbose options in fetch, assume false
|
||||||
prune(fetchconf, verify, false, false)
|
prune(fetchPruneCfg, verify, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
@ -169,9 +169,7 @@ func fetchPreviousVersions(ref string, since time.Time, filter *filepathfilter.F
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch recent objects based on config
|
// Fetch recent objects based on config
|
||||||
func fetchRecent(alreadyFetchedRefs []*git.Ref, filter *filepathfilter.Filter) bool {
|
func fetchRecent(fetchconf lfs.FetchPruneConfig, alreadyFetchedRefs []*git.Ref, filter *filepathfilter.Filter) bool {
|
||||||
fetchconf := cfg.FetchPruneConfig()
|
|
||||||
|
|
||||||
if fetchconf.FetchRecentRefsDays == 0 && fetchconf.FetchRecentCommitsDays == 0 {
|
if fetchconf.FetchRecentRefsDays == 0 && fetchconf.FetchRecentCommitsDays == 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func pruneCommand(cmd *cobra.Command, args []string) {
|
|||||||
Exit("Cannot specify both --verify-remote and --no-verify-remote")
|
Exit("Cannot specify both --verify-remote and --no-verify-remote")
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchPruneConfig := cfg.FetchPruneConfig()
|
fetchPruneConfig := lfs.NewFetchPruneConfig(cfg.Git)
|
||||||
verify := !pruneDoNotVerifyArg &&
|
verify := !pruneDoNotVerifyArg &&
|
||||||
(fetchPruneConfig.PruneVerifyRemoteAlways || pruneVerifyArg)
|
(fetchPruneConfig.PruneVerifyRemoteAlways || pruneVerifyArg)
|
||||||
prune(fetchPruneConfig, verify, pruneDryRunArg, pruneVerboseArg)
|
prune(fetchPruneConfig, verify, pruneDryRunArg, pruneVerboseArg)
|
||||||
@ -53,7 +53,7 @@ type PruneProgress struct {
|
|||||||
}
|
}
|
||||||
type PruneProgressChan chan PruneProgress
|
type PruneProgressChan chan PruneProgress
|
||||||
|
|
||||||
func prune(fetchPruneConfig config.FetchPruneConfig, verifyRemote, dryRun, verbose bool) {
|
func prune(fetchPruneConfig lfs.FetchPruneConfig, verifyRemote, dryRun, verbose bool) {
|
||||||
localObjects := make([]localstorage.Object, 0, 100)
|
localObjects := make([]localstorage.Object, 0, 100)
|
||||||
retainedObjects := tools.NewStringSetWithCapacity(100)
|
retainedObjects := tools.NewStringSetWithCapacity(100)
|
||||||
var reachableObjects tools.StringSet
|
var reachableObjects tools.StringSet
|
||||||
@ -345,7 +345,7 @@ func pruneTaskGetPreviousVersionsOfRef(gitscanner *lfs.GitScanner, ref string, s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Background task, must call waitg.Done() once at end
|
// Background task, must call waitg.Done() once at end
|
||||||
func pruneTaskGetRetainedCurrentAndRecentRefs(gitscanner *lfs.GitScanner, fetchconf config.FetchPruneConfig, retainChan chan string, errorChan chan error, waitg *sync.WaitGroup) {
|
func pruneTaskGetRetainedCurrentAndRecentRefs(gitscanner *lfs.GitScanner, fetchconf lfs.FetchPruneConfig, retainChan chan string, errorChan chan error, waitg *sync.WaitGroup) {
|
||||||
defer waitg.Done()
|
defer waitg.Done()
|
||||||
|
|
||||||
// We actually increment the waitg in this func since we kick off sub-goroutines
|
// We actually increment the waitg in this func since we kick off sub-goroutines
|
||||||
@ -399,7 +399,7 @@ func pruneTaskGetRetainedCurrentAndRecentRefs(gitscanner *lfs.GitScanner, fetchc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Background task, must call waitg.Done() once at end
|
// Background task, must call waitg.Done() once at end
|
||||||
func pruneTaskGetRetainedUnpushed(gitscanner *lfs.GitScanner, fetchconf config.FetchPruneConfig, retainChan chan string, errorChan chan error, waitg *sync.WaitGroup) {
|
func pruneTaskGetRetainedUnpushed(gitscanner *lfs.GitScanner, fetchconf lfs.FetchPruneConfig, retainChan chan string, errorChan chan error, waitg *sync.WaitGroup) {
|
||||||
defer waitg.Done()
|
defer waitg.Done()
|
||||||
|
|
||||||
err := gitscanner.ScanUnpushed(fetchconf.PruneRemoteName, func(p *lfs.WrappedPointer, err error) {
|
err := gitscanner.ScanUnpushed(fetchconf.PruneRemoteName, func(p *lfs.WrappedPointer, err error) {
|
||||||
|
@ -22,27 +22,6 @@ var (
|
|||||||
gitConfigWarningPrefix = "lfs."
|
gitConfigWarningPrefix = "lfs."
|
||||||
)
|
)
|
||||||
|
|
||||||
// FetchPruneConfig collects together the config options that control fetching and pruning
|
|
||||||
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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
// Os provides a `*Environment` used to access to the system's
|
// Os provides a `*Environment` used to access to the system's
|
||||||
// environment through os.Getenv. It is the point of entry for all
|
// environment through os.Getenv. It is the point of entry for all
|
||||||
@ -259,20 +238,6 @@ func (c *Configuration) SortedExtensions() ([]Extension, error) {
|
|||||||
return SortExtensions(c.Extensions())
|
return SortExtensions(c.Extensions())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Configuration) FetchPruneConfig() FetchPruneConfig {
|
|
||||||
f := &FetchPruneConfig{
|
|
||||||
FetchRecentRefsDays: 7,
|
|
||||||
FetchRecentRefsIncludeRemotes: true,
|
|
||||||
PruneOffsetDays: 3,
|
|
||||||
PruneRemoteName: "origin",
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.Unmarshal(f); err != nil {
|
|
||||||
panic(err.Error())
|
|
||||||
}
|
|
||||||
return *f
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Configuration) SkipDownloadErrors() bool {
|
func (c *Configuration) SkipDownloadErrors() bool {
|
||||||
return c.Os.Bool("GIT_LFS_SKIP_DOWNLOAD_ERRORS", false) || c.Git.Bool("lfs.skipdownloaderrors", false)
|
return c.Os.Bool("GIT_LFS_SKIP_DOWNLOAD_ERRORS", false) || c.Git.Bool("lfs.skipdownloaderrors", false)
|
||||||
}
|
}
|
||||||
|
@ -97,40 +97,6 @@ func TestLoadInvalidExtension(t *testing.T) {
|
|||||||
assert.Equal(t, 0, ext.Priority)
|
assert.Equal(t, 0, ext.Priority)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchPruneConfigDefault(t *testing.T) {
|
|
||||||
cfg := NewFrom(Values{})
|
|
||||||
fp := cfg.FetchPruneConfig()
|
|
||||||
|
|
||||||
assert.Equal(t, 7, fp.FetchRecentRefsDays)
|
|
||||||
assert.Equal(t, 0, fp.FetchRecentCommitsDays)
|
|
||||||
assert.Equal(t, 3, fp.PruneOffsetDays)
|
|
||||||
assert.True(t, fp.FetchRecentRefsIncludeRemotes)
|
|
||||||
assert.Equal(t, 3, fp.PruneOffsetDays)
|
|
||||||
assert.Equal(t, "origin", fp.PruneRemoteName)
|
|
||||||
assert.False(t, fp.PruneVerifyRemoteAlways)
|
|
||||||
|
|
||||||
}
|
|
||||||
func TestFetchPruneConfigCustom(t *testing.T) {
|
|
||||||
cfg := NewFrom(Values{
|
|
||||||
Git: map[string][]string{
|
|
||||||
"lfs.fetchrecentrefsdays": []string{"12"},
|
|
||||||
"lfs.fetchrecentremoterefs": []string{"false"},
|
|
||||||
"lfs.fetchrecentcommitsdays": []string{"9"},
|
|
||||||
"lfs.pruneoffsetdays": []string{"30"},
|
|
||||||
"lfs.pruneverifyremotealways": []string{"true"},
|
|
||||||
"lfs.pruneremotetocheck": []string{"upstream"},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
fp := cfg.FetchPruneConfig()
|
|
||||||
|
|
||||||
assert.Equal(t, 12, fp.FetchRecentRefsDays)
|
|
||||||
assert.Equal(t, 9, fp.FetchRecentCommitsDays)
|
|
||||||
assert.False(t, fp.FetchRecentRefsIncludeRemotes)
|
|
||||||
assert.Equal(t, 30, fp.PruneOffsetDays)
|
|
||||||
assert.Equal(t, "upstream", fp.PruneRemoteName)
|
|
||||||
assert.True(t, fp.PruneVerifyRemoteAlways)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFetchIncludeExcludesAreCleaned(t *testing.T) {
|
func TestFetchIncludeExcludesAreCleaned(t *testing.T) {
|
||||||
cfg := NewFrom(Values{
|
cfg := NewFrom(Values{
|
||||||
Git: map[string][]string{
|
Git: map[string][]string{
|
||||||
|
41
lfs/config.go
Normal file
41
lfs/config.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package lfs
|
||||||
|
|
||||||
|
import "github.com/git-lfs/git-lfs/config"
|
||||||
|
|
||||||
|
// FetchPruneConfig collects together the config options that control fetching and pruning
|
||||||
|
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
|
||||||
|
// Makes the FetchRecentRefsDays option apply to remote refs from fetch source as well (default true)
|
||||||
|
FetchRecentRefsIncludeRemotes bool
|
||||||
|
// 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
|
||||||
|
// Whether to always fetch recent even without --recent
|
||||||
|
FetchRecentAlways bool
|
||||||
|
// Number of days added to FetchRecent*; data outside combined window will be
|
||||||
|
// deleted when prune is run. (default 3)
|
||||||
|
PruneOffsetDays int
|
||||||
|
// Always verify with remote before pruning
|
||||||
|
PruneVerifyRemoteAlways bool
|
||||||
|
// Name of remote to check for unpushed and verify checks
|
||||||
|
PruneRemoteName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFetchPruneConfig(git config.Environment) FetchPruneConfig {
|
||||||
|
pruneRemote, _ := git.Get("lfs.pruneremotetocheck")
|
||||||
|
if len(pruneRemote) == 0 {
|
||||||
|
pruneRemote = "origin"
|
||||||
|
}
|
||||||
|
|
||||||
|
return FetchPruneConfig{
|
||||||
|
FetchRecentRefsDays: git.Int("lfs.fetchrecentrefsdays", 7),
|
||||||
|
FetchRecentRefsIncludeRemotes: git.Bool("lfs.fetchrecentremoterefs", true),
|
||||||
|
FetchRecentCommitsDays: git.Int("lfs.fetchrecentcommitsdays", 0),
|
||||||
|
FetchRecentAlways: git.Bool("lfs.fetchrecentalways", false),
|
||||||
|
PruneOffsetDays: git.Int("lfs.pruneoffsetdays", 3),
|
||||||
|
PruneVerifyRemoteAlways: git.Bool("lfs.pruneverifyremotealways", false),
|
||||||
|
PruneRemoteName: pruneRemote,
|
||||||
|
}
|
||||||
|
}
|
42
lfs/config_test.go
Normal file
42
lfs/config_test.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package lfs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/git-lfs/git-lfs/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFetchPruneConfigDefault(t *testing.T) {
|
||||||
|
cfg := config.NewFrom(config.Values{})
|
||||||
|
fp := NewFetchPruneConfig(cfg.Git)
|
||||||
|
|
||||||
|
assert.Equal(t, 7, fp.FetchRecentRefsDays)
|
||||||
|
assert.Equal(t, 0, fp.FetchRecentCommitsDays)
|
||||||
|
assert.Equal(t, 3, fp.PruneOffsetDays)
|
||||||
|
assert.True(t, fp.FetchRecentRefsIncludeRemotes)
|
||||||
|
assert.Equal(t, 3, fp.PruneOffsetDays)
|
||||||
|
assert.Equal(t, "origin", fp.PruneRemoteName)
|
||||||
|
assert.False(t, fp.PruneVerifyRemoteAlways)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFetchPruneConfigCustom(t *testing.T) {
|
||||||
|
cfg := config.NewFrom(config.Values{
|
||||||
|
Git: map[string][]string{
|
||||||
|
"lfs.fetchrecentrefsdays": []string{"12"},
|
||||||
|
"lfs.fetchrecentremoterefs": []string{"false"},
|
||||||
|
"lfs.fetchrecentcommitsdays": []string{"9"},
|
||||||
|
"lfs.pruneoffsetdays": []string{"30"},
|
||||||
|
"lfs.pruneverifyremotealways": []string{"true"},
|
||||||
|
"lfs.pruneremotetocheck": []string{"upstream"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
fp := NewFetchPruneConfig(cfg.Git)
|
||||||
|
|
||||||
|
assert.Equal(t, 12, fp.FetchRecentRefsDays)
|
||||||
|
assert.Equal(t, 9, fp.FetchRecentCommitsDays)
|
||||||
|
assert.False(t, fp.FetchRecentRefsIncludeRemotes)
|
||||||
|
assert.Equal(t, 30, fp.PruneOffsetDays)
|
||||||
|
assert.Equal(t, "upstream", fp.PruneRemoteName)
|
||||||
|
assert.True(t, fp.PruneVerifyRemoteAlways)
|
||||||
|
}
|
@ -78,7 +78,7 @@ func Environ(cfg *config.Configuration, manifest *tq.Manifest) []string {
|
|||||||
ultransfers := manifest.GetUploadAdapterNames()
|
ultransfers := manifest.GetUploadAdapterNames()
|
||||||
sort.Strings(ultransfers)
|
sort.Strings(ultransfers)
|
||||||
|
|
||||||
fetchPruneConfig := cfg.FetchPruneConfig()
|
fetchPruneConfig := NewFetchPruneConfig(cfg.Git)
|
||||||
storageConfig := localstorage.NewConfig(cfg.Git)
|
storageConfig := localstorage.NewConfig(cfg.Git)
|
||||||
|
|
||||||
env = append(env,
|
env = append(env,
|
||||||
|
Loading…
Reference in New Issue
Block a user