summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-08-17 18:38:26 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-08-17 18:38:26 -0400
commitb7a4ff1c3185404d36d34b372b016be052394a95 (patch)
tree28953385279993b63c28007dd0cfa5e3ea5e853a
parent228a724d1d1e1d2f27763bd5f71473acc4d022d9 (diff)
optimise initialized check
Avoid running external command if annex.version is set.
-rw-r--r--CmdLine.hs3
-rw-r--r--Init.hs20
-rw-r--r--Remote/Git.hs2
-rw-r--r--Version.hs19
4 files changed, 21 insertions, 23 deletions
diff --git a/CmdLine.hs b/CmdLine.hs
index 0590f1112..2652e5b8f 100644
--- a/CmdLine.hs
+++ b/CmdLine.hs
@@ -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
diff --git a/Init.hs b/Init.hs
index 36d3ed0fa..ae92998bb 100644
--- a/Init.hs
+++ b/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 ()
diff --git a/Remote/Git.hs b/Remote/Git.hs
index c588cc73b..d8ecd33c4 100644
--- a/Remote/Git.hs
+++ b/Remote/Git.hs
@@ -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
diff --git a/Version.hs b/Version.hs
index 44fd2e9de..fcf6bc4d1 100644
--- a/Version.hs
+++ b/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