Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions commands/command_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ func uploadsWithObjectIDs(ctx *uploadContext, oids []string) {
}
}

uploadPointers(ctx, pointers...)
ctx.Await()
q := ctx.NewQueue()
ctx.UploadPointers(q, pointers...)
ctx.CollectErrors(q)
ctx.ReportErrors()
}

// lfsPushRefs returns valid ref updates from the given ref and --all arguments.
Expand Down
5 changes: 0 additions & 5 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ func newDownloadQueue(manifest *tq.Manifest, remote string, options ...tq.Option
return tq.NewTransferQueue(tq.Download, manifest, remote, options...)
}

// newUploadQueue builds an UploadQueue, allowing `workers` concurrent uploads.
func newUploadQueue(manifest *tq.Manifest, remote string, options ...tq.Option) *tq.TransferQueue {
return tq.NewTransferQueue(tq.Upload, manifest, remote, options...)
}

func buildFilepathFilter(config *config.Configuration, includeArg, excludeArg *string) *filepathfilter.Filter {
inc, exc := determineIncludeExcludePaths(config, includeArg, excludeArg)
return filepathfilter.New(inc, exc)
Expand Down
91 changes: 56 additions & 35 deletions commands/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,34 @@ func uploadForRefUpdates(ctx *uploadContext, updates []*refUpdate, pushAll bool)
if err != nil {
return err
}
defer gitscanner.Close()

defer func() {
gitscanner.Close()
ctx.ReportErrors()
}()

verifyLocksForUpdates(ctx.lockVerifier, updates)
for _, update := range updates {
if err := uploadLeftOrAll(gitscanner, ctx, update, pushAll); err != nil {
q := ctx.NewQueue() // initialized here to prevent looped defer
err := uploadLeftOrAll(gitscanner, ctx, q, update, pushAll)
ctx.CollectErrors(q)

if err != nil {
return errors.Wrap(err, fmt.Sprintf("ref %s:", update.Left().Name))
}
}

ctx.Await()
return nil
}

func uploadLeftOrAll(g *lfs.GitScanner, ctx *uploadContext, update *refUpdate, pushAll bool) error {
func uploadLeftOrAll(g *lfs.GitScanner, ctx *uploadContext, q *tq.TransferQueue, update *refUpdate, pushAll bool) error {
cb := ctx.gitScannerCallback(q)
if pushAll {
if err := g.ScanRefWithDeleted(update.LeftCommitish(), nil); err != nil {
if err := g.ScanRefWithDeleted(update.LeftCommitish(), cb); err != nil {
return err
}
} else {
if err := g.ScanLeftToRemote(update.LeftCommitish(), nil); err != nil {
if err := g.ScanLeftToRemote(update.LeftCommitish(), cb); err != nil {
return err
}
}
Expand All @@ -58,7 +66,6 @@ type uploadContext struct {

logger *tasklog.Logger
meter *tq.Meter
tq *tq.TransferQueue

committerName string
committerEmail string
Expand All @@ -72,6 +79,11 @@ type uploadContext struct {
// tracks errors from gitscanner callbacks
scannerErr error
errMu sync.Mutex

// filename => oid
missing map[string]string
corrupt map[string]string
otherErrs []error
}

func newUploadContext(dryRun bool) *uploadContext {
Expand All @@ -85,6 +97,9 @@ func newUploadContext(dryRun bool) *uploadContext {
gitfilter: lfs.NewGitFilter(cfg),
lockVerifier: newLockVerifier(manifest),
allowMissing: cfg.Git.Bool("lfs.allowincompletepush", true),
missing: make(map[string]string),
corrupt: make(map[string]string),
otherErrs: make([]error, 0),
}

var sink io.Writer = os.Stdout
Expand All @@ -95,12 +110,15 @@ func newUploadContext(dryRun bool) *uploadContext {
ctx.logger = tasklog.NewLogger(sink)
ctx.meter = buildProgressMeter(ctx.DryRun)
ctx.logger.Enqueue(ctx.meter)

ctx.tq = newUploadQueue(ctx.Manifest, ctx.Remote, tq.WithProgress(ctx.meter), tq.DryRun(ctx.DryRun))
ctx.committerName, ctx.committerEmail = cfg.CurrentCommitter()
return ctx
}

func (c *uploadContext) NewQueue(options ...tq.Option) *tq.TransferQueue {
return tq.NewTransferQueue(tq.Upload, c.Manifest, c.Remote,
tq.DryRun(c.DryRun), tq.WithProgress(c.meter))
}

func (c *uploadContext) scannerError() error {
c.errMu.Lock()
defer c.errMu.Unlock()
Expand All @@ -120,17 +138,20 @@ func (c *uploadContext) addScannerError(err error) {
}

func (c *uploadContext) buildGitScanner() (*lfs.GitScanner, error) {
gitscanner := lfs.NewGitScanner(func(p *lfs.WrappedPointer, err error) {
gitscanner := lfs.NewGitScanner(nil)
gitscanner.FoundLockable = func(n string) { c.lockVerifier.LockedByThem(n) }
gitscanner.PotentialLockables = c.lockVerifier
return gitscanner, gitscanner.RemoteForPush(c.Remote)
}

func (c *uploadContext) gitScannerCallback(tqueue *tq.TransferQueue) func(*lfs.WrappedPointer, error) {
return func(p *lfs.WrappedPointer, err error) {
if err != nil {
c.addScannerError(err)
} else {
uploadPointers(c, p)
c.UploadPointers(tqueue, p)
}
})

gitscanner.FoundLockable = func(n string) { c.lockVerifier.LockedByThem(n) }
gitscanner.PotentialLockables = c.lockVerifier
return gitscanner, gitscanner.RemoteForPush(c.Remote)
}
}

// AddUpload adds the given oid to the set of oids that have been uploaded in
Expand All @@ -145,7 +166,7 @@ func (c *uploadContext) HasUploaded(oid string) bool {
return c.uploadedOids.Contains(oid)
}

func (c *uploadContext) prepareUpload(unfiltered ...*lfs.WrappedPointer) (*tq.TransferQueue, []*lfs.WrappedPointer) {
func (c *uploadContext) prepareUpload(unfiltered ...*lfs.WrappedPointer) []*lfs.WrappedPointer {
numUnfiltered := len(unfiltered)
uploadables := make([]*lfs.WrappedPointer, 0, numUnfiltered)

Expand Down Expand Up @@ -193,10 +214,10 @@ func (c *uploadContext) prepareUpload(unfiltered ...*lfs.WrappedPointer) (*tq.Tr
}
}

return c.tq, uploadables
return uploadables
}

func uploadPointers(c *uploadContext, unfiltered ...*lfs.WrappedPointer) {
func (c *uploadContext) UploadPointers(q *tq.TransferQueue, unfiltered ...*lfs.WrappedPointer) {
if c.DryRun {
for _, p := range unfiltered {
if c.HasUploaded(p.Oid) {
Expand All @@ -210,7 +231,7 @@ func uploadPointers(c *uploadContext, unfiltered ...*lfs.WrappedPointer) {
return
}

q, pointers := c.prepareUpload(unfiltered...)
pointers := c.prepareUpload(unfiltered...)
for _, p := range pointers {
t, err := c.uploadTransfer(p)
if err != nil && !errors.IsCleanPointerError(err) {
Expand All @@ -222,30 +243,30 @@ func uploadPointers(c *uploadContext, unfiltered ...*lfs.WrappedPointer) {
}
}

func (c *uploadContext) Await() {
c.tq.Wait()

var missing = make(map[string]string)
var corrupt = make(map[string]string)
var others = make([]error, 0, len(c.tq.Errors()))
func (c *uploadContext) CollectErrors(tqueue *tq.TransferQueue) {
tqueue.Wait()

for _, err := range c.tq.Errors() {
for _, err := range tqueue.Errors() {
if malformed, ok := err.(*tq.MalformedObjectError); ok {
if malformed.Missing() {
missing[malformed.Name] = malformed.Oid
c.missing[malformed.Name] = malformed.Oid
} else if malformed.Corrupt() {
corrupt[malformed.Name] = malformed.Oid
c.corrupt[malformed.Name] = malformed.Oid
}
} else {
others = append(others, err)
c.otherErrs = append(c.otherErrs, err)
}
}
}

func (c *uploadContext) ReportErrors() {
c.meter.Finish()

for _, err := range others {
for _, err := range c.otherErrs {
FullError(err)
}

if len(missing) > 0 || len(corrupt) > 0 {
if len(c.missing) > 0 || len(c.corrupt) > 0 {
var action string
if c.allowMissing {
action = "missing objects"
Expand All @@ -254,10 +275,10 @@ func (c *uploadContext) Await() {
}

Print("LFS upload %s:", action)
for name, oid := range missing {
for name, oid := range c.missing {
Print(" (missing) %s (%s)", name, oid)
}
for name, oid := range corrupt {
for name, oid := range c.corrupt {
Print(" (corrupt) %s (%s)", name, oid)
}

Expand All @@ -266,7 +287,7 @@ func (c *uploadContext) Await() {
}
}

if len(others) > 0 {
if len(c.otherErrs) > 0 {
os.Exit(2)
}

Expand Down
28 changes: 19 additions & 9 deletions tq/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (m *Meter) Add(size int64) {
return
}

defer m.update()
defer m.update(false)
atomic.AddInt32(&m.estimatedFiles, 1)
atomic.AddInt64(&m.estimatedBytes, size)
}
Expand All @@ -117,7 +117,7 @@ func (m *Meter) Skip(size int64) {
return
}

defer m.update()
defer m.update(false)
atomic.AddInt64(&m.skippedFiles, 1)
atomic.AddInt64(&m.skippedBytes, size)
// Reduce bytes and files so progress easier to parse
Expand All @@ -132,7 +132,7 @@ func (m *Meter) StartTransfer(name string) {
return
}

defer m.update()
defer m.update(false)
idx := atomic.AddInt64(&m.transferringFiles, 1)
m.fileIndexMutex.Lock()
m.fileIndex[name] = idx
Expand All @@ -145,7 +145,7 @@ func (m *Meter) TransferBytes(direction, name string, read, total int64, current
return
}

defer m.update()
defer m.update(false)
atomic.AddInt64(&m.currentBytes, int64(current))
m.logBytes(direction, name, read, total)
}
Expand All @@ -156,20 +156,29 @@ func (m *Meter) FinishTransfer(name string) {
return
}

defer m.update()
defer m.update(false)
atomic.AddInt64(&m.finishedFiles, 1)
m.fileIndexMutex.Lock()
delete(m.fileIndex, name)
m.fileIndexMutex.Unlock()
}

// Flush sends the latest progress update, while leaving the meter active.
func (m *Meter) Flush() {
if m == nil {
return
}

m.update(true)
}

// Finish shuts down the Meter.
func (m *Meter) Finish() {
if m == nil {
return
}

m.update()
m.update(false)
close(m.updates)
}

Expand All @@ -184,14 +193,15 @@ func (m *Meter) Throttled() bool {
return true
}

func (m *Meter) update() {
func (m *Meter) update(force bool) {
if m.skipUpdate() {
return
}

m.updates <- &tasklog.Update{
S: m.str(),
At: time.Now(),
S: m.str(),
At: time.Now(),
Force: force,
}
}

Expand Down
2 changes: 1 addition & 1 deletion tq/transfer_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ func (q *TransferQueue) Wait() {
close(watcher)
}

q.meter.Finish()
q.meter.Flush()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that Flush() will call close(m.updates) which means that the *tasklog.Logger won't yield to future Task implementations.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: Re-reading your PR body makes this make sense to me. Is the update channel closed elsewhere, though?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q.errorwait.Wait()
}

Expand Down