summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-03-14 17:43:34 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-03-14 17:43:34 -0400
commit60ab3d84e188b8dd3a284d962df25bbee41ff1cb (patch)
tree768d4f632bab0152dbc1ca72f81fc3b9c7915c0a /Annex
parenta4f72c9625486786a4549cf4db1b542ea89da7c7 (diff)
added ifM and nuked 11 lines of code
no behavior changes
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Content.hs35
-rw-r--r--Annex/Ssh.hs20
-rw-r--r--Annex/UUID.hs6
3 files changed, 31 insertions, 30 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs
index ccaff5c56..fad5f5134 100644
--- a/Annex/Content.hs
+++ b/Annex/Content.hs
@@ -150,16 +150,16 @@ prepTmp key = do
getViaTmpUnchecked :: Key -> (FilePath -> Annex Bool) -> Annex Bool
getViaTmpUnchecked key action = do
tmp <- prepTmp key
- success <- action tmp
- if success
- then do
+ ifM (action tmp)
+ ( do
moveAnnex key tmp
logStatus key InfoPresent
return True
- else do
+ , do
-- the tmp file is left behind, in case caller wants
-- to resume its transfer
return False
+ )
{- Creates a temp file, runs an action on it, and cleans up the temp file. -}
withTmp :: Key -> (FilePath -> Annex a) -> Annex a
@@ -230,15 +230,15 @@ moveAnnex :: Key -> FilePath -> Annex ()
moveAnnex key src = do
dest <- inRepo $ gitAnnexLocation key
let dir = parentDir dest
- e <- liftIO $ doesFileExist dest
- if e
- then liftIO $ removeFile src
- else liftIO $ do
+ liftIO $ ifM (doesFileExist dest)
+ ( removeFile src
+ , do
createDirectoryIfMissing True dir
allowWrite dir -- in case the directory already exists
moveFile src dest
preventWrite dest
preventWrite dir
+ )
withObjectLoc :: Key -> ((FilePath, FilePath) -> Annex a) -> Annex a
withObjectLoc key a = do
@@ -314,12 +314,12 @@ getKeysPresent = liftIO . traverse (2 :: Int) =<< fromRepo gitAnnexObjectDir
saveState :: Bool -> Annex ()
saveState oneshot = do
Annex.Queue.flush False
- unless oneshot $ do
- alwayscommit <- fromMaybe True . Git.configTrue
+ unless oneshot $
+ ifM alwayscommit
+ ( Annex.Branch.commit "update" , Annex.Branch.stage)
+ where
+ alwayscommit = fromMaybe True . Git.configTrue
<$> fromRepo (Git.Config.get "annex.alwayscommit" "")
- if alwayscommit
- then Annex.Branch.commit "update"
- else Annex.Branch.stage
{- Downloads content from any of a list of urls. -}
downloadUrl :: [Url.URLString] -> FilePath -> Annex Bool
@@ -338,10 +338,9 @@ preseedTmp key file = go =<< inAnnex key
ok <- copy
when ok $ liftIO $ allowWrite file
return ok
- copy = do
- present <- liftIO $ doesFileExist file
- if present
- then return True
- else do
+ copy = ifM (liftIO $ doesFileExist file)
+ ( return True
+ , do
s <- inRepo $ gitAnnexLocation key
liftIO $ copyFileExternal s file
+ )
diff --git a/Annex/Ssh.hs b/Annex/Ssh.hs
index 39983ab25..79cfbe908 100644
--- a/Annex/Ssh.hs
+++ b/Annex/Ssh.hs
@@ -37,15 +37,17 @@ sshParams (host, port) opts = go =<< sshInfo (host, port)
sshCleanup
sshInfo :: (String, Maybe Integer) -> Annex (Maybe FilePath, [CommandParam])
-sshInfo (host, port) = do
- caching <- fromMaybe SysConfig.sshconnectioncaching . Git.configTrue
- <$> fromRepo (Git.Config.get "annex.sshcaching" "")
- if caching
- then do
- dir <- fromRepo gitAnnexSshDir
- let socketfile = dir </> hostport2socket host port
- return (Just socketfile, cacheParams socketfile)
- else return (Nothing, [])
+sshInfo (host, port) = ifM caching
+ ( do
+ dir <- fromRepo gitAnnexSshDir
+ let socketfile = dir </> hostport2socket host port
+ return (Just socketfile, cacheParams socketfile)
+ , return (Nothing, [])
+ )
+ where
+ caching = fromMaybe SysConfig.sshconnectioncaching
+ . Git.configTrue
+ <$> fromRepo (Git.Config.get "annex.sshcaching" "")
cacheParams :: FilePath -> [CommandParam]
cacheParams socketfile =
diff --git a/Annex/UUID.hs b/Annex/UUID.hs
index 48bf71f10..0ab2e7e52 100644
--- a/Annex/UUID.hs
+++ b/Annex/UUID.hs
@@ -34,11 +34,11 @@ genUUID :: IO UUID
genUUID = pOpen ReadFromPipe command params $ liftM toUUID . hGetLine
where
command = SysConfig.uuid
- params = if command == "uuid"
+ params
-- request a random uuid be generated
- then ["-m"]
+ | command == "uuid" = ["-m"]
-- uuidgen generates random uuid by default
- else []
+ | otherwise = []
{- Get current repository's UUID. -}
getUUID :: Annex UUID