Merge pull request #2749 from git-lfs/progress-move-ccb
progress: move CopyCallback (& related) to package 'tools'
This commit is contained in:
commit
30b8d3b10c
@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/git-lfs/git-lfs/errors"
|
"github.com/git-lfs/git-lfs/errors"
|
||||||
"github.com/git-lfs/git-lfs/lfs"
|
"github.com/git-lfs/git-lfs/lfs"
|
||||||
"github.com/git-lfs/git-lfs/progress"
|
"github.com/git-lfs/git-lfs/tools"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ import (
|
|||||||
// If the object read from "from" is _already_ a clean pointer, then it will be
|
// If the object read from "from" is _already_ a clean pointer, then it will be
|
||||||
// written out verbatim to "to", without trying to make it a pointer again.
|
// written out verbatim to "to", without trying to make it a pointer again.
|
||||||
func clean(gf *lfs.GitFilter, to io.Writer, from io.Reader, fileName string, fileSize int64) (*lfs.Pointer, error) {
|
func clean(gf *lfs.GitFilter, to io.Writer, from io.Reader, fileName string, fileSize int64) (*lfs.Pointer, error) {
|
||||||
var cb progress.CopyCallback
|
var cb tools.CopyCallback
|
||||||
var file *os.File
|
var file *os.File
|
||||||
|
|
||||||
if len(fileName) > 0 {
|
if len(fileName) > 0 {
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/git-lfs/git-lfs/errors"
|
"github.com/git-lfs/git-lfs/errors"
|
||||||
"github.com/git-lfs/git-lfs/progress"
|
|
||||||
"github.com/git-lfs/git-lfs/tools"
|
"github.com/git-lfs/git-lfs/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ type cleanedAsset struct {
|
|||||||
*Pointer
|
*Pointer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *GitFilter) Clean(reader io.Reader, fileName string, fileSize int64, cb progress.CopyCallback) (*cleanedAsset, error) {
|
func (f *GitFilter) Clean(reader io.Reader, fileName string, fileSize int64, cb tools.CopyCallback) (*cleanedAsset, error) {
|
||||||
extensions, err := f.cfg.SortedExtensions()
|
extensions, err := f.cfg.SortedExtensions()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -61,7 +60,7 @@ func (f *GitFilter) Clean(reader io.Reader, fileName string, fileSize int64, cb
|
|||||||
return &cleanedAsset{tmp.Name(), pointer}, err
|
return &cleanedAsset{tmp.Name(), pointer}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *GitFilter) copyToTemp(reader io.Reader, fileSize int64, cb progress.CopyCallback) (oid string, size int64, tmp *os.File, err error) {
|
func (f *GitFilter) copyToTemp(reader io.Reader, fileSize int64, cb tools.CopyCallback) (oid string, size int64, tmp *os.File, err error) {
|
||||||
tmp, err = ioutil.TempFile(f.cfg.TempDir(), "")
|
tmp, err = ioutil.TempFile(f.cfg.TempDir(), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -6,17 +6,15 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/git-lfs/git-lfs/config"
|
||||||
|
"github.com/git-lfs/git-lfs/errors"
|
||||||
"github.com/git-lfs/git-lfs/tools"
|
"github.com/git-lfs/git-lfs/tools"
|
||||||
"github.com/git-lfs/git-lfs/tools/humanize"
|
"github.com/git-lfs/git-lfs/tools/humanize"
|
||||||
"github.com/git-lfs/git-lfs/tq"
|
"github.com/git-lfs/git-lfs/tq"
|
||||||
|
|
||||||
"github.com/git-lfs/git-lfs/config"
|
|
||||||
"github.com/git-lfs/git-lfs/errors"
|
|
||||||
"github.com/git-lfs/git-lfs/progress"
|
|
||||||
"github.com/rubyist/tracerx"
|
"github.com/rubyist/tracerx"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *GitFilter) SmudgeToFile(filename string, ptr *Pointer, download bool, manifest *tq.Manifest, cb progress.CopyCallback) error {
|
func (f *GitFilter) SmudgeToFile(filename string, ptr *Pointer, download bool, manifest *tq.Manifest, cb tools.CopyCallback) error {
|
||||||
os.MkdirAll(filepath.Dir(filename), 0755)
|
os.MkdirAll(filepath.Dir(filename), 0755)
|
||||||
file, err := os.Create(filename)
|
file, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -36,7 +34,7 @@ func (f *GitFilter) SmudgeToFile(filename string, ptr *Pointer, download bool, m
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *GitFilter) Smudge(writer io.Writer, ptr *Pointer, workingfile string, download bool, manifest *tq.Manifest, cb progress.CopyCallback) (int64, error) {
|
func (f *GitFilter) Smudge(writer io.Writer, ptr *Pointer, workingfile string, download bool, manifest *tq.Manifest, cb tools.CopyCallback) (int64, error) {
|
||||||
mediafile, err := f.ObjectPath(ptr.Oid)
|
mediafile, err := f.ObjectPath(ptr.Oid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -73,10 +71,10 @@ func (f *GitFilter) Smudge(writer io.Writer, ptr *Pointer, workingfile string, d
|
|||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *GitFilter) downloadFile(writer io.Writer, ptr *Pointer, workingfile, mediafile string, manifest *tq.Manifest, cb progress.CopyCallback) (int64, error) {
|
func (f *GitFilter) downloadFile(writer io.Writer, ptr *Pointer, workingfile, mediafile string, manifest *tq.Manifest, cb tools.CopyCallback) (int64, error) {
|
||||||
fmt.Fprintf(os.Stderr, "Downloading %s (%s)\n", workingfile, humanize.FormatBytes(uint64(ptr.Size)))
|
fmt.Fprintf(os.Stderr, "Downloading %s (%s)\n", workingfile, humanize.FormatBytes(uint64(ptr.Size)))
|
||||||
|
|
||||||
// NOTE: if given, "cb" is a progress.CopyCallback which writes updates
|
// NOTE: if given, "cb" is a tools.CopyCallback which writes updates
|
||||||
// to the logpath specified by GIT_LFS_PROGRESS.
|
// to the logpath specified by GIT_LFS_PROGRESS.
|
||||||
//
|
//
|
||||||
// Either way, forward it into the *tq.TransferQueue so that updates are
|
// Either way, forward it into the *tq.TransferQueue so that updates are
|
||||||
@ -101,7 +99,7 @@ func (f *GitFilter) downloadFile(writer io.Writer, ptr *Pointer, workingfile, me
|
|||||||
return f.readLocalFile(writer, ptr, mediafile, workingfile, nil)
|
return f.readLocalFile(writer, ptr, mediafile, workingfile, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *GitFilter) readLocalFile(writer io.Writer, ptr *Pointer, mediafile string, workingfile string, cb progress.CopyCallback) (int64, error) {
|
func (f *GitFilter) readLocalFile(writer io.Writer, ptr *Pointer, mediafile string, workingfile string, cb tools.CopyCallback) (int64, error) {
|
||||||
reader, err := os.Open(mediafile)
|
reader, err := os.Open(mediafile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.Wrapf(err, "Error opening media file.")
|
return 0, errors.Wrapf(err, "Error opening media file.")
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/git-lfs/git-lfs/config"
|
"github.com/git-lfs/git-lfs/config"
|
||||||
"github.com/git-lfs/git-lfs/progress"
|
|
||||||
"github.com/git-lfs/git-lfs/tools"
|
"github.com/git-lfs/git-lfs/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ const (
|
|||||||
|
|
||||||
var currentPlatform = PlatformUndetermined
|
var currentPlatform = PlatformUndetermined
|
||||||
|
|
||||||
func (f *GitFilter) CopyCallbackFile(event, filename string, index, totalFiles int) (progress.CopyCallback, *os.File, error) {
|
func (f *GitFilter) CopyCallbackFile(event, filename string, index, totalFiles int) (tools.CopyCallback, *os.File, error) {
|
||||||
logPath, _ := f.cfg.Os.Get("GIT_LFS_PROGRESS")
|
logPath, _ := f.cfg.Os.Get("GIT_LFS_PROGRESS")
|
||||||
if len(logPath) == 0 || len(filename) == 0 || len(event) == 0 {
|
if len(logPath) == 0 || len(filename) == 0 || len(event) == 0 {
|
||||||
return nil, nil, nil
|
return nil, nil, nil
|
||||||
@ -47,7 +46,7 @@ func (f *GitFilter) CopyCallbackFile(event, filename string, index, totalFiles i
|
|||||||
|
|
||||||
var prevWritten int64
|
var prevWritten int64
|
||||||
|
|
||||||
cb := progress.CopyCallback(func(total int64, written int64, current int) error {
|
cb := tools.CopyCallback(func(total int64, written int64, current int) error {
|
||||||
if written != prevWritten {
|
if written != prevWritten {
|
||||||
_, err := file.Write([]byte(fmt.Sprintf("%s %d/%d %d/%d %s\n", event, index, totalFiles, written, total, filename)))
|
_, err := file.Write([]byte(fmt.Sprintf("%s %d/%d %d/%d %s\n", event, index, totalFiles, written, total, filename)))
|
||||||
file.Sync()
|
file.Sync()
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/git-lfs/git-lfs/progress"
|
"github.com/git-lfs/git-lfs/tools"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ func TestBodyWithCallback(t *testing.T) {
|
|||||||
assert.Equal(t, 5, int(total))
|
assert.Equal(t, 5, int(total))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
reader := progress.NewByteBodyWithCallback([]byte("BOOYA"), 5, cb)
|
reader := tools.NewByteBodyWithCallback([]byte("BOOYA"), 5, cb)
|
||||||
|
|
||||||
readBuf := make([]byte, 3)
|
readBuf := make([]byte, 3)
|
||||||
n, err := reader.Read(readBuf)
|
n, err := reader.Read(readBuf)
|
||||||
@ -39,7 +39,7 @@ func TestReadWithCallback(t *testing.T) {
|
|||||||
called := 0
|
called := 0
|
||||||
calledRead := make([]int64, 0, 2)
|
calledRead := make([]int64, 0, 2)
|
||||||
|
|
||||||
reader := &progress.CallbackReader{
|
reader := &tools.CallbackReader{
|
||||||
TotalSize: 5,
|
TotalSize: 5,
|
||||||
Reader: bytes.NewBufferString("BOOYA"),
|
Reader: bytes.NewBufferString("BOOYA"),
|
||||||
C: func(total int64, read int64, current int) error {
|
C: func(total int64, read int64, current int) error {
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
"github.com/git-lfs/git-lfs/config"
|
"github.com/git-lfs/git-lfs/config"
|
||||||
"github.com/git-lfs/git-lfs/lfsapi"
|
"github.com/git-lfs/git-lfs/lfsapi"
|
||||||
"github.com/git-lfs/git-lfs/progress"
|
|
||||||
"github.com/git-lfs/git-lfs/tools"
|
"github.com/git-lfs/git-lfs/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -192,7 +191,7 @@ func performUpload(apiClient *lfsapi.Client, oid string, size int64, a *action,
|
|||||||
sendProgress(oid, readSoFar, readSinceLast, writer, errWriter)
|
sendProgress(oid, readSoFar, readSinceLast, writer, errWriter)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
req.Body = progress.NewBodyWithCallback(f, size, cb)
|
req.Body = tools.NewBodyWithCallback(f, size, cb)
|
||||||
|
|
||||||
res, err := apiClient.DoWithAuth("origin", req)
|
res, err := apiClient.DoWithAuth("origin", req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package progress
|
package tools
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -1,4 +1,4 @@
|
|||||||
package progress
|
package tools
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
@ -10,7 +10,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/git-lfs/git-lfs/errors"
|
"github.com/git-lfs/git-lfs/errors"
|
||||||
"github.com/git-lfs/git-lfs/progress"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -21,7 +20,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// CopyWithCallback copies reader to writer while performing a progress callback
|
// CopyWithCallback copies reader to writer while performing a progress callback
|
||||||
func CopyWithCallback(writer io.Writer, reader io.Reader, totalSize int64, cb progress.CopyCallback) (int64, error) {
|
func CopyWithCallback(writer io.Writer, reader io.Reader, totalSize int64, cb CopyCallback) (int64, error) {
|
||||||
if success, _ := CloneFile(writer, reader); success {
|
if success, _ := CloneFile(writer, reader); success {
|
||||||
if cb != nil {
|
if cb != nil {
|
||||||
cb(totalSize, totalSize, 0)
|
cb(totalSize, totalSize, 0)
|
||||||
@ -32,7 +31,7 @@ func CopyWithCallback(writer io.Writer, reader io.Reader, totalSize int64, cb pr
|
|||||||
return io.Copy(writer, reader)
|
return io.Copy(writer, reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
cbReader := &progress.CallbackReader{
|
cbReader := &CallbackReader{
|
||||||
C: cb,
|
C: cb,
|
||||||
TotalSize: totalSize,
|
TotalSize: totalSize,
|
||||||
Reader: reader,
|
Reader: reader,
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/git-lfs/git-lfs/errors"
|
"github.com/git-lfs/git-lfs/errors"
|
||||||
"github.com/git-lfs/git-lfs/lfsapi"
|
"github.com/git-lfs/git-lfs/lfsapi"
|
||||||
"github.com/git-lfs/git-lfs/progress"
|
"github.com/git-lfs/git-lfs/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -83,7 +83,7 @@ func (a *basicUploadAdapter) DoTransfer(ctx interface{}, t *Transfer, cb Progres
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cbr := progress.NewBodyWithCallback(f, t.Size, ccb)
|
cbr := tools.NewBodyWithCallback(f, t.Size, ccb)
|
||||||
var reader lfsapi.ReadSeekCloser = cbr
|
var reader lfsapi.ReadSeekCloser = cbr
|
||||||
|
|
||||||
// Signal auth was ok on first read; this frees up other workers to start
|
// Signal auth was ok on first read; this frees up other workers to start
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/git-lfs/git-lfs/errors"
|
"github.com/git-lfs/git-lfs/errors"
|
||||||
"github.com/git-lfs/git-lfs/lfsapi"
|
"github.com/git-lfs/git-lfs/lfsapi"
|
||||||
"github.com/git-lfs/git-lfs/progress"
|
"github.com/git-lfs/git-lfs/progress"
|
||||||
|
"github.com/git-lfs/git-lfs/tools"
|
||||||
"github.com/rubyist/tracerx"
|
"github.com/rubyist/tracerx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ type TransferQueue struct {
|
|||||||
adapterInProgress bool
|
adapterInProgress bool
|
||||||
adapterInitMutex sync.Mutex
|
adapterInitMutex sync.Mutex
|
||||||
dryRun bool
|
dryRun bool
|
||||||
cb progress.CopyCallback
|
cb tools.CopyCallback
|
||||||
meter progress.Meter
|
meter progress.Meter
|
||||||
errors []error
|
errors []error
|
||||||
transfers map[string]*objects
|
transfers map[string]*objects
|
||||||
@ -183,7 +184,7 @@ func WithProgress(m progress.Meter) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithProgressCallback(cb progress.CopyCallback) Option {
|
func WithProgressCallback(cb tools.CopyCallback) Option {
|
||||||
return func(tq *TransferQueue) {
|
return func(tq *TransferQueue) {
|
||||||
tq.cb = cb
|
tq.cb = cb
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/git-lfs/git-lfs/errors"
|
"github.com/git-lfs/git-lfs/errors"
|
||||||
"github.com/git-lfs/git-lfs/lfsapi"
|
"github.com/git-lfs/git-lfs/lfsapi"
|
||||||
"github.com/git-lfs/git-lfs/progress"
|
"github.com/git-lfs/git-lfs/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -119,7 +119,7 @@ func (a *tusUploadAdapter) DoTransfer(ctx interface{}, t *Transfer, cb ProgressC
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var reader lfsapi.ReadSeekCloser = progress.NewBodyWithCallback(f, t.Size, ccb)
|
var reader lfsapi.ReadSeekCloser = tools.NewBodyWithCallback(f, t.Size, ccb)
|
||||||
reader = newStartCallbackReader(reader, func() error {
|
reader = newStartCallbackReader(reader, func() error {
|
||||||
// seek to the offset since lfsapi.Client rewinds the body
|
// seek to the offset since lfsapi.Client rewinds the body
|
||||||
if _, err := f.Seek(offset, os.SEEK_CUR); err != nil {
|
if _, err := f.Seek(offset, os.SEEK_CUR); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user