got rid of almost all 'return ()'
This commit is contained in:
parent
9c7b3dce9e
commit
045b051ec1
9 changed files with 30 additions and 50 deletions
3
Annex.hs
3
Annex.hs
|
@ -61,7 +61,6 @@ gitRepoChange :: Git.Repo -> Annex ()
|
|||
gitRepoChange r = do
|
||||
state <- get
|
||||
put state { Internals.repo = r }
|
||||
return ()
|
||||
|
||||
{- Returns the backends being used. -}
|
||||
backends :: Annex [Backend]
|
||||
|
@ -74,7 +73,6 @@ backendsChange :: [Backend] -> Annex ()
|
|||
backendsChange b = do
|
||||
state <- get
|
||||
put state { Internals.backends = b }
|
||||
return ()
|
||||
|
||||
{- Returns the full list of supported backends. -}
|
||||
supportedBackends :: Annex [Backend]
|
||||
|
@ -95,7 +93,6 @@ flagChange :: FlagName -> Flag -> Annex ()
|
|||
flagChange name val = do
|
||||
state <- get
|
||||
put state { Internals.flags = M.insert name val $ Internals.flags state }
|
||||
return ()
|
||||
|
||||
{- Gets the value of a String flag (or "" if there is no such String flag) -}
|
||||
flagGet :: FlagName -> Annex String
|
||||
|
|
|
@ -129,7 +129,7 @@ checkRemoveKey key = do
|
|||
"Could only verify the existence of " ++
|
||||
(show have) ++ " out of " ++ (show need) ++
|
||||
" necessary copies"
|
||||
if (not $ null bad) then showTriedRemotes bad else return ()
|
||||
showTriedRemotes bad
|
||||
showLocations key
|
||||
hint
|
||||
return False
|
||||
|
@ -146,7 +146,8 @@ showLocations key = do
|
|||
if (null uuidsf)
|
||||
then showLongNote $ "No other repository is known to contain the file."
|
||||
else showLongNote $ "Try making some of these repositories available:\n" ++ ppuuids
|
||||
|
||||
|
||||
showTriedRemotes [] = return ()
|
||||
showTriedRemotes remotes =
|
||||
showLongNote $ "I was unable to access these remotes: " ++
|
||||
(Remotes.list remotes)
|
||||
|
|
|
@ -14,6 +14,7 @@ import System.Directory
|
|||
import System.Path
|
||||
import Data.String.Utils
|
||||
import Control.Monad (filterM)
|
||||
import Monad (when)
|
||||
import List
|
||||
import IO
|
||||
|
||||
|
@ -326,9 +327,7 @@ dropKeyCleanup key = do
|
|||
setKeyStart :: FilePath -> Annex (Maybe SubCmdPerform)
|
||||
setKeyStart tmpfile = do
|
||||
keyname <- Annex.flagGet "key"
|
||||
if (null keyname)
|
||||
then error "please specify the key with --key"
|
||||
else return ()
|
||||
when (null keyname) $ error "please specify the key with --key"
|
||||
backends <- Backend.list
|
||||
let key = genKey (backends !! 0) keyname
|
||||
return $ Just $ setKeyPerform tmpfile key
|
||||
|
@ -392,9 +391,7 @@ initCleanup = do
|
|||
fromKeyStart :: FilePath -> Annex (Maybe SubCmdPerform)
|
||||
fromKeyStart file = do
|
||||
keyname <- Annex.flagGet "key"
|
||||
if (null keyname)
|
||||
then error "please specify the key with --key"
|
||||
else return ()
|
||||
when (null keyname) $ error "please specify the key with --key"
|
||||
backends <- Backend.list
|
||||
let key = genKey (backends !! 0) keyname
|
||||
|
||||
|
|
23
Core.hs
23
Core.hs
|
@ -13,6 +13,7 @@ import System.Directory
|
|||
import Control.Monad.State (liftIO)
|
||||
import System.Path
|
||||
import Data.String.Utils
|
||||
import Monad (when, unless)
|
||||
|
||||
import Types
|
||||
import Locations
|
||||
|
@ -37,19 +38,15 @@ shutdown = do
|
|||
|
||||
-- Runs all queued git commands.
|
||||
q <- Annex.queueGet
|
||||
if (q == GitQueue.empty)
|
||||
then return ()
|
||||
else do
|
||||
verbose $ liftIO $ putStrLn "Recording state in git..."
|
||||
liftIO $ GitQueue.run g q
|
||||
unless (q == GitQueue.empty) $ do
|
||||
verbose $ liftIO $ putStrLn "Recording state in git..."
|
||||
liftIO $ GitQueue.run g q
|
||||
|
||||
-- clean up any files left in the temp directory, but leave
|
||||
-- the tmp directory itself
|
||||
let tmp = annexTmpLocation g
|
||||
exists <- liftIO $ doesDirectoryExist tmp
|
||||
if (exists)
|
||||
then liftIO $ removeDirectoryRecursive $ tmp
|
||||
else return ()
|
||||
when (exists) $ liftIO $ removeDirectoryRecursive $ tmp
|
||||
liftIO $ createDirectoryIfMissing True tmp
|
||||
|
||||
return True
|
||||
|
@ -65,11 +62,9 @@ gitAttributes repo = do
|
|||
commit
|
||||
else do
|
||||
content <- readFile attributes
|
||||
if (all (/= attrLine) (lines content))
|
||||
then do
|
||||
appendFile attributes $ attrLine ++ "\n"
|
||||
commit
|
||||
else return ()
|
||||
when (all (/= attrLine) (lines content)) $ do
|
||||
appendFile attributes $ attrLine ++ "\n"
|
||||
commit
|
||||
where
|
||||
attrLine = stateLoc ++ "*.log merge=union"
|
||||
attributes = Git.attributes repo
|
||||
|
@ -150,7 +145,7 @@ getViaTmp key action = do
|
|||
verbose :: Annex () -> Annex ()
|
||||
verbose a = do
|
||||
q <- Annex.flagIsSet "quiet"
|
||||
if (q) then return () else a
|
||||
unless q a
|
||||
showStart :: String -> String -> Annex ()
|
||||
showStart command file = verbose $ do
|
||||
liftIO $ putStr $ command ++ " " ++ file ++ " "
|
||||
|
|
|
@ -16,6 +16,7 @@ import qualified Data.Map as M
|
|||
import System.IO
|
||||
import System.Cmd.Utils
|
||||
import Data.String.Utils
|
||||
import Monad (unless)
|
||||
|
||||
import qualified GitRepo as Git
|
||||
|
||||
|
@ -52,9 +53,7 @@ run repo queue = do
|
|||
- Complicated by commandline length limits. -}
|
||||
runAction :: Git.Repo -> Action -> [FilePath] -> IO ()
|
||||
runAction repo action files = do
|
||||
if (null files)
|
||||
then return ()
|
||||
else runxargs
|
||||
unless (null files) runxargs
|
||||
where
|
||||
runxargs = pOpen WriteToPipe "xargs"
|
||||
(["-0", "git", subcommand action] ++ (params action))
|
||||
|
|
|
@ -191,8 +191,7 @@ gitCommandLine repo params = assertLocal repo $
|
|||
{- Runs git in the specified repo. -}
|
||||
run :: Repo -> [String] -> IO ()
|
||||
run repo params = assertLocal repo $ do
|
||||
r <- safeSystem "git" (gitCommandLine repo params)
|
||||
return ()
|
||||
safeSystem "git" (gitCommandLine repo params)
|
||||
|
||||
{- Runs a git subcommand and returns its output. -}
|
||||
pipeRead :: Repo -> [String] -> IO String
|
||||
|
|
|
@ -28,6 +28,7 @@ import System.Directory
|
|||
import System.Posix.Directory
|
||||
import List
|
||||
import Maybe
|
||||
import Monad (when, unless)
|
||||
|
||||
import Types
|
||||
import qualified GitRepo as Git
|
||||
|
@ -65,9 +66,9 @@ keyPossibilities key = do
|
|||
let cheap = filter (not . Git.repoIsUrl) allremotes
|
||||
let expensive = filter Git.repoIsUrl allremotes
|
||||
doexpensive <- filterM cachedUUID expensive
|
||||
if (not $ null doexpensive)
|
||||
then Core.showNote $ "getting UUID for " ++ (list doexpensive) ++ "..."
|
||||
else return ()
|
||||
unless (null doexpensive) $ do
|
||||
Core.showNote $ "getting UUID for " ++
|
||||
(list doexpensive) ++ "..."
|
||||
let todo = cheap ++ doexpensive
|
||||
if (not $ null todo)
|
||||
then do
|
||||
|
|
14
UUID.hs
14
UUID.hs
|
@ -63,10 +63,7 @@ getUUID r = do
|
|||
where
|
||||
uncached r = Git.configGet r "annex.uuid" ""
|
||||
cached r g = Git.configGet g (cachekey r) ""
|
||||
updatecache g r u = do
|
||||
if (g /= r)
|
||||
then setConfig (cachekey r) u
|
||||
else return ()
|
||||
updatecache g r u = when (g /= r) $ setConfig (cachekey r) u
|
||||
cachekey r = "remote." ++ (Git.repoRemoteName r) ++ ".annex-uuid"
|
||||
|
||||
{- Make sure that the repo has an annex.uuid setting. -}
|
||||
|
@ -74,11 +71,9 @@ prepUUID :: Annex ()
|
|||
prepUUID = do
|
||||
g <- Annex.gitRepo
|
||||
u <- getUUID g
|
||||
if ("" == u)
|
||||
then do
|
||||
uuid <- liftIO $ genUUID
|
||||
setConfig configkey uuid
|
||||
else return ()
|
||||
when ("" == u) $ do
|
||||
uuid <- liftIO $ genUUID
|
||||
setConfig configkey uuid
|
||||
|
||||
{- Changes a git config setting in both internal state and .git/config -}
|
||||
setConfig :: String -> String -> Annex ()
|
||||
|
@ -88,7 +83,6 @@ setConfig key value = do
|
|||
-- re-read git config and update the repo's state
|
||||
g' <- liftIO $ Git.configRead g
|
||||
Annex.gitRepoChange g'
|
||||
return ()
|
||||
|
||||
{- Filters a list of repos to ones that have listed UUIDs. -}
|
||||
reposByUUID :: [Git.Repo] -> [UUID] -> Annex [Git.Repo]
|
||||
|
|
11
git-annex.hs
11
git-annex.hs
|
@ -8,6 +8,7 @@
|
|||
import IO (try)
|
||||
import System.IO
|
||||
import System.Environment
|
||||
import Monad
|
||||
|
||||
import qualified Annex
|
||||
import Types
|
||||
|
@ -42,12 +43,8 @@ tryRun' state errnum (a:as) = do
|
|||
tryRun' state (errnum + 1) as
|
||||
Right (True,state') -> tryRun' state' errnum as
|
||||
Right (False,state') -> tryRun' state' (errnum + 1) as
|
||||
tryRun' state errnum [] = do
|
||||
if (errnum > 0)
|
||||
then error $ (show errnum) ++ " failed"
|
||||
else return ()
|
||||
tryRun' state errnum [] =
|
||||
when (errnum > 0) $ error $ (show errnum) ++ " failed"
|
||||
|
||||
{- Exception pretty-printing. -}
|
||||
showErr e = do
|
||||
hPutStrLn stderr $ "git-annex: " ++ (show e)
|
||||
return ()
|
||||
showErr e = hPutStrLn stderr $ "git-annex: " ++ (show e)
|
||||
|
|
Loading…
Reference in a new issue