From dddbc09ff0199967602ad5d4112b2b4e04780177 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 14 Jul 2011 16:41:17 -0400 Subject: [PATCH] allow configStore to be run incrementally to override configs --- Git.hs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Git.hs b/Git.hs index 7827f80514..2d03163bbf 100644 --- a/Git.hs +++ b/Git.hs @@ -466,13 +466,24 @@ hConfigRead repo h = do val <- hGetContentsStrict h configStore repo val -{- Parses a git config and returns a version of the repo using it. -} +{- Stores a git config into a repo, returning the new version of the repo. + - The git config may be multiple lines, or a single line. Config settings + - can be updated inrementally. -} configStore :: Repo -> String -> IO Repo configStore repo s = do - rs <- configRemotes r - return $ r { remotes = rs } + let repo' = repo { config = Map.union (configParse s) (config repo) } + rs <- configRemotes repo' + return $ repo' { remotes = rs } + +{- Parses git config --list output into a config map. -} +configParse :: String -> Map.Map String String +configParse s = Map.fromList $ map pair $ lines s where - r = repo { config = configParse s } + 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 = "=" {- Calculates a list of a repo's configured remotes, by parsing its config. -} configRemotes :: Repo -> IO [Repo] @@ -503,16 +514,6 @@ configRemotes repo = mapM construct remotepairs configTrue :: String -> Bool configTrue s = map toLower s == "true" -{- Parses git config --list output into a config map. -} -configParse :: String -> Map.Map String String -configParse s = Map.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 = "=" - {- Returns a single git config setting, or a default value if not set. -} configGet :: Repo -> String -> String -> String configGet repo key defaultValue =