summaryrefslogtreecommitdiff
path: root/Remotes.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-13 22:59:43 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-13 22:59:43 -0400
commit912d10e78b725b4d3d4105a0ffe5696c21fc0e10 (patch)
treec29fb05fd0854f3e5b3bf96f011ae2d655d9ecab /Remotes.hs
parent89654751daacd9336c114bfc1c88c952dcc4ffe9 (diff)
implemented remotes config caching
Diffstat (limited to 'Remotes.hs')
-rw-r--r--Remotes.hs28
1 files changed, 26 insertions, 2 deletions
diff --git a/Remotes.hs b/Remotes.hs
index 399291467..13b87982c 100644
--- a/Remotes.hs
+++ b/Remotes.hs
@@ -2,10 +2,12 @@
module Remotes (
remotesList,
- remotesWithKey
+ remotesWithKey,
+ remoteEnsureGitConfigRead
) where
import Control.Monad.State (liftIO)
+import qualified Data.Map as Map
import Types
import GitRepo
import LocationLog
@@ -29,7 +31,7 @@ remotesWithKey key = do
remotesByCost :: Annex [GitRepo]
remotesByCost = do
g <- gitAnnex
- reposByCost $ gitConfigRemotes g
+ reposByCost $ gitRepoRemotes g
{- Orders a list of git repos by cost. -}
reposByCost :: [GitRepo] -> Annex [GitRepo]
@@ -58,3 +60,25 @@ repoCost r = do
where
config g r = gitConfig g (configkey r) ""
configkey r = "remote." ++ (gitRepoRemoteName r) ++ ".annex-cost"
+
+{- The git configs for the git repo's remotes is not read on startup
+ - because reading it may be expensive. This function ensures that it is
+ - read for a specified remote, and updates state. It returns the
+ - updated git repo also. -}
+remoteEnsureGitConfigRead :: GitRepo -> Annex GitRepo
+remoteEnsureGitConfigRead r = do
+ if (Map.null $ gitConfigMap r)
+ then do
+ r' <- liftIO $ gitConfigRead r
+ g <- gitAnnex
+ let l = gitRepoRemotes g
+ let g' = gitRepoRemotesAdd g $ exchange l r'
+ gitAnnexChange g'
+ return r'
+ else return r
+ where
+ exchange [] new = []
+ exchange (old:ls) new =
+ if ((gitRepoRemoteName old) == (gitRepoRemoteName new))
+ then new:(exchange ls new)
+ else old:(exchange ls new)