From 7c02e2217cfcb40e66369dcd757f6a85ed6e37c7 Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Mon, 9 Jan 2017 12:52:36 -0700 Subject: [PATCH] tq: revert Direction back to int, add String() conversion func --- test/git-lfs-test-server-api/main.go | 2 +- tq/api.go | 4 ++-- tq/transfer.go | 17 ++++++++++++++--- tq/transfer_queue.go | 14 +++----------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/test/git-lfs-test-server-api/main.go b/test/git-lfs-test-server-api/main.go index 4f600b02..03f300e8 100644 --- a/test/git-lfs-test-server-api/main.go +++ b/test/git-lfs-test-server-api/main.go @@ -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 diff --git a/tq/api.go b/tq/api.go index a4ee240f..51d5b3e6 100644 --- a/tq/api.go +++ b/tq/api.go @@ -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), } diff --git a/tq/transfer.go b/tq/transfer.go index 6cf3080b..462358b9 100644 --- a/tq/transfer.go +++ b/tq/transfer.go @@ -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 "" + } +} + type Transfer struct { Name string `json:"name,omitempty"` Oid string `json:"oid,omitempty"` diff --git a/tq/transfer_queue.go b/tq/transfer_queue.go index c23065f3..143208d3 100644 --- a/tq/transfer_queue.go +++ b/tq/transfer_queue.go @@ -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 }