summaryrefslogtreecommitdiff
path: root/Command/TransferKeys.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-05-19 16:19:33 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-05-19 16:19:33 -0400
commitf5480e80f4e3f3299a4d738f413460c0dbff35f8 (patch)
tree31a0e669f538a596222efa08b759380a9538be20 /Command/TransferKeys.hs
parent897d9fb51740379c824ccf53bfb86a31c771ab39 (diff)
assistant: When there are multiple remotes giving different ways to access the same repository, honor remote cost settings and use the cheapest available.
Note that TransferInfo does not always contain the Remote, although any transfer added to the TransferQueue does have a Remote in its TransferInfo. The transferkeys command still accepts a UUID, which is useful to handle upgrades, where an old assistant version runs the new transferkeys. This commit was sponsored by Kalle Svensson.
Diffstat (limited to 'Command/TransferKeys.hs')
-rw-r--r--Command/TransferKeys.hs29
1 files changed, 16 insertions, 13 deletions
diff --git a/Command/TransferKeys.hs b/Command/TransferKeys.hs
index 05129005b..fba0e6593 100644
--- a/Command/TransferKeys.hs
+++ b/Command/TransferKeys.hs
@@ -17,6 +17,7 @@ import Annex.Transfer
import qualified Remote
import Types.Key
import Utility.SimpleProtocol (ioHandles)
+import Git.Types (RemoteName)
data TransferRequest = TransferRequest Direction Remote Key AssociatedFile
@@ -56,13 +57,13 @@ runRequests readh writeh a = do
fileEncoding writeh
go =<< readrequests
where
- go (d:u:k:f:rest) = do
- case (deserialize d, deserialize u, deserialize k, deserialize f) of
- (Just direction, Just uuid, Just key, Just file) -> do
- mremote <- Remote.remoteFromUUID uuid
+ go (d:rn:k:f:rest) = do
+ case (deserialize d, deserialize rn, deserialize k, deserialize f) of
+ (Just direction, Just remotename, Just key, Just file) -> do
+ mremote <- Remote.byName' remotename
case mremote of
- Nothing -> sendresult False
- Just remote -> sendresult =<< a
+ Left _ -> sendresult False
+ Right remote -> sendresult =<< a
(TransferRequest direction remote key file)
_ -> sendresult False
go rest
@@ -75,13 +76,15 @@ runRequests readh writeh a = do
hPutStrLn writeh $ serialize b
hFlush writeh
-sendRequest :: Transfer -> AssociatedFile -> Handle -> IO ()
-sendRequest t f h = do
+sendRequest :: Transfer -> TransferInfo -> Handle -> IO ()
+sendRequest t info h = do
hPutStr h $ intercalate fieldSep
[ serialize (transferDirection t)
- , serialize (transferUUID t)
+ , maybe (serialize (fromUUID (transferUUID t)))
+ (serialize . Remote.name)
+ (transferRemote info)
, serialize (transferKey t)
- , serialize f
+ , serialize (associatedFile info)
, "" -- adds a trailing null
]
hFlush h
@@ -116,9 +119,9 @@ instance TCSerialized AssociatedFile where
deserialize "" = Just Nothing
deserialize f = Just $ Just f
-instance TCSerialized UUID where
- serialize = fromUUID
- deserialize = Just . toUUID
+instance TCSerialized RemoteName where
+ serialize n = n
+ deserialize n = Just n
instance TCSerialized Key where
serialize = key2file