commands/uploader: reuse *tq.TransferQueue and progress.Meter
This commit is contained in:
parent
d4dbc17991
commit
8c663a770b
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"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/tools"
|
||||
"github.com/git-lfs/git-lfs/tq"
|
||||
)
|
||||
@ -16,16 +17,25 @@ type uploadContext struct {
|
||||
DryRun bool
|
||||
Manifest *tq.Manifest
|
||||
uploadedOids tools.StringSet
|
||||
|
||||
meter progress.Meter
|
||||
tq *tq.TransferQueue
|
||||
}
|
||||
|
||||
func newUploadContext(remote string, dryRun bool) *uploadContext {
|
||||
cfg.CurrentRemote = remote
|
||||
|
||||
return &uploadContext{
|
||||
Remote: remote,
|
||||
Manifest: getTransferManifest(),
|
||||
DryRun: dryRun,
|
||||
uploadedOids: tools.NewStringSet(),
|
||||
}
|
||||
|
||||
ctx.meter = buildProgressMeter(ctx.DryRun)
|
||||
ctx.tq = newUploadQueue(c.Manifest, c.Remote, tq.WithProgress(ctx.meter), tq.DryRun(ctx.DryRun))
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
// AddUpload adds the given oid to the set of oids that have been uploaded in
|
||||
@ -45,7 +55,6 @@ func (c *uploadContext) prepareUpload(unfiltered []*lfs.WrappedPointer) (*tq.Tra
|
||||
uploadables := make([]*lfs.WrappedPointer, 0, numUnfiltered)
|
||||
missingLocalObjects := make([]*lfs.WrappedPointer, 0, numUnfiltered)
|
||||
missingSize := int64(0)
|
||||
meter := buildProgressMeter(c.DryRun)
|
||||
|
||||
// XXX(taylor): temporary measure to fix duplicate (broken) results from
|
||||
// scanner
|
||||
@ -63,7 +72,7 @@ func (c *uploadContext) prepareUpload(unfiltered []*lfs.WrappedPointer) (*tq.Tra
|
||||
|
||||
// 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.Add(p.Size)
|
||||
c.meter.Add(p.Size)
|
||||
|
||||
if lfs.ObjectExistsOfSize(p.Oid, p.Size) {
|
||||
uploadables = append(uploadables, p)
|
||||
@ -78,21 +87,20 @@ func (c *uploadContext) prepareUpload(unfiltered []*lfs.WrappedPointer) (*tq.Tra
|
||||
// check to see if the server has the missing objects.
|
||||
c.checkMissing(missingLocalObjects, missingSize)
|
||||
|
||||
// build the TransferQueue, automatically skipping any missing objects that
|
||||
// the server already has.
|
||||
uploadQueue := newUploadQueue(c.Manifest, c.Remote, tq.WithProgress(meter), tq.DryRun(c.DryRun))
|
||||
// use the context's TransferQueue, automatically skipping any missing
|
||||
// objects that the server already has.
|
||||
for _, p := range missingLocalObjects {
|
||||
if c.HasUploaded(p.Oid) {
|
||||
// if the server already has this object, call Skip() on
|
||||
// the progressmeter to decrement the number of files by
|
||||
// 1 and the number of bytes by `p.Size`.
|
||||
uploadQueue.Skip(p.Size)
|
||||
c.tq.Skip(p.Size)
|
||||
} else {
|
||||
uploadables = append(uploadables, p)
|
||||
}
|
||||
}
|
||||
|
||||
return uploadQueue, uploadables
|
||||
return c.tq, uploadables
|
||||
}
|
||||
|
||||
// This checks the given slice of pointers that don't exist in .git/lfs/objects
|
||||
@ -157,14 +165,16 @@ func uploadPointers(c *uploadContext, unfiltered []*lfs.WrappedPointer) {
|
||||
q.Add(t.Name, t.Path, t.Oid, t.Size)
|
||||
c.SetUploaded(p.Oid)
|
||||
}
|
||||
}
|
||||
|
||||
q.Wait()
|
||||
func (c *uploadContext) Await() {
|
||||
c.tq.Wait()
|
||||
|
||||
for _, err := range q.Errors() {
|
||||
for _, err := range c.tq.Errors() {
|
||||
FullError(err)
|
||||
}
|
||||
|
||||
if len(q.Errors()) > 0 {
|
||||
if len(c.tq.Errors()) > 0 {
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user