error handling cleanup
Use Control.Exception bracket_; want to catch all errors. System.Posix.Env.getEnv doesn't fail, no need to try it.
This commit is contained in:
parent
af239e5c33
commit
afe9e78401
1 changed files with 5 additions and 7 deletions
12
Git.hs
12
Git.hs
|
@ -72,7 +72,7 @@ module Git (
|
||||||
|
|
||||||
import System.Posix.Directory
|
import System.Posix.Directory
|
||||||
import System.Posix.User
|
import System.Posix.User
|
||||||
import IO (bracket_, try)
|
import Control.Exception (bracket_)
|
||||||
import qualified Data.Map as M hiding (map, split)
|
import qualified Data.Map as M hiding (map, split)
|
||||||
import Network.URI
|
import Network.URI
|
||||||
import Data.Char
|
import Data.Char
|
||||||
|
@ -438,12 +438,12 @@ reap = do
|
||||||
- index file. -}
|
- index file. -}
|
||||||
useIndex :: FilePath -> IO (IO ())
|
useIndex :: FilePath -> IO (IO ())
|
||||||
useIndex index = do
|
useIndex index = do
|
||||||
res <- try $ getEnv var
|
res <- getEnv var
|
||||||
setEnv var index True
|
setEnv var index True
|
||||||
return $ reset res
|
return $ reset res
|
||||||
where
|
where
|
||||||
var = "GIT_INDEX_FILE"
|
var = "GIT_INDEX_FILE"
|
||||||
reset (Right (Just v)) = setEnv var v True
|
reset (Just v) = setEnv var v True
|
||||||
reset _ = unsetEnv var
|
reset _ = unsetEnv var
|
||||||
|
|
||||||
{- Runs an action that causes a git subcommand to emit a sha, and strips
|
{- Runs an action that causes a git subcommand to emit a sha, and strips
|
||||||
|
@ -484,10 +484,8 @@ configRead repo@(Repo { location = Dir d }) = do
|
||||||
{- Cannot use pipeRead because it relies on the config having
|
{- Cannot use pipeRead because it relies on the config having
|
||||||
been already read. Instead, chdir to the repo. -}
|
been already read. Instead, chdir to the repo. -}
|
||||||
cwd <- getCurrentDirectory
|
cwd <- getCurrentDirectory
|
||||||
bracket_ (changeWorkingDirectory d)
|
bracket_ (changeWorkingDirectory d) (changeWorkingDirectory cwd) $
|
||||||
(\_ -> changeWorkingDirectory cwd) $
|
pOpen ReadFromPipe "git" ["config", "--list"] $ hConfigRead repo
|
||||||
pOpen ReadFromPipe "git" ["config", "--list"] $
|
|
||||||
hConfigRead repo
|
|
||||||
configRead r = assertLocal r $ error "internal"
|
configRead r = assertLocal r $ error "internal"
|
||||||
|
|
||||||
{- Reads git config from a handle and populates a repo with it. -}
|
{- Reads git config from a handle and populates a repo with it. -}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue