summaryrefslogtreecommitdiff
path: root/Git
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-15 12:46:04 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-15 12:48:27 -0400
commit09cd04277577381464eddceb42558ad300c49378 (patch)
tree25413673497e639331c81fd0864b5ef0e394078a /Git
parentef28b3fef7e236d8c27ce35308c0e37ece58d20c (diff)
Properly handle multiline git config values.
A crash on parsing was fixed a while ago. This adds support for fully correctly parsing multiline git config values, using git config --null. Since git-annex-shell configlist uses normal git config output, I left in support for that too; the two forms of config output can be easily identified by the parser. Since configlist only prints the annex.uuid config, there's no risk of multiline values there, so no need to change it.
Diffstat (limited to 'Git')
-rw-r--r--Git/Config.hs14
1 files changed, 11 insertions, 3 deletions
diff --git a/Git/Config.hs b/Git/Config.hs
index 5f0e3fdc2..1fe948499 100644
--- a/Git/Config.hs
+++ b/Git/Config.hs
@@ -33,7 +33,8 @@ read repo@(Repo { location = Dir d }) = do
been already read. Instead, chdir to the repo. -}
cwd <- getCurrentDirectory
bracket_ (changeWorkingDirectory d) (changeWorkingDirectory cwd) $
- pOpen ReadFromPipe "git" ["config", "--list"] $ hRead repo
+ pOpen ReadFromPipe "git" ["config", "--null", "--list"] $
+ hRead repo
read r = assertLocal r $ error "internal"
{- Reads git config from a handle and populates a repo with it. -}
@@ -51,8 +52,15 @@ store s repo = do
rs <- Git.Construct.fromRemotes repo'
return $ repo' { remotes = rs }
-{- Parses git config --list output into a config map. -}
+{- Parses git config --list or git config --null --list output into a
+ - config map. -}
parse :: String -> M.Map String String
-parse s = M.fromList $ map pair $ lines s
+parse [] = M.empty
+parse s
+ -- --list output will have an = in the first line
+ | '=' `elem` head ls = M.fromList $ map (separate (== '=')) ls
+ -- --null --list output separates keys from values with newlines
+ | otherwise = M.fromList $ map (separate (== '\n')) $ split "\0" s
where
pair = separate (== '=')
+ ls = lines s