git-annex/Version.hs
Joey Hess 944c51ba26 improve version checking for v3
Do not set annex.version whenever any command is run. Just do it in init.
This ensures that, if a repo has annex.version=3, it has a git-annex
branch, so we don't have to run a command every time to check for the
branch.

Remove the old ad-hoc logic for v0 and v1, to simplify version checking.
2011-06-22 18:07:45 -04:00

53 lines
1.2 KiB
Haskell

{- git-annex repository versioning
-
- Copyright 2010 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Version where
import Control.Monad (unless)
import Types
import qualified Annex
import qualified GitRepo as Git
import Config
type Version = String
defaultVersion :: Version
defaultVersion = "3"
supportedVersions :: [Version]
supportedVersions = [defaultVersion]
upgradableVersions :: [Version]
upgradableVersions = ["0", "1", "2"]
versionField :: String
versionField = "annex.version"
getVersion :: Annex (Maybe Version)
getVersion = do
g <- Annex.gitRepo
let v = Git.configGet g versionField ""
if not $ null v
then return $ Just v
else return Nothing
setVersion :: Annex ()
setVersion = setConfig versionField defaultVersion
checkVersion :: Annex ()
checkVersion = getVersion >>= handle
where
handle Nothing = error "First run: git-annex init"
handle (Just v) = do
unless (v `elem` supportedVersions) $ do
error $ "Repository version " ++ v ++
" is not supported. " ++
msg v
msg v
| v `elem` upgradableVersions = "Upgrade this repository: git-annex upgrade"
| otherwise = "Upgrade git-annex."