Added annex.autoupgraderepository configuration

Can be set to false to prevent any automatic repository upgrades.

Also, removed direct mode specific upgrade code in Annex.Init, and made
needsUpgrade always include the name/path of the repo, so if
there's a problem it's clear what repo has the problem.

And, made needsUpgrade catch any exceptions that might occur during the
upgrade, so it can display a more useful error message than just the
exception.
This commit is contained in:
Joey Hess 2019-09-01 13:29:55 -04:00
parent b421004d75
commit f845195354
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 53 additions and 23 deletions

View file

@ -141,12 +141,7 @@ uninitialize = do
- Checks repository version and handles upgrades too. - Checks repository version and handles upgrades too.
-} -}
ensureInitialized :: Annex () ensureInitialized :: Annex ()
ensureInitialized = ifM isDirect ensureInitialized = getVersion >>= maybe needsinit checkUpgrade
( unlessM (catchBoolIO $ upgrade True defaultVersion) $ do
g <- Annex.gitRepo
giveup $ "Upgrading direct mode repository " ++ Git.repoDescribe g ++ " failed, and direct mode is no longer supported."
, getVersion >>= maybe needsinit checkUpgrade
)
where where
needsinit = ifM Annex.Branch.hasSibling needsinit = ifM Annex.Branch.hasSibling
( initialize Nothing Nothing ( initialize Nothing Nothing

View file

@ -4,6 +4,8 @@ git-annex (7.20190826) UNRELEASED; urgency=medium
* Automatically upgrade v5 repositories to v7. * Automatically upgrade v5 repositories to v7.
* Automatically convert direct mode repositories to v7 with adjusted * Automatically convert direct mode repositories to v7 with adjusted
unlocked branches and set annex.thin. unlocked branches and set annex.thin.
* Added annex.autoupgraderepository configuration that can be set to false
to prevent any automatic repository upgrades.
* Refuse to upgrade direct mode repositories when git is older than 2.22, * Refuse to upgrade direct mode repositories when git is older than 2.22,
which fixed a memory leak that could cause an OOM during the upgrade. which fixed a memory leak that could cause an OOM during the upgrade.
* assistant: When creating a new repository, no longer use direct * assistant: When creating a new repository, no longer use direct

View file

@ -13,9 +13,13 @@ import Annex.Version
import Annex.Init import Annex.Init
cmd :: Command cmd :: Command
cmd = dontCheck repoExists $ -- because an old version may not seem to exist cmd = dontCheck repoExists $
noDaemonRunning $ -- avoid upgrading repo out from under daemon -- ^ because an old version may not seem to exist
command "upgrade" SectionMaintenance "upgrade repository layout" -- and also, this avoids automatic silent upgrades before
-- this command can start up.
noDaemonRunning $
-- ^ avoid upgrading repo out from under daemon
command "upgrade" SectionMaintenance "upgrade repository"
paramNothing (withParams seek) paramNothing (withParams seek)
seek :: CmdParams -> CommandSeek seek :: CmdParams -> CommandSeek

View file

@ -103,6 +103,7 @@ data GitConfig = GitConfig
, annexMaxExtensionLength :: Maybe Int , annexMaxExtensionLength :: Maybe Int
, annexJobs :: Concurrency , annexJobs :: Concurrency
, annexCacheCreds :: Bool , annexCacheCreds :: Bool
, annexAutoUpgradeRepository :: Bool
, coreSymlinks :: Bool , coreSymlinks :: Bool
, coreSharedRepository :: SharedRepository , coreSharedRepository :: SharedRepository
, receiveDenyCurrentBranch :: DenyCurrentBranch , receiveDenyCurrentBranch :: DenyCurrentBranch
@ -182,6 +183,7 @@ extractGitConfig r = GitConfig
, annexJobs = fromMaybe NonConcurrent $ , annexJobs = fromMaybe NonConcurrent $
parseConcurrency =<< getmaybe (annex "jobs") parseConcurrency =<< getmaybe (annex "jobs")
, annexCacheCreds = getbool (annex "cachecreds") True , annexCacheCreds = getbool (annex "cachecreds") True
, annexAutoUpgradeRepository = getbool (annex "autoupgraderepository") True
, coreSymlinks = getbool "core.symlinks" True , coreSymlinks = getbool "core.symlinks" True
, coreSharedRepository = getSharedRepository r , coreSharedRepository = getSharedRepository r
, receiveDenyCurrentBranch = getDenyCurrentBranch r , receiveDenyCurrentBranch = getDenyCurrentBranch r

View file

@ -1,6 +1,6 @@
{- git-annex upgrade support {- git-annex upgrade support
- -
- Copyright 2010, 2013 Joey Hess <id@joeyh.name> - Copyright 2010-2019 Joey Hess <id@joeyh.name>
- -
- Licensed under the GNU AGPL version 3 or higher. - Licensed under the GNU AGPL version 3 or higher.
-} -}
@ -10,6 +10,8 @@
module Upgrade where module Upgrade where
import Annex.Common import Annex.Common
import qualified Annex
import qualified Git
import Annex.Version import Annex.Version
import Types.RepoVersion import Types.RepoVersion
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
@ -36,14 +38,23 @@ needsUpgrade v
err "Upgrade this repository: git-annex upgrade" err "Upgrade this repository: git-annex upgrade"
| otherwise -> | otherwise ->
err "Upgrade git-annex." err "Upgrade git-annex."
Just newv -> ifM (upgrade True newv) Just newv -> ifM (annexAutoUpgradeRepository <$> Annex.getGitConfig)
( ok ( tryNonAsync (upgrade True newv) >>= \case
, err "Automatic upgrade failed!" Right True -> ok
Right False -> "Automatic upgrade failed!"
Left err -> "Automatic upgrade exception! " ++ show err
, err "Automatic upgrade is disabled by annex.autoupgraderepository configuration. To upgrade this repository: git-annex upgrade"
) )
where where
err msg = return $ Just $ "Repository version " ++ err msg = do
show (fromRepoVersion v) ++ g <- Annex.gitRepo
" is not supported. " ++ msg p <- liftIO $ absPath $ Git.repoPath g
return $ Just $ unwords
[ "Repository", p
, "is at unsupported version"
, show (fromRepoVersion v) ++ "."
, msg
]
ok = return Nothing ok = return Nothing
upgrade :: Bool -> RepoVersion -> Annex Bool upgrade :: Bool -> RepoVersion -> Annex Bool
@ -74,3 +85,4 @@ upgrade automatic destversion = do
up (RepoVersion 5) = Upgrade.V5.upgrade automatic up (RepoVersion 5) = Upgrade.V5.upgrade automatic
up (RepoVersion 6) = Upgrade.V6.upgrade automatic up (RepoVersion 6) = Upgrade.V6.upgrade automatic
up _ = return True up _ = return True

View file

@ -1,6 +1,6 @@
# NAME # NAME
git-annex upgrade - upgrade repository layout git-annex upgrade - upgrade repository
# SYNOPSIS # SYNOPSIS
@ -8,13 +8,16 @@ git annex upgrade
# DESCRIPTION # DESCRIPTION
Upgrades the repository to current layout. Upgrades the repository.
Each git-annex repository has an annex.version in its git configuration, Each git-annex repository has an annex.version in its git configuration,
that indicates the repository version. If git-annex changes to a new that indicates the repository version. When an old repository version
layout, you must upgrade the repository before git-annex can be used in it. becomes deprecated, git-annex will automatically upgrade it
(unless annex.autoupgraderepository is set to false). To manually upgrade,
you can use this command.
To see version information, run `git annex version`. Sometimes there's a newer repository version that is not the default yet,
and then you can use this command to upgrade to it.
Currently, git-annex supports upgrades all the way back to version 0, which Currently, git-annex supports upgrades all the way back to version 0, which
was only used by its author. It's expected that git-annex will always was only used by its author. It's expected that git-annex will always

View file

@ -383,7 +383,7 @@ subdirectories).
* `upgrade` * `upgrade`
Upgrades the repository to current layout. Upgrades the repository.
See [[git-annex-upgrade]](1) for details. See [[git-annex-upgrade]](1) for details.
@ -1066,7 +1066,19 @@ Like other git commands, git-annex is configured via `.git/config`.
* `annex.version` * `annex.version`
Automatically maintained, and used to automate upgrades between versions. The current version of the git-annex repository. This is
maintained by git-annex and should never be manually changed.
* `annex.autoupgraderepository`
When an old git-annex repository version has become deprecated,
git-annex will normally automatically upgrade the repository to
the new version.
If this is set to false, git-annex won't automatically upgrade the
repository. Instead it will exit with an error message. You can run
`git annex upgrade` yourself when you are ready to upgrade the
repository.
* `annex.crippledfilesystem` * `annex.crippledfilesystem`