more partial function removal

Left a few Prelude.head's in where it was checked not null and too hard to
remove, etc.
This commit is contained in:
Joey Hess 2011-12-15 18:11:42 -04:00
parent b7e0d39abb
commit 95d2391f58
24 changed files with 73 additions and 78 deletions

View file

@ -68,7 +68,7 @@ logFile key = hashDirLower key ++ keyFile key ++ ".log"
{- Converts a log filename into a key. -}
logFileKey :: FilePath -> Maybe Key
logFileKey file
| end == ".log" = fileKey beginning
| ext == ".log" = fileKey base
| otherwise = Nothing
where
(beginning, end) = splitAt (length file - 4) file
(base, ext) = splitAt (length file - 4) file

View file

@ -73,14 +73,13 @@ configUnEscape = unescape
| c == '&' = entity rest
| otherwise = c : unescape rest
entity s = if ok
then chr (read num) : unescape rest
then chr (Prelude.read num) : unescape rest
else '&' : unescape s
where
num = takeWhile isNumber s
r = drop (length num) s
rest = drop 1 r
ok = not (null num) &&
not (null r) && head r == ';'
ok = not (null num) && take 1 r == ";"
{- for quickcheck -}
prop_idempotent_configEscape :: String -> Bool

View file

@ -54,18 +54,16 @@ trustMap = do
Just m -> return m
Nothing -> do
overrides <- M.fromList <$> Annex.getState Annex.forcetrust
m <- (M.union overrides . simpleMap . parseLog parseTrust) <$>
m <- (M.union overrides . simpleMap . parseLog (Just . parseTrust)) <$>
Annex.Branch.get trustLog
Annex.changeState $ \s -> s { Annex.trustmap = Just m }
return m
parseTrust :: String -> Maybe TrustLevel
parseTrust s
| length w > 0 = Just $ parse $ head w
-- back-compat; the trust.log used to only list trusted repos
| otherwise = Just Trusted
{- The trust.log used to only list trusted repos, without a field for the
- trust status, which is why this defaults to Trusted. -}
parseTrust :: String -> TrustLevel
parseTrust s = maybe Trusted parse $ headMaybe $ words s
where
w = words s
parse "1" = Trusted
parse "0" = UnTrusted
parse "X" = DeadTrusted
@ -82,6 +80,6 @@ trustSet :: UUID -> TrustLevel -> Annex ()
trustSet uuid@(UUID _) level = do
ts <- liftIO getPOSIXTime
Annex.Branch.change trustLog $
showLog showTrust . changeLog ts uuid level . parseLog parseTrust
showLog showTrust . changeLog ts uuid level . parseLog (Just . parseTrust)
Annex.changeState $ \s -> s { Annex.trustmap = Nothing }
trustSet NoUUID _ = error "unknown UUID; cannot modify trust level"

View file

@ -57,9 +57,9 @@ fixBadUUID = M.fromList . map fixup . M.toList
kuuid = fromUUID k
isbad = not (isuuid kuuid) && isuuid lastword
ws = words $ value v
lastword = last ws
lastword = Prelude.last ws
fixeduuid = toUUID lastword
fixedvalue = unwords $ kuuid: init ws
fixedvalue = unwords $ kuuid: Prelude.init ws
-- For the fixed line to take precidence, it should be
-- slightly newer, but only slightly.
newertime (LogEntry (Date d) _) = d + minimumPOSIXTimeSlice