From e9b6c350b15a93d82affadfabca18b3e95840cb1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 17 Apr 2014 18:03:39 -0400 Subject: replace (Key, Backend) with Key Only fsck and reinject and the test suite used the Backend, and they can look it up as needed from the Key. This simplifies the code and also speeds it up. There is a small behavior change here. Before, all commands would warn when acting on an annexed file with an unknown backend. Now, only fsck and reinject show that warning. --- Backend.hs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'Backend.hs') diff --git a/Backend.hs b/Backend.hs index 38314687a..dded0d005 100644 --- a/Backend.hs +++ b/Backend.hs @@ -1,6 +1,6 @@ {- git-annex key/value backends - - - Copyright 2010,2013 Joey Hess + - Copyright 2010-2014 Joey Hess - - Licensed under the GNU GPL version 3 or higher. -} @@ -10,6 +10,7 @@ module Backend ( orderedList, genKey, lookupFile, + getBackend, isAnnexLink, chooseBackend, lookupBackendName, @@ -74,7 +75,7 @@ genKey' (b:bs) source = do | c == '\n' = '_' | otherwise = c -{- Looks up the key and backend corresponding to an annexed file, +{- Looks up the key corresponding to an annexed file, - by examining what the file links to. - - In direct mode, there is often no link on disk, in which case @@ -82,7 +83,7 @@ genKey' (b:bs) source = do - on disk still takes precedence over what was committed to git in direct - mode. -} -lookupFile :: FilePath -> Annex (Maybe (Key, Backend)) +lookupFile :: FilePath -> Annex (Maybe Key) lookupFile file = do mkey <- isAnnexLink file case mkey of @@ -92,14 +93,15 @@ lookupFile file = do , return Nothing ) where - makeret k = let bname = keyBackendName k in - case maybeLookupBackendName bname of - Just backend -> return $ Just (k, backend) - Nothing -> do - warning $ - "skipping " ++ file ++ - " (unknown backend " ++ bname ++ ")" - return Nothing + makeret k = return $ Just k + +getBackend :: FilePath -> Key -> Annex (Maybe Backend) +getBackend file k = let bname = keyBackendName k in + case maybeLookupBackendName bname of + Just backend -> return $ Just backend + Nothing -> do + warning $ "skipping " ++ file ++ " (unknown backend " ++ bname ++ ")" + return Nothing {- Looks up the backend that should be used for a file. - That can be configured on a per-file basis in the gitattributes file. -} -- cgit v1.2.3