From 0093a456e869b5250735ef4ec790faac115d9142 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 19 May 2012 10:22:43 -0400 Subject: [PATCH] test suite saved my bacon git config reading memoization shouldn't be used when changing config --- Config.hs | 3 +-- Git/Config.hs | 31 ++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Config.hs b/Config.hs index bb57ab675e..f579e40b21 100644 --- a/Config.hs +++ b/Config.hs @@ -21,8 +21,7 @@ data ConfigKey = ConfigKey String setConfig :: ConfigKey -> String -> Annex () setConfig (ConfigKey key) value = do inRepo $ Git.Command.run "config" [Param key, Param value] - -- re-read git config and update the repo's state - newg <- inRepo Git.Config.read + newg <- inRepo Git.Config.reRead Annex.changeState $ \s -> s { Annex.repo = newg } {- Unsets a git config setting. (Leaves it in state currently.) -} diff --git a/Git/Config.hs b/Git/Config.hs index 2fa685a11d..38e1ca4be7 100644 --- a/Git/Config.hs +++ b/Git/Config.hs @@ -28,19 +28,28 @@ getMaybe :: String -> Repo -> Maybe String getMaybe key repo = M.lookup key (config repo) {- Runs git config and populates a repo with its config. - - Cannot use pipeRead because it relies on the config having been already + - Avoids re-reading config when run repeatedly. -} +read :: Repo -> IO Repo +read repo@(Repo { config = c }) + | c == M.empty = read' repo + | otherwise = return repo + +{- Reads config even if it was read before. -} +reRead :: Repo -> IO Repo +reRead = read' + +{- Cannot use pipeRead because it relies on the config having been already - read. Instead, chdir to the repo. -} -read :: Repo -> IO Repo -read repo@(Repo { location = Local { gitdir = d } }) = read' repo d -read repo@(Repo { location = LocalUnknown d }) = read' repo d -read r = assertLocal r $ error "internal" -read' :: Repo -> FilePath -> IO Repo -read' repo@(Repo { config = c}) d - | c == M.empty = bracketCd d $ - pOpen ReadFromPipe "git" ["config", "--null", "--list"] $ - hRead repo - | otherwise = return repo -- config already read +read' :: Repo -> IO Repo +read' repo = go repo + where + go Repo { location = Local { gitdir = d } } = git_config d + go Repo { location = LocalUnknown d } = git_config d + go _ = assertLocal repo $ error "internal" + git_config d = bracketCd d $ + pOpen ReadFromPipe "git" ["config", "--null", "--list"] $ + hRead repo {- Reads git config from a handle and populates a repo with it. -} hRead :: Repo -> Handle -> IO Repo