From cbaebf538a8659193fb3dbb4f32e0f918a385af3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 13 Feb 2012 23:42:44 -0400 Subject: rework git check-attr interface Now gitattributes are looked up, efficiently, in only the places that really need them, using the same approach used for cat-file. The old CheckAttr code seemed very fragile, in the way it streamed files through git check-attr. I actually found that cad8824852aa0623dc41eac02a9e2bae47d88ec4 was still deadlocking with ghc 7.4, at the end of adding a lot of files. This should fix that problem, and avoid future ones. The best part is that this removes withAttrFilesInGit and withNumCopies, which were complicated Seek methods, as well as simplfying the types for several other Seek methods that had a Backend tupled in. --- Backend.hs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'Backend.hs') diff --git a/Backend.hs b/Backend.hs index e351bb3b2..50c89ecc5 100644 --- a/Backend.hs +++ b/Backend.hs @@ -6,12 +6,11 @@ -} module Backend ( - BackendFile, list, orderedList, genKey, lookupFile, - chooseBackends, + chooseBackend, lookupBackendName, maybeLookupBackendName ) where @@ -22,6 +21,7 @@ import Common.Annex import qualified Git.Config import qualified Git.CheckAttr import qualified Annex +import Annex.CheckAttr import Types.Key import qualified Types.Backend as B @@ -93,20 +93,15 @@ lookupFile file = do bname ++ ")" return Nothing -type BackendFile = (Maybe Backend, FilePath) - -{- Looks up the backends that should be used for each file in a list. +{- Looks up the backend that should be used for a file. - That can be configured on a per-file basis in the gitattributes file. -} -chooseBackends :: [FilePath] -> Annex [BackendFile] -chooseBackends fs = Annex.getState Annex.forcebackend >>= go +chooseBackend :: FilePath -> Annex (Maybe Backend) +chooseBackend f = Annex.getState Annex.forcebackend >>= go where - go Nothing = do - pairs <- inRepo $ Git.CheckAttr.lookup "annex.backend" fs - return $ map (\(f,b) -> (maybeLookupBackendName b, f)) pairs - go (Just _) = do - l <- orderedList - return $ map (\f -> (Just $ Prelude.head l, f)) fs + go Nothing = maybeLookupBackendName <$> + checkAttr "annex.backend" f + go (Just _) = Just . Prelude.head <$> orderedList {- Looks up a backend by name. May fail if unknown. -} lookupBackendName :: String -> Backend -- cgit v1.2.3