aboutsummaryrefslogtreecommitdiff
path: root/Utility/Misc.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-04 15:48:59 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-04 16:00:19 -0400
commit9214a810faa300862d3d847c9ee425e5605bccef (patch)
tree4c69e8fa7bb7bc0bc107b328b817b6e7c6c9c4e3 /Utility/Misc.hs
parenta0e16e34466008221ad2431ca001ddb536b88b84 (diff)
added preferred-content log, and allow editing it with vicfg
This includes a full parser for the boolean expressions in the log, that compiles them into Matchers. Those matchers are not used yet. A complication is that matching against an expression should never crash git-annex with an error. Instead, vicfg checks that the expressions parse. If a bad expression (or an expression understood by some future git-annex version) gets into the log, it'll be ignored. Most of the code in Limit couldn't fail anyway, but I did have to make limitCopies check its parameter first, and return an error if it's bad, rather than erroring at runtime.
Diffstat (limited to 'Utility/Misc.hs')
-rw-r--r--Utility/Misc.hs8
1 files changed, 6 insertions, 2 deletions
diff --git a/Utility/Misc.hs b/Utility/Misc.hs
index 349b20efe..88d210de6 100644
--- a/Utility/Misc.hs
+++ b/Utility/Misc.hs
@@ -42,11 +42,15 @@ firstLine = takeWhile (/= '\n')
{- Splits a list into segments that are delimited by items matching
- a predicate. (The delimiters are not included in the segments.) -}
segment :: (a -> Bool) -> [a] -> [[a]]
-segment p l = map reverse $ go [] [] l
+segment p = filter (not . all p) . segmentDelim p
+
+{- Includes the delimiters as segments of their own. -}
+segmentDelim :: (a -> Bool) -> [a] -> [[a]]
+segmentDelim p l = map reverse $ go [] [] l
where
go c r [] = reverse $ c:r
go c r (i:is)
- | p i = go [] (c:r) is
+ | p i = go [] ([i]:c:r) is
| otherwise = go (i:c) r is
{- Given two orderings, returns the second if the first is EQ and returns