diff options
Diffstat (limited to 'PresenceLog.hs')
-rw-r--r-- | PresenceLog.hs | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/PresenceLog.hs b/PresenceLog.hs index e0c872997..5828f76af 100644 --- a/PresenceLog.hs +++ b/PresenceLog.hs @@ -85,7 +85,7 @@ readLog :: FilePath -> Annex [LogLine] readLog file = parseLog <$> Branch.get file parseLog :: String -> [LogLine] -parseLog s = filter parsable $ map read $ lines s +parseLog = filter parsable . map read . lines where -- some lines may be unparseable, avoid them parsable l = status l /= Undefined @@ -102,23 +102,18 @@ logNow s i = do {- Reads a log and returns only the info that is still in effect. -} currentLog :: FilePath -> Annex [String] -currentLog file = do - ls <- readLog file - return $ map info $ filterPresent ls +currentLog file = map info . filterPresent <$> readLog file {- Returns the info from LogLines that are in effect. -} filterPresent :: [LogLine] -> [LogLine] -filterPresent ls = filter (\l -> InfoPresent == status l) $ compactLog ls - -type LogMap = Map.Map String LogLine +filterPresent = filter (\l -> InfoPresent == status l) . compactLog {- Compacts a set of logs, returning a subset that contains the current - status. -} compactLog :: [LogLine] -> [LogLine] -compactLog = compactLog' Map.empty -compactLog' :: LogMap -> [LogLine] -> [LogLine] -compactLog' m [] = Map.elems m -compactLog' m (l:ls) = compactLog' (mapLog m l) ls +compactLog = Map.elems . foldl mapLog Map.empty + +type LogMap = Map.Map String LogLine {- Inserts a log into a map of logs, if the log has better (ie, newer) - information than the other logs in the map -} @@ -128,5 +123,6 @@ mapLog m l = then Map.insert i l m else m where - better = maybe True (\l' -> date l' <= date l) $ Map.lookup i m + better = maybe True newer $ Map.lookup i m + newer l' = date l' <= date l i = info l |