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 Content
|
||||||
import Types
|
import Types
|
||||||
import Command
|
import Command
|
||||||
import Version
|
|
||||||
import Options
|
import Options
|
||||||
import Messages
|
import Messages
|
||||||
import Init
|
import Init
|
||||||
|
@ -59,7 +58,7 @@ parseCmd argv header cmds options = do
|
||||||
|
|
||||||
{- Checks that the command can be run in the current environment. -}
|
{- Checks that the command can be run in the current environment. -}
|
||||||
checkCmdEnviron :: Command -> Annex ()
|
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 message with lists of commands and options. -}
|
||||||
usage :: String -> [Command] -> [Option] -> String
|
usage :: String -> [Command] -> [Option] -> String
|
||||||
|
|
12
Init.hs
12
Init.hs
|
@ -6,8 +6,8 @@
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Init (
|
module Init (
|
||||||
|
ensureInitialized,
|
||||||
initialize,
|
initialize,
|
||||||
initializeSafe,
|
|
||||||
uninitialize
|
uninitialize
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
@ -38,12 +38,16 @@ uninitialize = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
gitPreCommitHookUnWrite g
|
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
|
branch from somewhere. Otherwise, require a manual init
|
||||||
to avoid git-annex accidentially being run in git
|
to avoid git-annex accidentially being run in git
|
||||||
repos that did not intend to use it. -}
|
repos that did not intend to use it. -}
|
||||||
initializeSafe :: Annex ()
|
ensureInitialized :: Annex ()
|
||||||
initializeSafe = do
|
ensureInitialized = do
|
||||||
|
v <- getVersion
|
||||||
|
case v of
|
||||||
|
Just version -> checkVersion version
|
||||||
|
Nothing -> do
|
||||||
annexed <- Branch.hasSomeBranch
|
annexed <- Branch.hasSomeBranch
|
||||||
if annexed
|
if annexed
|
||||||
then initialize
|
then initialize
|
||||||
|
|
|
@ -81,7 +81,7 @@ tryGitConfigRead r
|
||||||
| Git.repoIsHttp r = store $ safely $ geturlconfig
|
| Git.repoIsHttp r = store $ safely $ geturlconfig
|
||||||
| Git.repoIsUrl r = return r
|
| Git.repoIsUrl r = return r
|
||||||
| otherwise = store $ safely $ do
|
| otherwise = store $ safely $ do
|
||||||
onLocal r initializeSafe
|
onLocal r ensureInitialized
|
||||||
Git.configRead r
|
Git.configRead r
|
||||||
where
|
where
|
||||||
-- Reading config can fail due to IO error or
|
-- Reading config can fail due to IO error or
|
||||||
|
|
19
Version.hs
19
Version.hs
|
@ -7,8 +7,6 @@
|
||||||
|
|
||||||
module Version where
|
module Version where
|
||||||
|
|
||||||
import Control.Monad (unless)
|
|
||||||
|
|
||||||
import Types
|
import Types
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
import qualified Git
|
import qualified Git
|
||||||
|
@ -39,14 +37,11 @@ getVersion = do
|
||||||
setVersion :: Annex ()
|
setVersion :: Annex ()
|
||||||
setVersion = setConfig versionField defaultVersion
|
setVersion = setConfig versionField defaultVersion
|
||||||
|
|
||||||
checkVersion :: Annex () -> Annex ()
|
checkVersion :: Version -> Annex ()
|
||||||
checkVersion initaction = getVersion >>= handle
|
checkVersion v
|
||||||
|
| v `elem` supportedVersions = return ()
|
||||||
|
| v `elem` upgradableVersions = err "Upgrade this repository: git-annex upgrade"
|
||||||
|
| otherwise = err "Upgrade git-annex."
|
||||||
where
|
where
|
||||||
handle Nothing = initaction
|
err msg = error $ "Repository version " ++ v ++
|
||||||
handle (Just v) = unless (v `elem` supportedVersions) $
|
" is not supported. " ++ msg
|
||||||
error $ "Repository version " ++ v ++
|
|
||||||
" is not supported. " ++
|
|
||||||
msg v
|
|
||||||
msg v
|
|
||||||
| v `elem` upgradableVersions = "Upgrade this repository: git-annex upgrade"
|
|
||||||
| otherwise = "Upgrade git-annex."
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue