summaryrefslogtreecommitdiff
path: root/Git.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-09 18:10:41 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-09 18:10:41 -0400
commit28699c95a7de284f07a5c0e34fb1755868301f3c (patch)
treeef6b372edf27c9cbb508169e7adf707dc25a84c6 /Git.hs
parent95e748cbd4bb858a3b87621e60f5b43d53b50480 (diff)
some work on avoiding partial functions
There are still hundreds of places that use partial functions head, tail, init, and last.
Diffstat (limited to 'Git.hs')
-rw-r--r--Git.hs18
1 files changed, 6 insertions, 12 deletions
diff --git a/Git.hs b/Git.hs
index 5bdd4afd4..84153be5d 100644
--- a/Git.hs
+++ b/Git.hs
@@ -507,11 +507,7 @@ configStore s repo = do
configParse :: String -> M.Map String String
configParse s = M.fromList $ map pair $ lines s
where
- pair l = (key l, val l)
- key l = head $ keyval l
- val l = join sep $ drop 1 $ keyval l
- keyval l = split sep l :: [String]
- sep = "="
+ pair = separate (== '=')
{- Calculates a list of a repo's configured remotes, by parsing its config. -}
configRemotes :: Repo -> IO [Repo]
@@ -550,13 +546,11 @@ genRemote s repo = gen $ calcloc s
scpstyle v = ":" `isInfixOf` v && not ("//" `isInfixOf` v)
scptourl v = "ssh://" ++ host ++ slash dir
where
- bits = split ":" v
- host = head bits
- dir = join ":" $ drop 1 bits
- slash d | d == "" = "/~/" ++ dir
- | head d == '/' = dir
- | head d == '~' = '/':dir
- | otherwise = "/~/" ++ dir
+ (host, dir) = separate (== ':') v
+ slash d | d == "" = "/~/" ++ d
+ | "/" `isPrefixOf` d = d
+ | "~" `isPrefixOf` d = '/':d
+ | otherwise = "/~/" ++ d
{- Checks if a string from git config is a true value. -}
configTrue :: String -> Bool