summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-03-27 16:24:46 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-03-27 16:24:46 -0400
commit3470260a8500b42f805b8263af9c73b99706bb92 (patch)
tree1b962acc9007fa6d50063032fd07ed7b0d224819
parentf30320aa75d6fa590f60030f13df6b3899816196 (diff)
clean up remote list generation to only run once
-rw-r--r--Remote.hs21
1 files changed, 14 insertions, 7 deletions
diff --git a/Remote.hs b/Remote.hs
index 078a603bb..f4b56846b 100644
--- a/Remote.hs
+++ b/Remote.hs
@@ -6,7 +6,6 @@
-}
module Remote (
- generate,
keyPossibilities,
remotesWithUUID,
remotesWithoutUUID
@@ -27,11 +26,19 @@ import LocationLog
generators :: [Annex [Remote Annex]]
generators = [Remote.GitRemote.generate]
-{- generates a list of all available Remotes -}
-generate :: Annex [Remote Annex]
-generate = do
- lists <- sequence generators
- return $ concat lists
+{- Builds a list of all available Remotes.
+ - Since doing so can be expensive, the list is cached in the Annex. -}
+genList :: Annex [Remote Annex]
+genList = do
+ liftIO $ putStrLn "Remote.genList"
+ rs <- Annex.getState Annex.remotes
+ if null rs
+ then do
+ lists <- sequence generators
+ let rs' = concat lists
+ Annex.changeState $ \s -> s { Annex.remotes = rs' }
+ return rs'
+ else return rs
{- Filters a list of remotes to ones that have the listed uuids. -}
remotesWithUUID :: [Remote Annex] -> [UUID] -> [Remote Annex]
@@ -60,7 +67,7 @@ keyPossibilities key = do
let validtrusteduuids = intersect validuuids trusted
-- remotes that match uuids that have the key
- allremotes <- generate
+ allremotes <- genList
let validremotes = remotesWithUUID allremotes validuuids
return (sort validremotes, validtrusteduuids)