lfs,tq: move type *lfs.TransferQueue to pkg "tq"

This commit is contained in:
Taylor Blau 2016-12-11 17:20:14 -07:00
parent f17a07ea70
commit c5ce4b7287
8 changed files with 26 additions and 20 deletions

@ -8,6 +8,7 @@ import (
"github.com/git-lfs/git-lfs/git"
"github.com/git-lfs/git-lfs/lfs"
"github.com/git-lfs/git-lfs/progress"
"github.com/git-lfs/git-lfs/tq"
"github.com/rubyist/tracerx"
"github.com/spf13/cobra"
)
@ -290,7 +291,7 @@ func fetchAndReportToChan(allpointers []*lfs.WrappedPointer, filter *filepathfil
}
ready, pointers, meter := readyAndMissingPointers(allpointers, filter)
q := lfs.NewDownloadQueue(lfs.WithProgress(meter))
q := lfs.NewDownloadQueue(tq.WithProgress(meter))
if out != nil {
// If we already have it, or it won't be fetched

@ -13,6 +13,7 @@ import (
"github.com/git-lfs/git-lfs/localstorage"
"github.com/git-lfs/git-lfs/progress"
"github.com/git-lfs/git-lfs/tools"
"github.com/git-lfs/git-lfs/tq"
"github.com/rubyist/tracerx"
"github.com/spf13/cobra"
)
@ -111,7 +112,7 @@ func prune(fetchPruneConfig config.FetchPruneConfig, verifyRemote, dryRun, verbo
prunableObjects := make([]string, 0, len(localObjects)/2)
// Build list of prunables (also queue for verify at same time if applicable)
var verifyQueue *lfs.TransferQueue
var verifyQueue *tq.TransferQueue
var verifiedObjects tools.StringSet
var totalSize int64
var verboseOutput bytes.Buffer

@ -6,6 +6,7 @@ import (
"github.com/git-lfs/git-lfs/errors"
"github.com/git-lfs/git-lfs/lfs"
"github.com/git-lfs/git-lfs/tools"
"github.com/git-lfs/git-lfs/tq"
)
var uploadMissingErr = "%s does not exist in .git/lfs/objects. Tried %s, which matches %s."
@ -34,7 +35,7 @@ func (c *uploadContext) HasUploaded(oid string) bool {
return c.uploadedOids.Contains(oid)
}
func (c *uploadContext) prepareUpload(unfiltered []*lfs.WrappedPointer) (*lfs.TransferQueue, []*lfs.WrappedPointer) {
func (c *uploadContext) prepareUpload(unfiltered []*lfs.WrappedPointer) (*tq.TransferQueue, []*lfs.WrappedPointer) {
numUnfiltered := len(unfiltered)
uploadables := make([]*lfs.WrappedPointer, 0, numUnfiltered)
missingLocalObjects := make([]*lfs.WrappedPointer, 0, numUnfiltered)
@ -74,7 +75,7 @@ func (c *uploadContext) prepareUpload(unfiltered []*lfs.WrappedPointer) (*lfs.Tr
// build the TransferQueue, automatically skipping any missing objects that
// the server already has.
uploadQueue := lfs.NewUploadQueue(lfs.WithProgress(meter), lfs.DryRun(c.DryRun))
uploadQueue := lfs.NewUploadQueue(tq.WithProgress(meter), tq.DryRun(c.DryRun))
for _, p := range missingLocalObjects {
if c.HasUploaded(p.Oid) {
// if the server already has this object, call Skip() on

@ -2,6 +2,7 @@ package lfs
import (
"github.com/git-lfs/git-lfs/api"
"github.com/git-lfs/git-lfs/tq"
"github.com/git-lfs/git-lfs/transfer"
)
@ -40,11 +41,11 @@ func NewDownloadable(p *WrappedPointer) *Downloadable {
}
// NewDownloadCheckQueue builds a checking queue, checks that objects are there but doesn't download
func NewDownloadCheckQueue(options ...transferQueueOption) *TransferQueue {
return newTransferQueue(transfer.Download, options...)
func NewDownloadCheckQueue(options ...tq.TransferQueueOption) *tq.TransferQueue {
return tq.NewTransferQueue(transfer.Download, options...)
}
// NewDownloadQueue builds a DownloadQueue, allowing concurrent downloads.
func NewDownloadQueue(options ...transferQueueOption) *TransferQueue {
return newTransferQueue(transfer.Download, options...)
func NewDownloadQueue(options ...tq.TransferQueueOption) *tq.TransferQueue {
return tq.NewTransferQueue(transfer.Download, options...)
}

@ -8,6 +8,7 @@ import (
"github.com/git-lfs/git-lfs/api"
"github.com/git-lfs/git-lfs/config"
"github.com/git-lfs/git-lfs/errors"
"github.com/git-lfs/git-lfs/tq"
"github.com/git-lfs/git-lfs/transfer"
)
@ -67,8 +68,8 @@ func NewUploadable(oid, filename string) (*Uploadable, error) {
}
// NewUploadQueue builds an UploadQueue, allowing `workers` concurrent uploads.
func NewUploadQueue(options ...transferQueueOption) *TransferQueue {
return newTransferQueue(transfer.Upload, options...)
func NewUploadQueue(options ...tq.TransferQueueOption) *tq.TransferQueue {
return tq.NewTransferQueue(transfer.Upload, options...)
}
// ensureFile makes sure that the cleanPath exists before pushing it. If it

@ -16,6 +16,7 @@ import (
"github.com/git-lfs/git-lfs/lfs"
"github.com/git-lfs/git-lfs/progress"
"github.com/git-lfs/git-lfs/test"
"github.com/git-lfs/git-lfs/tq"
"github.com/spf13/cobra"
)
@ -158,7 +159,7 @@ func buildTestData() (oidsExist, oidsMissing []TestObject, err error) {
outputs := repo.AddCommits([]*test.CommitInput{&commit})
// now upload
uploadQueue := lfs.NewUploadQueue(lfs.WithProgress(meter))
uploadQueue := lfs.NewUploadQueue(tq.WithProgress(meter))
for _, f := range outputs[0].Files {
oidsExist = append(oidsExist, TestObject{Oid: f.Oid, Size: f.Size})

@ -1,4 +1,4 @@
package lfs
package tq
import (
"sort"
@ -137,30 +137,30 @@ type TransferQueue struct {
rc *retryCounter
}
type transferQueueOption func(*TransferQueue)
type TransferQueueOption func(*TransferQueue)
func DryRun(dryRun bool) transferQueueOption {
func DryRun(dryRun bool) TransferQueueOption {
return func(tq *TransferQueue) {
tq.dryRun = dryRun
}
}
func WithProgress(m progress.Meter) transferQueueOption {
func WithProgress(m progress.Meter) TransferQueueOption {
return func(tq *TransferQueue) {
tq.meter = m
}
}
func WithBatchSize(size int) transferQueueOption {
func WithBatchSize(size int) TransferQueueOption {
return func(tq *TransferQueue) { tq.batchSize = size }
}
func WithBufferDepth(depth int) transferQueueOption {
func WithBufferDepth(depth int) TransferQueueOption {
return func(tq *TransferQueue) { tq.bufferDepth = depth }
}
// newTransferQueue builds a TransferQueue, direction and underlying mechanism determined by adapter
func newTransferQueue(dir transfer.Direction, options ...transferQueueOption) *TransferQueue {
// NewTransferQueue builds a TransferQueue, direction and underlying mechanism determined by adapter
func NewTransferQueue(dir transfer.Direction, options ...TransferQueueOption) *TransferQueue {
q := &TransferQueue{
batchSize: defaultBatchSize,
bufferDepth: defaultBatchSize,

@ -1,4 +1,4 @@
package lfs
package tq
import (
"testing"