aboutsummaryrefslogtreecommitdiff
path: root/Logs/PreferredContent.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-19 16:09:21 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-19 16:09:21 -0400
commit5237b17193befdac87dfbeac9391e5ccad3049bb (patch)
treea107b4120c993103a0d37668ec9e6c9f3b28041e /Logs/PreferredContent.hs
parent5f835c769eb673b28d2d0211adfd6cbdf420b4bc (diff)
Replace "in=" with "present" in preferred content expressions
in= was problimatic in two ways. First, it referred to a remote by name, but preferred content expressions can be evaluated elsewhere, where that remote doesn't exist, or a different remote has the same name. This name lookup code could error out at runtime. Secondly, in= seemed pretty useless. in=here did not cause content to be gotten, but it did let present content be dropped. present is more useful, although "not present" is unstable and should be avoided.
Diffstat (limited to 'Logs/PreferredContent.hs')
-rw-r--r--Logs/PreferredContent.hs18
1 files changed, 9 insertions, 9 deletions
diff --git a/Logs/PreferredContent.hs b/Logs/PreferredContent.hs
index d3c120b70..f3454cc7d 100644
--- a/Logs/PreferredContent.hs
+++ b/Logs/PreferredContent.hs
@@ -88,7 +88,7 @@ makeMatcher groupmap u s
| null (lefts tokens) = Utility.Matcher.generate $ rights tokens
| otherwise = matchAll
where
- tokens = map (parseToken groupmap) (tokenizeMatcher s)
+ tokens = map (parseToken (Just u) groupmap) (tokenizeMatcher s)
{- Standard matchers are pre-defined for some groups. If none is defined,
- or a repository is in multiple groups with standard matchers, match all. -}
@@ -103,26 +103,26 @@ matchAll = Utility.Matcher.generate []
checkPreferredContentExpression :: String -> Maybe String
checkPreferredContentExpression s
| s == "standard" = Nothing
- | otherwise = case lefts $ map (parseToken emptyGroupMap) (tokenizeMatcher s) of
+ | otherwise = case lefts $ map (parseToken Nothing emptyGroupMap) (tokenizeMatcher s) of
[] -> Nothing
l -> Just $ unwords $ map ("Parse failure: " ++) l
-parseToken :: GroupMap -> String -> Either String (Utility.Matcher.Token MatchFiles)
-parseToken groupmap t
+parseToken :: (Maybe UUID) -> GroupMap -> String -> Either String (Utility.Matcher.Token MatchFiles)
+parseToken mu groupmap t
| any (== t) Utility.Matcher.tokens = Right $ Utility.Matcher.token t
- | otherwise = maybe (Left $ "near " ++ show t) use $ M.lookup k m
- where
- (k, v) = separate (== '=') t
- m = M.fromList
+ | t == "present" = use $ limitPresent mu
+ | otherwise = maybe (Left $ "near " ++ show t) use $ M.lookup k $
+ M.fromList
[ ("include", limitInclude)
, ("exclude", limitExclude)
- , ("in", limitIn)
, ("copies", limitCopies)
, ("inbackend", limitInBackend)
, ("largerthan", limitSize (>))
, ("smallerthan", limitSize (<))
, ("inallgroup", limitInAllGroup groupmap)
]
+ where
+ (k, v) = separate (== '=') t
use a = Utility.Matcher.Operation <$> a v
{- This is really dumb tokenization; there's no support for quoted values.