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.
This commit is contained in:
Joey Hess 2011-12-15 12:46:04 -04:00
parent ef28b3fef7
commit 09cd042775
4 changed files with 14 additions and 5 deletions

View file

@ -203,7 +203,7 @@ tryScan r
liftIO $ pipedconfig "ssh" sshparams
where
sshcmd = cddir ++ " && " ++
"git config --list"
"git config --null --list"
dir = Git.workTree r
cddir
| "/~" `isPrefixOf` dir =

View file

@ -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

View file

@ -111,7 +111,7 @@ tryGitConfigRead r
withTempFile "git-annex.tmp" $ \tmpfile h -> do
hPutStr h s
hClose h
pOpen ReadFromPipe "git" ["config", "--list", "--file", tmpfile] $
pOpen ReadFromPipe "git" ["config", "--null", "--list", "--file", tmpfile] $
Git.Config.hRead r
store a = do

1
debian/changelog vendored
View file

@ -2,6 +2,7 @@ git-annex (3.20111212) UNRELEASED; urgency=low
* Union merge now finds the least expensive way to represent the merge.
* reinject: Add a sanity check for using an annexed file as the source file.
* Properly handle multiline git config values.
-- Joey Hess <joeyh@debian.org> Mon, 12 Dec 2011 01:57:49 -0400