diff --git a/commands/command_smudge.go b/commands/command_smudge.go index ba5b5c63..5da81456 100644 --- a/commands/command_smudge.go +++ b/commands/command_smudge.go @@ -53,7 +53,7 @@ func smudge(to io.Writer, from io.Reader, filename string, skip bool, filter *fi } lfs.LinkOrCopyFromReference(ptr.Oid, ptr.Size) - cb, file, err := lfs.CopyCallbackFile("smudge", filename, 1, 1) + cb, file, err := lfs.CopyCallbackFile("download", filename, 1, 1) if err != nil { return 0, err } diff --git a/lfs/pointer_smudge.go b/lfs/pointer_smudge.go index fe876211..2ad1999f 100644 --- a/lfs/pointer_smudge.go +++ b/lfs/pointer_smudge.go @@ -76,7 +76,12 @@ func PointerSmudge(writer io.Writer, ptr *Pointer, workingfile string, download func downloadFile(writer io.Writer, ptr *Pointer, workingfile, mediafile string, manifest *tq.Manifest, cb progress.CopyCallback) (int64, error) { fmt.Fprintf(os.Stderr, "Downloading %s (%s)\n", workingfile, humanize.FormatBytes(uint64(ptr.Size))) - q := tq.NewTransferQueue(tq.Download, manifest, "") + // NOTE: if given, "cb" is a progress.CopyCallback which writes updates + // to the logpath specified by GIT_LFS_PROGRESS. + // + // Either way, forward it into the *tq.TransferQueue so that updates are + // sent over correctly. + q := tq.NewTransferQueue(tq.Download, manifest, "", tq.WithProgressCallback(cb)) q.Add(filepath.Base(workingfile), mediafile, ptr.Oid, ptr.Size) q.Wait() diff --git a/progress/logger.go b/progress/logger.go index bc8f2e80..7b487a64 100644 --- a/progress/logger.go +++ b/progress/logger.go @@ -11,7 +11,7 @@ type progressLogger struct { // Write will write to the file and perform a Sync() if writing succeeds. func (l *progressLogger) Write(b []byte) error { - if l.writeData { + if !l.writeData { return nil } if _, err := l.log.Write(b); err != nil { diff --git a/tq/transfer_queue.go b/tq/transfer_queue.go index 6052f014..67f4e9a7 100644 --- a/tq/transfer_queue.go +++ b/tq/transfer_queue.go @@ -95,6 +95,7 @@ type TransferQueue struct { adapterInProgress bool adapterInitMutex sync.Mutex dryRun bool + cb progress.CopyCallback meter progress.Meter errors []error transfers map[string]*objectTuple @@ -134,6 +135,12 @@ func WithProgress(m progress.Meter) Option { } } +func WithProgressCallback(cb progress.CopyCallback) Option { + return func(tq *TransferQueue) { + tq.cb = cb + } +} + func WithBatchSize(size int) Option { return func(tq *TransferQueue) { tq.batchSize = size } } @@ -575,6 +582,13 @@ func (q *TransferQueue) ensureAdapterBegun(e lfsapi.Endpoint) error { // Progress callback - receives byte updates cb := func(name string, total, read int64, current int) error { q.meter.TransferBytes(q.direction.String(), name, read, total, current) + if q.cb != nil { + // NOTE: this is the mechanism by which the logpath + // specified by GIT_LFS_PROGRESS is written to. + // + // See: lfs.downloadFile() for more. + q.cb(total, read, current) + } return nil }