summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-07-14 16:41:17 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-07-14 16:41:17 -0400
commitdddbc09ff0199967602ad5d4112b2b4e04780177 (patch)
treea42c44d76fe087112ac4117553fc2035b4487486
parent020787bb974da8eafb5002b9427d44e21b3c802e (diff)
allow configStore to be run incrementally to override configs
-rw-r--r--Git.hs29
1 files changed, 15 insertions, 14 deletions
diff --git a/Git.hs b/Git.hs
index 7827f8051..2d03163bb 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 =