tq: revert Direction back to int, add String() conversion func
This commit is contained in:
parent
924befe2f0
commit
7c02e2217c
@ -265,7 +265,7 @@ func callBatchApi(manifest *tq.Manifest, dir tq.Direction, objs []TestObject) ([
|
||||
apiobjs = append(apiobjs, &tq.Transfer{Oid: o.Oid, Size: o.Size})
|
||||
}
|
||||
|
||||
return tq.Batch(dir, manifest, "origin", apiobjs)
|
||||
return tq.Batch(manifest, dir, "origin", apiobjs)
|
||||
}
|
||||
|
||||
// Combine 2 slices into one by "randomly" interleaving
|
||||
|
@ -25,13 +25,13 @@ type batchResponse struct {
|
||||
Objects []*Transfer `json:"objects"`
|
||||
}
|
||||
|
||||
func Batch(dir Direction, m *Manifest, remote string, objects []*Transfer) ([]*Transfer, error) {
|
||||
func Batch(m *Manifest, dir Direction, remote string, objects []*Transfer) ([]*Transfer, error) {
|
||||
if len(objects) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
breq := &batchRequest{
|
||||
Operation: string(dir),
|
||||
Operation: dir.String(),
|
||||
Objects: objects,
|
||||
TransferAdapterNames: m.GetAdapterNames(dir),
|
||||
}
|
||||
|
@ -10,13 +10,24 @@ import (
|
||||
"github.com/git-lfs/git-lfs/lfsapi"
|
||||
)
|
||||
|
||||
type Direction string
|
||||
type Direction int
|
||||
|
||||
const (
|
||||
Upload = Direction("upload")
|
||||
Download = Direction("download")
|
||||
Upload = Direction(iota)
|
||||
Download = Direction(iota)
|
||||
)
|
||||
|
||||
func (d Direction) String() string {
|
||||
switch d {
|
||||
case Download:
|
||||
return "download"
|
||||
case Upload:
|
||||
return "upload"
|
||||
default:
|
||||
return "<unknown>"
|
||||
}
|
||||
}
|
||||
|
||||
type Transfer struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Oid string `json:"oid,omitempty"`
|
||||
|
@ -283,7 +283,7 @@ func (q *TransferQueue) enqueueAndCollectRetriesFor(batch batch) (batch, error)
|
||||
tracerx.Printf("tq: sending batch of size %d", len(batch))
|
||||
|
||||
bReq := &batchRequest{
|
||||
Operation: q.transferKind(),
|
||||
Operation: q.direction.String(),
|
||||
Objects: batch.ToTransfers(),
|
||||
TransferAdapterNames: q.manifest.GetAdapterNames(q.direction),
|
||||
}
|
||||
@ -340,7 +340,7 @@ func (q *TransferQueue) enqueueAndCollectRetriesFor(batch batch) (batch, error)
|
||||
} else {
|
||||
tr := newTransfer(o, t.Name, t.Path)
|
||||
|
||||
if _, err := tr.Actions.Get(q.transferKind()); err != nil {
|
||||
if _, err := tr.Actions.Get(q.direction.String()); err != nil {
|
||||
// XXX(taylor): duplication
|
||||
if q.canRetryObject(tr.Oid, err) {
|
||||
q.rc.Increment(tr.Oid)
|
||||
@ -509,14 +509,6 @@ func (q *TransferQueue) Skip(size int64) {
|
||||
q.meter.Skip(size)
|
||||
}
|
||||
|
||||
func (q *TransferQueue) transferKind() string {
|
||||
if q.direction == Download {
|
||||
return "download"
|
||||
} else {
|
||||
return "upload"
|
||||
}
|
||||
}
|
||||
|
||||
func (q *TransferQueue) ensureAdapterBegun(e lfsapi.Endpoint) error {
|
||||
q.adapterInitMutex.Lock()
|
||||
defer q.adapterInitMutex.Unlock()
|
||||
@ -527,7 +519,7 @@ 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.transferKind(), name, read, total, current)
|
||||
q.meter.TransferBytes(q.direction.String(), name, read, total, current)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user