From 09cd04277577381464eddceb42558ad300c49378 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 15 Dec 2011 12:46:04 -0400 Subject: 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. --- Git/Config.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'Git') 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 -- cgit v1.2.3