From 5c46685ab3bc1f579e55d764d5887b7f4a208d65 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 5 Mar 2013 15:39:42 -0400 Subject: two types of byName Clean up from 5123a1a83aa3b954fe67629508bab5ccea0e4148. In some cases, looking up a remote by name even though it has no UUID is desirable. This includes git annex sync, which can operate on remotes without an annex, and XMPP pairing, which runs addRemote (with calls byName) before the UUID of the XMPP remote has been configured in git. --- Remote.hs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'Remote.hs') diff --git a/Remote.hs b/Remote.hs index 22e304de3..4f8b7cf6a 100644 --- a/Remote.hs +++ b/Remote.hs @@ -24,6 +24,7 @@ module Remote ( remoteMap, uuidDescriptions, byName, + byNameWithUUID, byCost, prettyPrintUUIDs, prettyListUUIDs, @@ -72,18 +73,27 @@ addName desc n | otherwise = n ++ " (" ++ desc ++ ")" {- When a name is specified, looks up the remote matching that name. - - (Or it can be a UUID.) Only finds currently configured git remotes. -} + - (Or it can be a UUID.) -} byName :: Maybe String -> Annex (Maybe Remote) byName Nothing = return Nothing byName (Just n) = either error Just <$> byName' n + +{- Like byName, but the remote must have a configured UUID. -} +byNameWithUUID :: Maybe String -> Annex (Maybe Remote) +byNameWithUUID n = do + v <- byName n + return $ checkuuid <$> v + where + checkuuid r + | uuid r == NoUUID = error $ "cannot determine uuid for " ++ name r + | otherwise = r + byName' :: String -> Annex (Either String Remote) byName' "" = return $ Left "no remote specified" byName' n = handle . filter matching <$> remoteList where handle [] = Left $ "there is no available git remote named \"" ++ n ++ "\"" - handle (match:_) - | uuid match == NoUUID = Left $ "cannot determine uuid for " ++ name match - | otherwise = Right match + handle (match:_) = Right match matching r = n == name r || toUUID n == uuid r {- Looks up a remote by name (or by UUID, or even by description), -- cgit v1.2.3