From 61000904d74ffd4745dd6808bcfa88289affc169 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 29 Oct 2011 18:47:53 -0400 Subject: [PATCH] refactor --- Command.hs | 10 ++++++++-- Command/Fsck.hs | 12 +++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Command.hs b/Command.hs index 4e312e66d4..32f6743f36 100644 --- a/Command.hs +++ b/Command.hs @@ -149,22 +149,28 @@ backendPairs a fs = runFilteredGen a snd (Backend.chooseBackends fs) runFilteredGen :: (b -> Annex (Maybe a)) -> (b -> FilePath) -> Annex [b] -> Annex [Annex (Maybe a)] runFilteredGen a d fs = do matcher <- Limit.getMatcher - liftM (map $ proc matcher) fs + runActions (proc matcher) fs where proc matcher v = do let f = d v ok <- matcher f if ok then a v else stop +runActions :: (b -> Annex (Maybe a)) -> Annex [b] -> Annex [Annex (Maybe a)] +runActions a fs = liftM (map a) fs + notAnnexed :: FilePath -> Annex (Maybe a) -> Annex (Maybe a) notAnnexed file a = maybe a (const $ return Nothing) =<< Backend.lookupFile file isAnnexed :: FilePath -> ((Key, Backend Annex) -> Annex (Maybe a)) -> Annex (Maybe a) isAnnexed file a = maybe (return Nothing) a =<< Backend.lookupFile file +isBareRepo :: Annex Bool +isBareRepo = Git.repoIsLocalBare <$> gitRepo + notBareRepo :: Annex a -> Annex a notBareRepo a = do - whenM (Git.repoIsLocalBare <$> gitRepo) $ + whenM isBareRepo $ error "You cannot run this subcommand in a bare repository." a diff --git a/Command/Fsck.hs b/Command/Fsck.hs index 6f184a760c..1f30d2eb63 100644 --- a/Command/Fsck.hs +++ b/Command/Fsck.hs @@ -13,7 +13,6 @@ import qualified Remote import qualified Types.Backend import qualified Types.Key import qualified Backend -import qualified Git import Annex.Content import Logs.Location import Logs.Trust @@ -44,14 +43,13 @@ perform key file backend numcopies = check {- To fsck a bare repository, fsck each key in the location log. -} withBarePresentKeys :: (Key -> CommandStart) -> CommandSeek -withBarePresentKeys a params = do - bare <- Git.repoIsLocalBare <$> gitRepo - if bare - then do +withBarePresentKeys a params = isBareRepo >>= go + where + go False = return [] + go True = do unless (null params) $ do error "fsck should be run without parameters in a bare repository" - liftM (map a) loggedKeys - else return [] + runActions a loggedKeys startBare :: Key -> CommandStart startBare key = case Backend.maybeLookupBackendName (Types.Key.keyBackendName key) of