summaryrefslogtreecommitdiff
path: root/Logs/PreferredContent.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-08 15:18:58 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-08 15:18:58 -0400
commitc452c70ef88197b152c1552563daa6a79e88e91f (patch)
tree27b2031fdb79d183a8abef7ca837cb25a0ecd3a0 /Logs/PreferredContent.hs
parent1ccd0ed1e6541534626673dc5dbdd97c9ab9ca49 (diff)
add --ingroup limit
Diffstat (limited to 'Logs/PreferredContent.hs')
-rw-r--r--Logs/PreferredContent.hs25
1 files changed, 15 insertions, 10 deletions
diff --git a/Logs/PreferredContent.hs b/Logs/PreferredContent.hs
index 3da5cc329..26e0d7073 100644
--- a/Logs/PreferredContent.hs
+++ b/Logs/PreferredContent.hs
@@ -25,6 +25,8 @@ import Limit
import qualified Utility.Matcher
import Annex.UUID
import Git.FilePath
+import Types.Group
+import Logs.Group
{- Filename of preferred-content.log. -}
preferredContentLog :: FilePath
@@ -54,11 +56,12 @@ isPreferredContent mu notpresent file = do
{- Read the preferredContentLog into a map. The map is cached for speed. -}
preferredContentMap :: Annex Annex.PreferredContentMap
preferredContentMap = do
+ groupmap <- groupMap
cached <- Annex.getState Annex.preferredcontentmap
case cached of
Just m -> return m
Nothing -> do
- m <- simpleMap . parseLog (Just . makeMatcher)
+ m <- simpleMap . parseLog (Just . makeMatcher groupmap)
<$> Annex.Branch.get preferredContentLog
Annex.changeState $ \s -> s { Annex.preferredcontentmap = Just m }
return m
@@ -71,21 +74,22 @@ preferredContentMapRaw = simpleMap . parseLog Just
- because the configuration is shared amoung repositories and newer
- versions of git-annex may add new features. Instead, parse errors
- result in a Matcher that will always succeed. -}
-makeMatcher :: String -> Utility.Matcher.Matcher MatchFiles
-makeMatcher s
+makeMatcher :: GroupMap -> String -> Utility.Matcher.Matcher MatchFiles
+makeMatcher groupmap s
| null (lefts tokens) = Utility.Matcher.generate $ rights tokens
| otherwise = Utility.Matcher.generate []
where
- tokens = map parseToken $ tokenizeMatcher s
+ tokens = map (parseToken groupmap) (tokenizeMatcher s)
{- Checks if an expression can be parsed, if not returns Just error -}
checkPreferredContentExpression :: String -> Maybe String
-checkPreferredContentExpression s = case lefts $ map parseToken $ tokenizeMatcher s of
- [] -> Nothing
- l -> Just $ unwords $ map ("Parse failure: " ++) l
+checkPreferredContentExpression s =
+ case lefts $ map (parseToken emptyGroupMap) (tokenizeMatcher s) of
+ [] -> Nothing
+ l -> Just $ unwords $ map ("Parse failure: " ++) l
-parseToken :: String -> Either String (Utility.Matcher.Token MatchFiles)
-parseToken t
+parseToken :: GroupMap -> String -> Either String (Utility.Matcher.Token MatchFiles)
+parseToken groupmap t
| any (== t) Utility.Matcher.tokens = Right $ Utility.Matcher.token t
| otherwise = maybe (Left $ "near " ++ show t) use $ M.lookup k m
where
@@ -95,9 +99,10 @@ parseToken t
, ("exclude", limitExclude)
, ("in", limitIn)
, ("copies", limitCopies)
- , ("backend", limitInBackend)
+ , ("inbackend", limitInBackend)
, ("largerthan", limitSize (>))
, ("smallerthan", limitSize (<))
+ , ("ingroup", limitInGroup groupmap)
]
use a = Utility.Matcher.Operation <$> a v