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