From 6d3df8a0833fdef290b76681e8ba85ec94b76e36 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 29 Jan 2011 23:47:10 -0400 Subject: [PATCH] more pure code refactoring --- CmdLine.hs | 1 - Command.hs | 13 ++++++++----- LocationLog.hs | 10 +++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CmdLine.hs b/CmdLine.hs index 030637a738..d65739791f 100644 --- a/CmdLine.hs +++ b/CmdLine.hs @@ -101,5 +101,4 @@ shutdown = do unless (q == GitQueue.empty) $ do showSideAction "Recording state in git..." Annex.queueRun - return True diff --git a/Command.hs b/Command.hs index 298234fa05..e54add707b 100644 --- a/Command.hs +++ b/Command.hs @@ -184,17 +184,20 @@ filterFiles l = do if null exclude then return l' else do - let regexp = compile (toregex exclude) [] + let regexp = compile (wildsRegex exclude) [] return $ filter (notExcluded regexp) l' where notState f = not $ stateDir `isPrefixOf` f notExcluded r f = case match r f [] of Nothing -> True Just _ -> False - toregex exclude = "^(" ++ toregex' exclude "" ++ ")" - toregex' [] c = c - toregex' (w:ws) "" = toregex' ws (wildToRegex w) - toregex' (w:ws) c = toregex' ws (c ++ "|" ++ wildToRegex w) + +wildsRegex :: [String] -> String +wildsRegex ws = "^(" ++ wildsRegex' ws "" ++ ")" +wildsRegex' :: [String] -> String -> String +wildsRegex' [] c = c +wildsRegex' (w:ws) "" = wildsRegex' ws (wildToRegex w) +wildsRegex' (w:ws) c = wildsRegex' ws (c ++ "|" ++ wildToRegex w) {- filter out symlinks -} notSymlink :: FilePath -> IO Bool diff --git a/LocationLog.hs b/LocationLog.hs index 56953bc029..f778df3864 100644 --- a/LocationLog.hs +++ b/LocationLog.hs @@ -104,11 +104,15 @@ readLog file = do if exists then do s <- readFile file - -- filter out any unparsable lines - return $ filter (\l -> status l /= Undefined ) - $ map read $ lines s + return $ parseLog s else return [] +parseLog :: String -> [LogLine] +parseLog s = filter parsable $ map read $ lines s + where + -- some lines may be unparseable, avoid them + parsable l = status l /= Undefined + {- Writes a set of lines to a log file -} writeLog :: FilePath -> [LogLine] -> IO () writeLog file ls = safeWriteFile file (unlines $ map show ls)