summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-09-18 23:09:40 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-09-18 23:09:40 -0400
commitc31a6a9e100d9d9a822fd5e93f2a59d1562db579 (patch)
tree830e693b7e3355385b64013e4b47cf74d336bdbc
parent4f1fea1a856a2c82ed200e805bb18e9f9aaaa67b (diff)
refactor
-rw-r--r--Command.hs33
1 files changed, 11 insertions, 22 deletions
diff --git a/Command.hs b/Command.hs
index 3cfff268c..a568da33b 100644
--- a/Command.hs
+++ b/Command.hs
@@ -115,20 +115,11 @@ withAttrFilesInGit :: String -> ((FilePath, String) -> CommandStart) -> CommandS
withAttrFilesInGit attr a params = do
repo <- Annex.gitRepo
files <- liftIO $ runPreserveOrder (LsFiles.inRepo repo) params
- run $ liftIO $ Git.checkAttr repo attr files
- where
- run fs = do
- matcher <- Limit.getMatcher
- liftM (map $ proc matcher) fs
- proc matcher p@(f, _) = do
- ok <- matcher f
- if ok then a p else stop
+ runFilteredGen a fst $ liftIO $ Git.checkAttr repo attr files
withNumCopies :: (FilePath -> Maybe Int -> CommandStart) -> CommandSeek
withNumCopies a params = withAttrFilesInGit "annex.numcopies" go params
where
- go (file, v) = do
- let numcopies = readMaybe v
- a file numcopies
+ go (file, v) = a file (readMaybe v)
withBackendFilesInGit :: (BackendFile -> CommandStart) -> CommandSeek
withBackendFilesInGit a params = do
repo <- Annex.gitRepo
@@ -174,22 +165,20 @@ withNothing a [] = return [a]
withNothing _ _ = error "This command takes no parameters."
runFiltered :: (FilePath -> Annex (Maybe a)) -> Annex [FilePath] -> Annex [Annex (Maybe a)]
-runFiltered a fs = do
- matcher <- Limit.getMatcher
- liftM (map $ proc matcher) fs
- where
- proc matcher f = do
- ok <- matcher f
- if ok then a f else stop
+runFiltered a fs = runFilteredGen a id fs
backendPairs :: (BackendFile -> CommandStart) -> CommandSeek
-backendPairs a fs = do
+backendPairs a fs = runFilteredGen a snd (Backend.chooseBackends fs)
+
+runFilteredGen :: (a1 -> Annex (Maybe a)) -> (a1 -> FilePath) -> Annex [a1] -> Annex [Annex (Maybe a)]
+runFilteredGen a d fs = do
matcher <- Limit.getMatcher
- liftM (map $ proc matcher) (Backend.chooseBackends fs)
+ liftM (map $ proc matcher) fs
where
- proc matcher p@(_, f) = do
+ proc matcher v = do
+ let f = d v
ok <- matcher f
- if ok then a p else stop
+ if ok then a v else stop
{- filter out symlinks -}
notSymlink :: FilePath -> IO Bool