From 8214aeee598ee81c5392434e6008d42a5a4776ab Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Wed, 9 Sep 2015 16:44:58 -0600 Subject: [PATCH] extract scanAll() from fetchAll() so the push cmd can use it too --- commands/command_fetch.go | 13 +++++++++++-- commands/command_push.go | 19 +------------------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/commands/command_fetch.go b/commands/command_fetch.go index c28c52d3..eee8fbd4 100644 --- a/commands/command_fetch.go +++ b/commands/command_fetch.go @@ -175,9 +175,16 @@ func fetchRecent(alreadyFetchedRefs []*git.Ref, include, exclude []string) { } func fetchAll() { + pointers := scanAll() + Print("Fetching objects...") + fetchPointers(pointers, nil, nil) +} + +func scanAll() []*lfs.WrappedPointer { // converts to `git rev-list --all` // We only pick up objects in real commits and not the reflog opts := &lfs.ScanRefsOptions{ScanMode: lfs.ScanAllMode, SkipDeletedBlobs: false} + // This could be a long process so use the chan version & report progress Print("Scanning for all objects ever referenced...") spinner := lfs.NewSpinner() @@ -186,15 +193,17 @@ func fetchAll() { if err != nil { Panic(err, "Could not scan for Git LFS files") } + pointers := make([]*lfs.WrappedPointer, 0) + for p := range pointerchan { numObjs++ spinner.Print(OutputWriter, fmt.Sprintf("%d objects found", numObjs)) pointers = append(pointers, p) } + spinner.Finish(OutputWriter, fmt.Sprintf("%d objects found", numObjs)) - Print("Fetching objects...") - fetchPointers(pointers, nil, nil) + return pointers } func fetchPointers(pointers []*lfs.WrappedPointer, include, exclude []string) { diff --git a/commands/command_push.go b/commands/command_push.go index 9f21493e..6a1ff4c7 100644 --- a/commands/command_push.go +++ b/commands/command_push.go @@ -1,7 +1,6 @@ package commands import ( - "fmt" "io/ioutil" "os" @@ -43,23 +42,7 @@ func uploadsBetweenRefAndRemote(remote string, refs []string) *lfs.TransferQueue if pushAll { if len(refs) == 0 { - // no ref given as an arg, so scan all refs - opts := &lfs.ScanRefsOptions{ScanMode: lfs.ScanAllMode, SkipDeletedBlobs: false} - // This could be a long process so use the chan version & report progress - Print("Scanning for all objects ever referenced...") - spinner := lfs.NewSpinner() - var numObjs int64 - pointerchan, err := lfs.ScanRefsToChan("", "", opts) - if err != nil { - Panic(err, "Could not scan for Git LFS files") - } - pointers := make([]*lfs.WrappedPointer, 0) - for p := range pointerchan { - numObjs++ - spinner.Print(OutputWriter, fmt.Sprintf("%d objects found", numObjs)) - pointers = append(pointers, p) - } - spinner.Finish(OutputWriter, fmt.Sprintf("%d objects found", numObjs)) + pointers := scanAll() Print("Pushing objects...") return uploadPointers(pointers) } else {