summaryrefslogtreecommitdiff
path: root/Remote.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-06-13 22:19:44 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-06-13 22:19:44 -0400
commitf547277b751d81f516a638bc281735fa1946b17d (patch)
tree6c17f7ae514409e953bb74309478c74c04c7c3ba /Remote.hs
parent66f5b390fe761946280c8999648d13e917fba45b (diff)
Allow --trust etc to specify a repository by name, for temporarily trusting repositories that are not configured remotes.
Diffstat (limited to 'Remote.hs')
-rw-r--r--Remote.hs29
1 files changed, 22 insertions, 7 deletions
diff --git a/Remote.hs b/Remote.hs
index 2e956cb81..d975c2404 100644
--- a/Remote.hs
+++ b/Remote.hs
@@ -34,7 +34,7 @@ module Remote (
) where
import Control.Monad.State (liftIO)
-import Control.Monad (when, liftM, filterM)
+import Control.Monad (filterM)
import Data.List
import qualified Data.Map as M
import Data.Maybe
@@ -91,20 +91,35 @@ genList = do
{- Looks up a remote by name. (Or by UUID.) -}
byName :: String -> Annex (Remote Annex)
-byName "" = error "no remote specified"
byName n = do
+ res <- byName' n
+ case res of
+ Left e -> error e
+ Right r -> return r
+byName' :: String -> Annex (Either String (Remote Annex))
+byName' "" = return $ Left "no remote specified"
+byName' n = do
allremotes <- genList
let match = filter matching allremotes
- when (null match) $ error $
- "there is no git remote named \"" ++ n ++ "\""
- return $ head match
+ if (null match)
+ then return $ Left $ "there is no git remote named \"" ++ n ++ "\""
+ else return $ Right $ head match
where
matching r = n == name r || n == uuid r
-{- Looks up a remote by name (or by UUID), and returns its UUID. -}
+{- Looks up a remote by name (or by UUID, or even by description),
+ - and returns its UUID. -}
nameToUUID :: String -> Annex UUID
nameToUUID "." = getUUID =<< Annex.gitRepo -- special case for current repo
-nameToUUID n = liftM uuid (byName n)
+nameToUUID n = do
+ res <- byName' n
+ case res of
+ Left e -> return . (maybe (error e) id) =<< byDescription
+ Right r -> return $ uuid r
+ where
+ byDescription = return . M.lookup n . invertMap =<< uuidMap
+ invertMap = M.fromList . map swap . M.toList
+ swap (a, b) = (b, a)
{- Filters a list of remotes to ones that have the listed uuids. -}
remotesWithUUID :: [Remote Annex] -> [UUID] -> [Remote Annex]