optimise initialized check
Avoid running external command if annex.version is set.
This commit is contained in:
parent
228a724d1d
commit
b7a4ff1c31
4 changed files with 21 additions and 23 deletions
|
@ -22,7 +22,6 @@ import qualified Git
|
|||
import Content
|
||||
import Types
|
||||
import Command
|
||||
import Version
|
||||
import Options
|
||||
import Messages
|
||||
import Init
|
||||
|
@ -59,7 +58,7 @@ parseCmd argv header cmds options = do
|
|||
|
||||
{- Checks that the command can be run in the current environment. -}
|
||||
checkCmdEnviron :: Command -> Annex ()
|
||||
checkCmdEnviron command = when (cmdusesrepo command) $ checkVersion $ initializeSafe
|
||||
checkCmdEnviron command = when (cmdusesrepo command) ensureInitialized
|
||||
|
||||
{- Usage message with lists of commands and options. -}
|
||||
usage :: String -> [Command] -> [Option] -> String
|
||||
|
|
20
Init.hs
20
Init.hs
|
@ -6,8 +6,8 @@
|
|||
-}
|
||||
|
||||
module Init (
|
||||
ensureInitialized,
|
||||
initialize,
|
||||
initializeSafe,
|
||||
uninitialize
|
||||
) where
|
||||
|
||||
|
@ -38,16 +38,20 @@ uninitialize = do
|
|||
g <- Annex.gitRepo
|
||||
gitPreCommitHookUnWrite g
|
||||
|
||||
{- Call to automatically initialize if there is already a git-annex
|
||||
{- Will automatically initialize if there is already a git-annex
|
||||
branch from somewhere. Otherwise, require a manual init
|
||||
to avoid git-annex accidentially being run in git
|
||||
repos that did not intend to use it. -}
|
||||
initializeSafe :: Annex ()
|
||||
initializeSafe = do
|
||||
annexed <- Branch.hasSomeBranch
|
||||
if annexed
|
||||
then initialize
|
||||
else error "First run: git-annex init"
|
||||
ensureInitialized :: Annex ()
|
||||
ensureInitialized = do
|
||||
v <- getVersion
|
||||
case v of
|
||||
Just version -> checkVersion version
|
||||
Nothing -> do
|
||||
annexed <- Branch.hasSomeBranch
|
||||
if annexed
|
||||
then initialize
|
||||
else error "First run: git-annex init"
|
||||
|
||||
{- set up a git pre-commit hook, if one is not already present -}
|
||||
gitPreCommitHookWrite :: Git.Repo -> Annex ()
|
||||
|
|
|
@ -81,7 +81,7 @@ tryGitConfigRead r
|
|||
| Git.repoIsHttp r = store $ safely $ geturlconfig
|
||||
| Git.repoIsUrl r = return r
|
||||
| otherwise = store $ safely $ do
|
||||
onLocal r initializeSafe
|
||||
onLocal r ensureInitialized
|
||||
Git.configRead r
|
||||
where
|
||||
-- Reading config can fail due to IO error or
|
||||
|
|
19
Version.hs
19
Version.hs
|
@ -7,8 +7,6 @@
|
|||
|
||||
module Version where
|
||||
|
||||
import Control.Monad (unless)
|
||||
|
||||
import Types
|
||||
import qualified Annex
|
||||
import qualified Git
|
||||
|
@ -39,14 +37,11 @@ getVersion = do
|
|||
setVersion :: Annex ()
|
||||
setVersion = setConfig versionField defaultVersion
|
||||
|
||||
checkVersion :: Annex () -> Annex ()
|
||||
checkVersion initaction = getVersion >>= handle
|
||||
checkVersion :: Version -> Annex ()
|
||||
checkVersion v
|
||||
| v `elem` supportedVersions = return ()
|
||||
| v `elem` upgradableVersions = err "Upgrade this repository: git-annex upgrade"
|
||||
| otherwise = err "Upgrade git-annex."
|
||||
where
|
||||
handle Nothing = initaction
|
||||
handle (Just v) = unless (v `elem` supportedVersions) $
|
||||
error $ "Repository version " ++ v ++
|
||||
" is not supported. " ++
|
||||
msg v
|
||||
msg v
|
||||
| v `elem` upgradableVersions = "Upgrade this repository: git-annex upgrade"
|
||||
| otherwise = "Upgrade git-annex."
|
||||
err msg = error $ "Repository version " ++ v ++
|
||||
" is not supported. " ++ msg
|
||||
|
|
Loading…
Reference in a new issue