This commit is contained in:
Joey Hess 2011-09-18 23:09:40 -04:00
parent 4f1fea1a85
commit c31a6a9e10

View file

@ -115,20 +115,11 @@ withAttrFilesInGit :: String -> ((FilePath, String) -> CommandStart) -> CommandS
withAttrFilesInGit attr a params = do withAttrFilesInGit attr a params = do
repo <- Annex.gitRepo repo <- Annex.gitRepo
files <- liftIO $ runPreserveOrder (LsFiles.inRepo repo) params files <- liftIO $ runPreserveOrder (LsFiles.inRepo repo) params
run $ liftIO $ Git.checkAttr repo attr files runFilteredGen a fst $ 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
withNumCopies :: (FilePath -> Maybe Int -> CommandStart) -> CommandSeek withNumCopies :: (FilePath -> Maybe Int -> CommandStart) -> CommandSeek
withNumCopies a params = withAttrFilesInGit "annex.numcopies" go params withNumCopies a params = withAttrFilesInGit "annex.numcopies" go params
where where
go (file, v) = do go (file, v) = a file (readMaybe v)
let numcopies = readMaybe v
a file numcopies
withBackendFilesInGit :: (BackendFile -> CommandStart) -> CommandSeek withBackendFilesInGit :: (BackendFile -> CommandStart) -> CommandSeek
withBackendFilesInGit a params = do withBackendFilesInGit a params = do
repo <- Annex.gitRepo repo <- Annex.gitRepo
@ -174,22 +165,20 @@ withNothing a [] = return [a]
withNothing _ _ = error "This command takes no parameters." withNothing _ _ = error "This command takes no parameters."
runFiltered :: (FilePath -> Annex (Maybe a)) -> Annex [FilePath] -> Annex [Annex (Maybe a)] runFiltered :: (FilePath -> Annex (Maybe a)) -> Annex [FilePath] -> Annex [Annex (Maybe a)]
runFiltered a fs = do runFiltered a fs = runFilteredGen a id fs
backendPairs :: (BackendFile -> CommandStart) -> CommandSeek
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 matcher <- Limit.getMatcher
liftM (map $ proc matcher) fs liftM (map $ proc matcher) fs
where where
proc matcher f = do proc matcher v = do
let f = d v
ok <- matcher f ok <- matcher f
if ok then a f else stop if ok then a v else stop
backendPairs :: (BackendFile -> CommandStart) -> CommandSeek
backendPairs a fs = do
matcher <- Limit.getMatcher
liftM (map $ proc matcher) (Backend.chooseBackends fs)
where
proc matcher p@(_, f) = do
ok <- matcher f
if ok then a p else stop
{- filter out symlinks -} {- filter out symlinks -}
notSymlink :: FilePath -> IO Bool notSymlink :: FilePath -> IO Bool