diff options
author | Joey Hess <joey@kitenet.net> | 2011-09-28 02:35:23 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-09-28 02:35:23 -0400 |
commit | 1c9c9a0cee33b63e9147863b95e570a8cc349304 (patch) | |
tree | f8de8957ec52d52bf07171c252c6626348d910cd | |
parent | 7724f895a810d5922fb0581403ff17169344f514 (diff) |
golfing
-rw-r--r-- | LocationLog.hs | 13 | ||||
-rw-r--r-- | PresenceLog.hs | 20 |
2 files changed, 14 insertions, 19 deletions
diff --git a/LocationLog.hs b/LocationLog.hs index fa660c8b6..7e5e81d7a 100644 --- a/LocationLog.hs +++ b/LocationLog.hs @@ -23,7 +23,6 @@ module LocationLog ( ) where import System.FilePath -import Control.Monad (when) import Control.Applicative import Data.Maybe @@ -36,16 +35,16 @@ import PresenceLog {- Log a change in the presence of a key's value in a repository. -} logChange :: Git.Repo -> Key -> UUID -> LogStatus -> Annex () -logChange repo key u s = do - when (null u) $ - error $ "unknown UUID for " ++ Git.repoDescribe repo ++ - " (have you run git annex init there?)" - addLog (logFile key) =<< logNow s u +logChange repo key u s + | null u = error $ + "unknown UUID for " ++ Git.repoDescribe repo ++ + " (have you run git annex init there?)" + | otherwise = addLog (logFile key) =<< logNow s u {- Returns a list of repository UUIDs that, according to the log, have - the value of a key. -} keyLocations :: Key -> Annex [UUID] -keyLocations key = currentLog $ logFile key +keyLocations = currentLog . logFile {- Finds all keys that have location log information. - (There may be duplicate keys in the list.) -} 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 |