diff options
author | Joey Hess <joey@kitenet.net> | 2014-03-14 15:04:33 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-03-14 15:04:33 -0400 |
commit | f99d54176d97d099d82f073c6c18ab9f0c33399e (patch) | |
tree | 1e544c34dac042d585a4451ae50af07b9834fd90 /Logs | |
parent | b076926ad5c6dbf9353af7968b89f0553b0f4535 (diff) |
"standard" can now be used as a first-class keyword in preferred content expressions.
For example "standard or (include=otherdir/*)" or even "not standard"
Note that the implementation avoids any potential for loops (if a
standard preferred content expression itself mentioned standard).
This commit was sponsored by Jochen Bartl.
Diffstat (limited to 'Logs')
-rw-r--r-- | Logs/PreferredContent.hs | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/Logs/PreferredContent.hs b/Logs/PreferredContent.hs index 4b25ea094..2bc5f08d6 100644 --- a/Logs/PreferredContent.hs +++ b/Logs/PreferredContent.hs @@ -67,29 +67,25 @@ preferredContentMapLoad = do - versions of git-annex may add new features. Instead, parse errors - result in a Matcher that will always succeed. -} makeMatcher :: GroupMap -> M.Map UUID RemoteConfig -> UUID -> PreferredContentExpression -> FileMatcher -makeMatcher groupmap configmap u expr - | expr == "standard" = standardMatcher groupmap configmap u - | null (lefts tokens) = Utility.Matcher.generate $ rights tokens - | otherwise = matchAll +makeMatcher groupmap configmap u = go True where - tokens = exprParser groupmap configmap (Just u) expr - -{- Standard matchers are pre-defined for some groups. If none is defined, - - or a repository is in multiple groups with standard matchers, match all. -} -standardMatcher :: GroupMap -> M.Map UUID RemoteConfig -> UUID -> FileMatcher -standardMatcher groupmap configmap u = - maybe matchAll (makeMatcher groupmap configmap u . preferredContent) $ - getStandardGroup =<< u `M.lookup` groupsByUUID groupmap + go expandstandard expr + | null (lefts tokens) = Utility.Matcher.generate $ rights tokens + | otherwise = matchAll + where + tokens = exprParser matchstandard groupmap configmap (Just u) expr + matchstandard + | expandstandard = maybe matchAll (go False . preferredContent) $ + getStandardGroup =<< u `M.lookup` groupsByUUID groupmap + | otherwise = matchAll {- Checks if an expression can be parsed, if not returns Just error -} checkPreferredContentExpression :: PreferredContentExpression -> Maybe String -checkPreferredContentExpression expr - | expr == "standard" = Nothing - | otherwise = case parsedToMatcher tokens of - Left e -> Just e - Right _ -> Nothing +checkPreferredContentExpression expr = case parsedToMatcher tokens of + Left e -> Just e + Right _ -> Nothing where - tokens = exprParser emptyGroupMap M.empty Nothing expr + tokens = exprParser matchAll emptyGroupMap M.empty Nothing expr {- Puts a UUID in a standard group, and sets its preferred content to use - the standard expression for that group, unless something is already set. -} |