test suite saved my bacon

git config reading memoization shouldn't be used when changing config
This commit is contained in:
Joey Hess 2012-05-19 10:22:43 -04:00
parent a1885bd116
commit 0093a456e8
2 changed files with 21 additions and 13 deletions

View file

@ -21,8 +21,7 @@ data ConfigKey = ConfigKey String
setConfig :: ConfigKey -> String -> Annex () setConfig :: ConfigKey -> String -> Annex ()
setConfig (ConfigKey key) value = do setConfig (ConfigKey key) value = do
inRepo $ Git.Command.run "config" [Param key, Param value] inRepo $ Git.Command.run "config" [Param key, Param value]
-- re-read git config and update the repo's state newg <- inRepo Git.Config.reRead
newg <- inRepo Git.Config.read
Annex.changeState $ \s -> s { Annex.repo = newg } Annex.changeState $ \s -> s { Annex.repo = newg }
{- Unsets a git config setting. (Leaves it in state currently.) -} {- Unsets a git config setting. (Leaves it in state currently.) -}

View file

@ -28,19 +28,28 @@ getMaybe :: String -> Repo -> Maybe String
getMaybe key repo = M.lookup key (config repo) getMaybe key repo = M.lookup key (config repo)
{- Runs git config and populates a repo with its config. {- 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. Instead, chdir to the repo.
-} -}
read :: Repo -> IO Repo read' :: Repo -> IO Repo
read repo@(Repo { location = Local { gitdir = d } }) = read' repo d read' repo = go repo
read repo@(Repo { location = LocalUnknown d }) = read' repo d where
read r = assertLocal r $ error "internal" go Repo { location = Local { gitdir = d } } = git_config d
read' :: Repo -> FilePath -> IO Repo go Repo { location = LocalUnknown d } = git_config d
read' repo@(Repo { config = c}) d go _ = assertLocal repo $ error "internal"
| c == M.empty = bracketCd d $ git_config d = bracketCd d $
pOpen ReadFromPipe "git" ["config", "--null", "--list"] $ pOpen ReadFromPipe "git" ["config", "--null", "--list"] $
hRead repo hRead repo
| otherwise = return repo -- config already read
{- Reads git config from a handle and populates a repo with it. -} {- Reads git config from a handle and populates a repo with it. -}
hRead :: Repo -> Handle -> IO Repo hRead :: Repo -> Handle -> IO Repo