summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-09 18:57:09 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-09 18:57:09 -0400
commit4b3c4c0c2b88aa17a9b7822470e3e5dd2a3e7c2b (patch)
tree15aa009b770199bca447d81a9d2f0bb401908a91
parent28699c95a7de284f07a5c0e34fb1755868301f3c (diff)
avoid some read
-rw-r--r--Config.hs7
-rw-r--r--Git.hs2
-rw-r--r--Utility/BadPrelude.hs4
3 files changed, 9 insertions, 4 deletions
diff --git a/Config.hs b/Config.hs
index cc0c92953..c6107fc8e 100644
--- a/Config.hs
+++ b/Config.hs
@@ -79,9 +79,10 @@ repoNotIgnored r = not . Git.configTrue <$> getConfig r "ignore" "false"
{- If a value is specified, it is used; otherwise the default is looked up
- in git config. forcenumcopies overrides everything. -}
getNumCopies :: Maybe Int -> Annex Int
-getNumCopies v =
- Annex.getState Annex.forcenumcopies >>= maybe (use v) (return . id)
+getNumCopies v = perhaps (use v) =<< Annex.getState Annex.forcenumcopies
where
use (Just n) = return n
- use Nothing = read <$> fromRepo (Git.configGet config "1")
+ use Nothing = perhaps (return 1) =<<
+ readMaybe <$> fromRepo (Git.configGet config "1")
+ perhaps fallback = maybe fallback (return . id)
config = "annex.numcopies"
diff --git a/Git.hs b/Git.hs
index 84153be5d..8bc32b7cc 100644
--- a/Git.hs
+++ b/Git.hs
@@ -345,7 +345,7 @@ urlPort :: Repo -> Maybe Integer
urlPort r =
case urlAuthPart uriPort r of
":" -> Nothing
- (':':p) -> Just (read p)
+ (':':p) -> readMaybe p
_ -> Nothing
{- Hostname of an URL repo, including any username (ie, "user@host") -}
diff --git a/Utility/BadPrelude.hs b/Utility/BadPrelude.hs
index 1bb70adfb..7921a7e9b 100644
--- a/Utility/BadPrelude.hs
+++ b/Utility/BadPrelude.hs
@@ -22,3 +22,7 @@ init = Prelude.init
{- last too -}
last :: [a] -> a
last = Prelude.last
+
+{- read should be avoided, as it throws an error -}
+read :: Read a => String -> a
+read = Prelude.read