skip local remotes that are not available (ie, not mounted)

With --fast, unavailable local remotes are filtered out of the fast set.
This way, if there are local remotes, --fast always acts only on them,
and if none are mounted, acts on nothing. This consistency is better
than --fast acting on different remotes depending on what's mounted.
This commit is contained in:
Joey Hess 2011-12-31 04:50:39 -04:00
parent 25e4b116c7
commit f0957426c5
3 changed files with 13 additions and 4 deletions

View file

@ -57,12 +57,13 @@ syncRemotes rs = do
then nub <$> pickfast then nub <$> pickfast
else wanted else wanted
where where
pickfast = (++) <$> listed <*> (fastest <$> available) pickfast = (++) <$> listed <*> (good =<< fastest <$> available)
wanted wanted
| null rs = available | null rs = good =<< available
| otherwise = listed | otherwise = listed
listed = mapM Remote.byName rs listed = mapM Remote.byName rs
available = filter nonspecial <$> Remote.enabledRemoteList available = filter nonspecial <$> Remote.enabledRemoteList
good = filterM $ Remote.Git.repoAvail . Types.Remote.repo
nonspecial r = Types.Remote.remotetype r == Remote.Git.remote nonspecial r = Types.Remote.remotetype r == Remote.Git.remote
fastest = fromMaybe [] . headMaybe . fastest = fromMaybe [] . headMaybe .
map snd . sort . M.toList . costmap map snd . sort . M.toList . costmap

View file

@ -29,7 +29,8 @@ read repo@(Repo { location = Dir d }) = do
bracket_ (changeWorkingDirectory d) (changeWorkingDirectory cwd) $ bracket_ (changeWorkingDirectory d) (changeWorkingDirectory cwd) $
pOpen ReadFromPipe "git" ["config", "--null", "--list"] $ pOpen ReadFromPipe "git" ["config", "--null", "--list"] $
hRead repo hRead repo
read r = assertLocal r $ error "internal" read r = assertLocal r $
error $ "internal error; trying to read config of " ++ show r
{- Reads git config from a handle and populates a repo with it. -} {- Reads git config from a handle and populates a repo with it. -}
hRead :: Repo -> Handle -> IO Repo hRead :: Repo -> Handle -> IO Repo

View file

@ -5,7 +5,7 @@
- Licensed under the GNU GPL version 3 or higher. - Licensed under the GNU GPL version 3 or higher.
-} -}
module Remote.Git (remote) where module Remote.Git (remote, repoAvail) where
import Control.Exception.Extensible import Control.Exception.Extensible
import qualified Data.Map as M import qualified Data.Map as M
@ -164,6 +164,13 @@ inAnnex r key
dispatch (Right Nothing) = unknown dispatch (Right Nothing) = unknown
unknown = Left $ "unable to check " ++ Git.repoDescribe r unknown = Left $ "unable to check " ++ Git.repoDescribe r
{- Checks inexpensively if a repository is available for use. -}
repoAvail :: Git.Repo -> Annex Bool
repoAvail r
| Git.repoIsHttp r = return True
| Git.repoIsUrl r = return True
| otherwise = liftIO $ catchBoolIO $ onLocal r $ return True
{- Runs an action on a local repository inexpensively, by making an annex {- Runs an action on a local repository inexpensively, by making an annex
- monad using that repository. -} - monad using that repository. -}
onLocal :: Git.Repo -> Annex a -> IO a onLocal :: Git.Repo -> Annex a -> IO a