commands/command_{fetch,prune}.go: tidy task setup

The SimpleTask structure of the "tasklog" package, which was introduced
in commit 7a760b6b43d1131bbac89a552cf656b7fa6ce17a of PR #2756, is used
at several points in the implementation of the "git lfs fetch" and
"git lfs prune" commands, and in each case is constructed with a
call to the NewSimpleTask() function, and then passed to a Logger
structure's Enqueue() method.

However, in commit 0cad488c23350ff35f969980753bf9798071942e of PR #2767,
a Logger.Simple() method was added to both create a new SimpleTask
structure and pass it to a Logger structure's Enqueue() method.  This
Logger.Simple() method was added to be consistent with other existing
similar methods such as Logger.List() and Logger.Percentage().

These other methods are used consistently throughout our code
to create and enqueue tasks, so we now update the locations where
we call NewSimpleTask() to use the Logger.Simple() method instead.

This also provides an opportunity to tidy some of the surrounding
code and whitespace.
This commit is contained in:
Chris Darroch 2023-05-26 01:46:32 -07:00
parent a5e26b2705
commit 7bd5791f32
2 changed files with 8 additions and 15 deletions

@ -154,18 +154,16 @@ func fetchRef(ref string, filter *filepathfilter.Filter) bool {
func pointersToFetchForRefs(refs []string) ([]*lfs.WrappedPointer, error) {
// This could be a long process so use the chan version & report progress
task := tasklog.NewSimpleTask()
defer task.Complete()
logger := tasklog.NewLogger(OutputWriter,
tasklog.ForceProgress(cfg.ForceProgress()),
)
logger.Enqueue(task)
var numObjs int64
task := logger.Simple()
defer task.Complete()
// use temp gitscanner to collect pointers
var pointers []*lfs.WrappedPointer
var multiErr error
var numObjs int64
tempgitscanner := lfs.NewGitScanner(cfg, func(p *lfs.WrappedPointer, err error) {
if err != nil {
if multiErr != nil {
@ -293,18 +291,16 @@ func fetchAll() bool {
func scanAll() []*lfs.WrappedPointer {
// This could be a long process so use the chan version & report progress
task := tasklog.NewSimpleTask()
defer task.Complete()
logger := tasklog.NewLogger(OutputWriter,
tasklog.ForceProgress(cfg.ForceProgress()),
)
logger.Enqueue(task)
var numObjs int64
task := logger.Simple()
defer task.Complete()
// use temp gitscanner to collect pointers
var pointers []*lfs.WrappedPointer
var multiErr error
var numObjs int64
tempgitscanner := lfs.NewGitScanner(cfg, func(p *lfs.WrappedPointer, err error) {
if err != nil {
if multiErr != nil {

@ -197,8 +197,7 @@ func prune(fetchPruneConfig lfs.FetchPruneConfig, verifyRemote, dryRun, verbose
return
}
info := tasklog.NewSimpleTask()
logger.Enqueue(info)
info := logger.Simple()
if dryRun {
info.Logf("prune: %s", tr.Tr.GetN(
"%d file would be pruned (%s)",
@ -255,11 +254,9 @@ func pruneCheckErrors(taskErrors []error) {
func pruneTaskDisplayProgress(progressChan PruneProgressChan, waitg *sync.WaitGroup, logger *tasklog.Logger) {
defer waitg.Done()
task := tasklog.NewSimpleTask()
task := logger.Simple()
defer task.Complete()
logger.Enqueue(task)
localCount := 0
retainCount := 0
verifyCount := 0