Merge pull request #2465 from git-lfs/tq-forward-ccb

progress: fix writing updates to $GIT_LFS_PROGRESS
This commit is contained in:
Taylor Blau 2017-08-01 14:47:19 -06:00 committed by GitHub
commit 330e899466
4 changed files with 22 additions and 3 deletions

@ -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
}

@ -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()

@ -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 {

@ -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
}