Pass a *progress.ProgressMeter to NewUploadQueue()

This commit is contained in:
risk danger olson 2016-12-06 19:59:42 -07:00
parent fd8aeaf320
commit 9a8ee52a6f
3 changed files with 13 additions and 13 deletions

@ -38,9 +38,8 @@ func (c *uploadContext) prepareUpload(unfiltered []*lfs.WrappedPointer) (*lfs.Tr
numUnfiltered := len(unfiltered)
uploadables := make([]*lfs.WrappedPointer, 0, numUnfiltered)
missingLocalObjects := make([]*lfs.WrappedPointer, 0, numUnfiltered)
numObjects := 0
totalSize := int64(0)
missingSize := int64(0)
meter := buildProgressMeter()
// XXX(taylor): temporary measure to fix duplicate (broken) results from
// scanner
@ -56,11 +55,9 @@ func (c *uploadContext) prepareUpload(unfiltered []*lfs.WrappedPointer) (*lfs.Tr
}
uniqOids.Add(p.Oid)
// increment numObjects and totalSize early (even if it's not
// going into uploadables), since we will call Skip() based on
// the results of the download check queue
numObjects += 1
totalSize += p.Size
// estimate in meter early (even if it's not going into uploadables), since
// we will call Skip() based on the results of the download check queue.
meter.AddEstimate(p.Size)
if lfs.ObjectExistsOfSize(p.Oid, p.Size) {
uploadables = append(uploadables, p)
@ -77,7 +74,7 @@ func (c *uploadContext) prepareUpload(unfiltered []*lfs.WrappedPointer) (*lfs.Tr
// build the TransferQueue, automatically skipping any missing objects that
// the server already has.
uploadQueue := lfs.NewUploadQueue(numObjects, totalSize, c.DryRun)
uploadQueue := lfs.NewUploadQueue(meter, c.DryRun)
for _, p := range missingLocalObjects {
if c.HasUploaded(p.Oid) {
// if the server already has this object, call Skip() on

@ -8,6 +8,7 @@ import (
"github.com/git-lfs/git-lfs/api"
"github.com/git-lfs/git-lfs/config"
"github.com/git-lfs/git-lfs/errors"
"github.com/git-lfs/git-lfs/progress"
"github.com/git-lfs/git-lfs/transfer"
)
@ -67,8 +68,8 @@ func NewUploadable(oid, filename string) (*Uploadable, error) {
}
// NewUploadQueue builds an UploadQueue, allowing `workers` concurrent uploads.
func NewUploadQueue(files int, size int64, dryRun bool) *TransferQueue {
return newTransferQueue(files, size, dryRun, transfer.Upload)
func NewUploadQueue(meter *progress.ProgressMeter, dryRun bool) *TransferQueue {
return newTransferQueueWithMeter(transfer.Upload, meter, dryRun)
}
// ensureFile makes sure that the cleanPath exists before pushing it. If it

@ -14,6 +14,7 @@ import (
"github.com/git-lfs/git-lfs/config"
"github.com/git-lfs/git-lfs/errors"
"github.com/git-lfs/git-lfs/lfs"
"github.com/git-lfs/git-lfs/progress"
"github.com/git-lfs/git-lfs/test"
"github.com/spf13/cobra"
)
@ -137,6 +138,8 @@ func buildTestData() (oidsExist, oidsMissing []TestObject, err error) {
const oidCount = 50
oidsExist = make([]TestObject, 0, oidCount)
oidsMissing = make([]TestObject, 0, oidCount)
logPath, _ := config.Config.Os.Get("GIT_LFS_PROGRESS")
meter := progress.NewMeter(logPath)
// Build test data for existing files & upload
// Use test repo for this to simplify the process of making sure data matches oid
@ -147,17 +150,16 @@ func buildTestData() (oidsExist, oidsMissing []TestObject, err error) {
defer repo.Cleanup()
// just one commit
commit := test.CommitInput{CommitterName: "A N Other", CommitterEmail: "noone@somewhere.com"}
var totalSize int64
for i := 0; i < oidCount; i++ {
filename := fmt.Sprintf("file%d.dat", i)
sz := int64(rand.Intn(200)) + 50
commit.Files = append(commit.Files, &test.FileInput{Filename: filename, Size: sz})
totalSize += sz
meter.AddEstimate(sz)
}
outputs := repo.AddCommits([]*test.CommitInput{&commit})
// now upload
uploadQueue := lfs.NewUploadQueue(len(oidsExist), totalSize, false)
uploadQueue := lfs.NewUploadQueue(meter, false)
for _, f := range outputs[0].Files {
oidsExist = append(oidsExist, TestObject{Oid: f.Oid, Size: f.Size})