aboutsummaryrefslogtreecommitdiff
path: root/Annex/FileMatcher.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-01-23 16:37:08 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-01-23 16:44:02 -0400
commit5112650348f6bf04cebe1fb97ed900b24e4aaac1 (patch)
tree4e207b96021812213d237e68d156e2e0bbdf32c3 /Annex/FileMatcher.hs
parent425c6ddfcd84b6bf26f3a277d010df1fb6b018da (diff)
fix transfers of key with no associated file
Several places assumed this would not happen, and when the AssociatedFile was Nothing, did nothing. As part of this, preferred content checks pass the Key around. Note that checkMatcher is sometimes now called with Just Key and Just File. It currently constructs a FileMatcher, ignoring the Key. However, if it constructed a FileKeyMatcher, which contained both, then it might be possible to speed up parts of Limit, which currently call the somewhat expensive lookupFileKey to get the Key. I have not made this optimisation yet, because I am not sure if the key is always the same. Will need some significant checking to satisfy myself that's the case..
Diffstat (limited to 'Annex/FileMatcher.hs')
-rw-r--r--Annex/FileMatcher.hs29
1 files changed, 18 insertions, 11 deletions
diff --git a/Annex/FileMatcher.hs b/Annex/FileMatcher.hs
index c144920cf..158f3e787 100644
--- a/Annex/FileMatcher.hs
+++ b/Annex/FileMatcher.hs
@@ -1,6 +1,6 @@
{- git-annex file matching
-
- - Copyright 2012, 2013 Joey Hess <joey@kitenet.net>
+ - Copyright 2012-2014 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -28,18 +28,25 @@ import qualified Data.Set as S
type FileMatcher = Matcher MatchFiles
checkFileMatcher :: FileMatcher -> FilePath -> Annex Bool
-checkFileMatcher matcher file = checkFileMatcher' matcher file S.empty True
+checkFileMatcher matcher file = checkMatcher matcher Nothing (Just file) S.empty True
-checkFileMatcher' :: FileMatcher -> FilePath -> AssumeNotPresent -> Bool -> Annex Bool
-checkFileMatcher' matcher file notpresent def
+checkMatcher :: FileMatcher -> Maybe Key -> AssociatedFile -> AssumeNotPresent -> Bool -> Annex Bool
+checkMatcher matcher mkey afile notpresent def
| isEmpty matcher = return def
- | otherwise = do
- matchfile <- getTopFilePath <$> inRepo (toTopFilePath file)
- let mi = MatchingFile $ FileInfo
- { matchFile = matchfile
- , relFile = file
- }
- matchMrun matcher $ \a -> a notpresent mi
+ | otherwise = case (mkey, afile) of
+ (_, Just file) -> go =<< fileMatchInfo file
+ (Just key, _) -> go (MatchingKey key)
+ _ -> return def
+ where
+ go mi = matchMrun matcher $ \a -> a notpresent mi
+
+fileMatchInfo :: FilePath -> Annex MatchInfo
+fileMatchInfo file = do
+ matchfile <- getTopFilePath <$> inRepo (toTopFilePath file)
+ return $ MatchingFile $ FileInfo
+ { matchFile = matchfile
+ , relFile = file
+ }
matchAll :: FileMatcher
matchAll = generate []