2015-12-15 19:56:37 +00:00
{- git - annex v5 - > v6 upgrade support
2015-12-04 20:14:48 +00:00
-
2019-08-26 17:46:58 +00:00
- Copyright 2015 - 2019 Joey Hess < id @ joeyh . name >
2015-12-04 20:14:48 +00:00
-
2019-03-13 19:48:14 +00:00
- Licensed under the GNU AGPL version 3 or higher .
2015-12-04 20:14:48 +00:00
- }
2019-12-02 16:01:20 +00:00
{- # LANGUAGE OverloadedStrings # -}
2015-12-04 20:14:48 +00:00
module Upgrade.V5 where
2016-01-20 20:36:33 +00:00
import Annex.Common
2015-12-04 20:14:48 +00:00
import Config
2018-08-28 14:26:51 +00:00
import Config.Smudge
2015-12-09 19:42:16 +00:00
import Annex.InodeSentinal
2015-12-15 19:56:37 +00:00
import Annex.Link
2015-12-27 19:59:59 +00:00
import Annex.CatFile
2016-10-17 18:58:33 +00:00
import Annex.WorkTree
2019-08-27 17:54:21 +00:00
import Annex.UUID
import Logs.Location
2019-08-27 18:01:28 +00:00
import qualified Upgrade.V5.Direct as Direct
2019-08-27 16:59:57 +00:00
import qualified Annex.Content as Content
2015-12-15 19:56:37 +00:00
import qualified Database.Keys
import qualified Git
import qualified Git.LsFiles
import qualified Git.Branch
Refuse to upgrade direct mode repositories when git is older than 2.22
That git fixed a memory leak that could cause an OOM during the upgrade.
Most git-annex builds have a new enough git already.
OSX git was upgraded with brew.
Linux i386ancient build's git was too old. Upgrading it to a fixed
git didn't work (due to the newer git not working with the old ssh,
https://bugs.chromium.org/p/git/issues/detail?id=7 )
Choices to deal with that were:
* Somehow make direct mode upgrade work with the old git, avoiding its
OOM problem. One way would be to switch the repo to indirect mode
first, and so upgrade to a repo with locked files. Not good when
the filesystem does not support symlinks.
* backport the OOM fix from git 2.22
(And do what about the version number so git-annex knows it's fixed?)
* backport openssh (and possibly more stuff)
* move the i386ancient build to at least Debian stretch (still backporting git)
But this will make it no longer work with some of the ancient kernels it
targets.
Of those, backporting the OOM fix seemed the best approach. Put "oomfix"
in the git version number to indicate it.
I have not automated building the git backport, so here's the patch I
used:
diff -ur orig/git-2.1.4/convert.c git-2.1.4/convert.c
--- orig/git-2.1.4/convert.c 2014-12-18 18:42:18.000000000 +0000
+++ git-2.1.4/convert.c 2019-08-29 20:05:04.371872338 +0100
@@ -404,7 +404,7 @@
if (start_async(&async))
return 0; /* error was already reported */
- if (strbuf_read(&nbuf, async.out, len) < 0) {
+ if (strbuf_read(&nbuf, async.out, 0) < 0) {
error("read from external filter %s failed", cmd);
ret = 0;
}
diff -ur orig/git-2.1.4/GIT-VERSION-GEN git-2.1.4/GIT-VERSION-GEN
--- orig/git-2.1.4/GIT-VERSION-GEN 2014-12-18 18:42:18.000000000 +0000
+++ git-2.1.4/GIT-VERSION-GEN 2019-08-29 20:06:39.132743228 +0100
@@ -1,7 +1,7 @@
#!/bin/sh
GVF=GIT-VERSION-FILE
-DEF_VER=v2.1.4
+DEF_VER=v2.1.4.oomfix
LF='
'
diff -ur orig/git-2.1.4/configure git-2.1.4/configure
--- orig/git-2.1.4/configure 2014-12-18 18:42:19.000000000 +0000
+++ git-2.1.4/configure 2019-08-29 20:27:45.896380015 +0100
@@ -580,8 +580,8 @@
# Identity of this package.
PACKAGE_NAME='git'
PACKAGE_TARNAME='git'
-PACKAGE_VERSION='2.1.4'
-PACKAGE_STRING='git 2.1.4'
+PACKAGE_VERSION='2.1.4.oomfix'
+PACKAGE_STRING='git 2.1.4.oomfix'
PACKAGE_BUGREPORT='git@vger.kernel.org'
PACKAGE_URL=''
diff -ur orig/git-2.1.4/version git-2.1.4/version
--- orig/git-2.1.4/version 2014-12-18 18:42:19.000000000 +0000
+++ git-2.1.4/version 2019-08-29 20:06:17.572545210 +0100
@@ -1 +1 @@
-2.1.4
+2.1.4.oomfix
2019-08-29 18:12:45 +00:00
import qualified Git.Version
2016-01-05 21:22:19 +00:00
import Git.FilePath
2015-12-15 19:56:37 +00:00
import Git.FileMode
2015-12-27 19:59:59 +00:00
import Git.Config
2016-04-04 17:17:24 +00:00
import Git.Ref
2015-12-22 19:20:03 +00:00
import Utility.InodeCache
Refuse to upgrade direct mode repositories when git is older than 2.22
That git fixed a memory leak that could cause an OOM during the upgrade.
Most git-annex builds have a new enough git already.
OSX git was upgraded with brew.
Linux i386ancient build's git was too old. Upgrading it to a fixed
git didn't work (due to the newer git not working with the old ssh,
https://bugs.chromium.org/p/git/issues/detail?id=7 )
Choices to deal with that were:
* Somehow make direct mode upgrade work with the old git, avoiding its
OOM problem. One way would be to switch the repo to indirect mode
first, and so upgrade to a repo with locked files. Not good when
the filesystem does not support symlinks.
* backport the OOM fix from git 2.22
(And do what about the version number so git-annex knows it's fixed?)
* backport openssh (and possibly more stuff)
* move the i386ancient build to at least Debian stretch (still backporting git)
But this will make it no longer work with some of the ancient kernels it
targets.
Of those, backporting the OOM fix seemed the best approach. Put "oomfix"
in the git version number to indicate it.
I have not automated building the git backport, so here's the patch I
used:
diff -ur orig/git-2.1.4/convert.c git-2.1.4/convert.c
--- orig/git-2.1.4/convert.c 2014-12-18 18:42:18.000000000 +0000
+++ git-2.1.4/convert.c 2019-08-29 20:05:04.371872338 +0100
@@ -404,7 +404,7 @@
if (start_async(&async))
return 0; /* error was already reported */
- if (strbuf_read(&nbuf, async.out, len) < 0) {
+ if (strbuf_read(&nbuf, async.out, 0) < 0) {
error("read from external filter %s failed", cmd);
ret = 0;
}
diff -ur orig/git-2.1.4/GIT-VERSION-GEN git-2.1.4/GIT-VERSION-GEN
--- orig/git-2.1.4/GIT-VERSION-GEN 2014-12-18 18:42:18.000000000 +0000
+++ git-2.1.4/GIT-VERSION-GEN 2019-08-29 20:06:39.132743228 +0100
@@ -1,7 +1,7 @@
#!/bin/sh
GVF=GIT-VERSION-FILE
-DEF_VER=v2.1.4
+DEF_VER=v2.1.4.oomfix
LF='
'
diff -ur orig/git-2.1.4/configure git-2.1.4/configure
--- orig/git-2.1.4/configure 2014-12-18 18:42:19.000000000 +0000
+++ git-2.1.4/configure 2019-08-29 20:27:45.896380015 +0100
@@ -580,8 +580,8 @@
# Identity of this package.
PACKAGE_NAME='git'
PACKAGE_TARNAME='git'
-PACKAGE_VERSION='2.1.4'
-PACKAGE_STRING='git 2.1.4'
+PACKAGE_VERSION='2.1.4.oomfix'
+PACKAGE_STRING='git 2.1.4.oomfix'
PACKAGE_BUGREPORT='git@vger.kernel.org'
PACKAGE_URL=''
diff -ur orig/git-2.1.4/version git-2.1.4/version
--- orig/git-2.1.4/version 2014-12-18 18:42:19.000000000 +0000
+++ git-2.1.4/version 2019-08-29 20:06:17.572545210 +0100
@@ -1 +1 @@
-2.1.4
+2.1.4.oomfix
2019-08-29 18:12:45 +00:00
import Utility.DottedVersion
2016-04-04 17:17:24 +00:00
import Annex.AdjustedBranch
2015-12-04 20:14:48 +00:00
2019-01-14 19:19:20 +00:00
import qualified Data.ByteString as S
2015-12-04 20:14:48 +00:00
upgrade :: Bool -> Annex Bool
2020-05-07 16:22:32 +00:00
upgrade automatic = flip catchNonAsync onexception $ do
2015-12-04 20:14:48 +00:00
unless automatic $
showAction " v5 to v6 "
2019-08-26 17:46:58 +00:00
ifM isDirect
( do
Refuse to upgrade direct mode repositories when git is older than 2.22
That git fixed a memory leak that could cause an OOM during the upgrade.
Most git-annex builds have a new enough git already.
OSX git was upgraded with brew.
Linux i386ancient build's git was too old. Upgrading it to a fixed
git didn't work (due to the newer git not working with the old ssh,
https://bugs.chromium.org/p/git/issues/detail?id=7 )
Choices to deal with that were:
* Somehow make direct mode upgrade work with the old git, avoiding its
OOM problem. One way would be to switch the repo to indirect mode
first, and so upgrade to a repo with locked files. Not good when
the filesystem does not support symlinks.
* backport the OOM fix from git 2.22
(And do what about the version number so git-annex knows it's fixed?)
* backport openssh (and possibly more stuff)
* move the i386ancient build to at least Debian stretch (still backporting git)
But this will make it no longer work with some of the ancient kernels it
targets.
Of those, backporting the OOM fix seemed the best approach. Put "oomfix"
in the git version number to indicate it.
I have not automated building the git backport, so here's the patch I
used:
diff -ur orig/git-2.1.4/convert.c git-2.1.4/convert.c
--- orig/git-2.1.4/convert.c 2014-12-18 18:42:18.000000000 +0000
+++ git-2.1.4/convert.c 2019-08-29 20:05:04.371872338 +0100
@@ -404,7 +404,7 @@
if (start_async(&async))
return 0; /* error was already reported */
- if (strbuf_read(&nbuf, async.out, len) < 0) {
+ if (strbuf_read(&nbuf, async.out, 0) < 0) {
error("read from external filter %s failed", cmd);
ret = 0;
}
diff -ur orig/git-2.1.4/GIT-VERSION-GEN git-2.1.4/GIT-VERSION-GEN
--- orig/git-2.1.4/GIT-VERSION-GEN 2014-12-18 18:42:18.000000000 +0000
+++ git-2.1.4/GIT-VERSION-GEN 2019-08-29 20:06:39.132743228 +0100
@@ -1,7 +1,7 @@
#!/bin/sh
GVF=GIT-VERSION-FILE
-DEF_VER=v2.1.4
+DEF_VER=v2.1.4.oomfix
LF='
'
diff -ur orig/git-2.1.4/configure git-2.1.4/configure
--- orig/git-2.1.4/configure 2014-12-18 18:42:19.000000000 +0000
+++ git-2.1.4/configure 2019-08-29 20:27:45.896380015 +0100
@@ -580,8 +580,8 @@
# Identity of this package.
PACKAGE_NAME='git'
PACKAGE_TARNAME='git'
-PACKAGE_VERSION='2.1.4'
-PACKAGE_STRING='git 2.1.4'
+PACKAGE_VERSION='2.1.4.oomfix'
+PACKAGE_STRING='git 2.1.4.oomfix'
PACKAGE_BUGREPORT='git@vger.kernel.org'
PACKAGE_URL=''
diff -ur orig/git-2.1.4/version git-2.1.4/version
--- orig/git-2.1.4/version 2014-12-18 18:42:19.000000000 +0000
+++ git-2.1.4/version 2019-08-29 20:06:17.572545210 +0100
@@ -1 +1 @@
-2.1.4
+2.1.4.oomfix
2019-08-29 18:12:45 +00:00
checkGitVersionForDirectUpgrade
2019-08-27 16:32:44 +00:00
convertDirect
Refuse to upgrade direct mode repositories when git is older than 2.22
That git fixed a memory leak that could cause an OOM during the upgrade.
Most git-annex builds have a new enough git already.
OSX git was upgraded with brew.
Linux i386ancient build's git was too old. Upgrading it to a fixed
git didn't work (due to the newer git not working with the old ssh,
https://bugs.chromium.org/p/git/issues/detail?id=7 )
Choices to deal with that were:
* Somehow make direct mode upgrade work with the old git, avoiding its
OOM problem. One way would be to switch the repo to indirect mode
first, and so upgrade to a repo with locked files. Not good when
the filesystem does not support symlinks.
* backport the OOM fix from git 2.22
(And do what about the version number so git-annex knows it's fixed?)
* backport openssh (and possibly more stuff)
* move the i386ancient build to at least Debian stretch (still backporting git)
But this will make it no longer work with some of the ancient kernels it
targets.
Of those, backporting the OOM fix seemed the best approach. Put "oomfix"
in the git version number to indicate it.
I have not automated building the git backport, so here's the patch I
used:
diff -ur orig/git-2.1.4/convert.c git-2.1.4/convert.c
--- orig/git-2.1.4/convert.c 2014-12-18 18:42:18.000000000 +0000
+++ git-2.1.4/convert.c 2019-08-29 20:05:04.371872338 +0100
@@ -404,7 +404,7 @@
if (start_async(&async))
return 0; /* error was already reported */
- if (strbuf_read(&nbuf, async.out, len) < 0) {
+ if (strbuf_read(&nbuf, async.out, 0) < 0) {
error("read from external filter %s failed", cmd);
ret = 0;
}
diff -ur orig/git-2.1.4/GIT-VERSION-GEN git-2.1.4/GIT-VERSION-GEN
--- orig/git-2.1.4/GIT-VERSION-GEN 2014-12-18 18:42:18.000000000 +0000
+++ git-2.1.4/GIT-VERSION-GEN 2019-08-29 20:06:39.132743228 +0100
@@ -1,7 +1,7 @@
#!/bin/sh
GVF=GIT-VERSION-FILE
-DEF_VER=v2.1.4
+DEF_VER=v2.1.4.oomfix
LF='
'
diff -ur orig/git-2.1.4/configure git-2.1.4/configure
--- orig/git-2.1.4/configure 2014-12-18 18:42:19.000000000 +0000
+++ git-2.1.4/configure 2019-08-29 20:27:45.896380015 +0100
@@ -580,8 +580,8 @@
# Identity of this package.
PACKAGE_NAME='git'
PACKAGE_TARNAME='git'
-PACKAGE_VERSION='2.1.4'
-PACKAGE_STRING='git 2.1.4'
+PACKAGE_VERSION='2.1.4.oomfix'
+PACKAGE_STRING='git 2.1.4.oomfix'
PACKAGE_BUGREPORT='git@vger.kernel.org'
PACKAGE_URL=''
diff -ur orig/git-2.1.4/version git-2.1.4/version
--- orig/git-2.1.4/version 2014-12-18 18:42:19.000000000 +0000
+++ git-2.1.4/version 2019-08-29 20:06:17.572545210 +0100
@@ -1 +1 @@
-2.1.4
+2.1.4.oomfix
2019-08-29 18:12:45 +00:00
, do
checkGitVersionForIndirectUpgrade
2019-08-26 17:46:58 +00:00
)
2019-11-05 16:41:15 +00:00
scanUnlockedFiles
2015-12-04 20:14:48 +00:00
configureSmudgeFilter
2015-12-09 19:42:16 +00:00
-- Inode sentinal file was only used in direct mode and when
-- locking down files as they were added. In v6, it's used more
-- extensively, so make sure it exists, since old repos that didn't
-- use direct mode may not have created it.
2019-08-26 19:52:19 +00:00
unlessM isDirect $
2015-12-09 19:42:16 +00:00
createInodeSentinalFile True
2015-12-04 20:14:48 +00:00
return True
2020-05-07 16:22:32 +00:00
where
onexception e = do
warning $ " caught exception: " ++ show e
return False
2015-12-15 19:56:37 +00:00
Refuse to upgrade direct mode repositories when git is older than 2.22
That git fixed a memory leak that could cause an OOM during the upgrade.
Most git-annex builds have a new enough git already.
OSX git was upgraded with brew.
Linux i386ancient build's git was too old. Upgrading it to a fixed
git didn't work (due to the newer git not working with the old ssh,
https://bugs.chromium.org/p/git/issues/detail?id=7 )
Choices to deal with that were:
* Somehow make direct mode upgrade work with the old git, avoiding its
OOM problem. One way would be to switch the repo to indirect mode
first, and so upgrade to a repo with locked files. Not good when
the filesystem does not support symlinks.
* backport the OOM fix from git 2.22
(And do what about the version number so git-annex knows it's fixed?)
* backport openssh (and possibly more stuff)
* move the i386ancient build to at least Debian stretch (still backporting git)
But this will make it no longer work with some of the ancient kernels it
targets.
Of those, backporting the OOM fix seemed the best approach. Put "oomfix"
in the git version number to indicate it.
I have not automated building the git backport, so here's the patch I
used:
diff -ur orig/git-2.1.4/convert.c git-2.1.4/convert.c
--- orig/git-2.1.4/convert.c 2014-12-18 18:42:18.000000000 +0000
+++ git-2.1.4/convert.c 2019-08-29 20:05:04.371872338 +0100
@@ -404,7 +404,7 @@
if (start_async(&async))
return 0; /* error was already reported */
- if (strbuf_read(&nbuf, async.out, len) < 0) {
+ if (strbuf_read(&nbuf, async.out, 0) < 0) {
error("read from external filter %s failed", cmd);
ret = 0;
}
diff -ur orig/git-2.1.4/GIT-VERSION-GEN git-2.1.4/GIT-VERSION-GEN
--- orig/git-2.1.4/GIT-VERSION-GEN 2014-12-18 18:42:18.000000000 +0000
+++ git-2.1.4/GIT-VERSION-GEN 2019-08-29 20:06:39.132743228 +0100
@@ -1,7 +1,7 @@
#!/bin/sh
GVF=GIT-VERSION-FILE
-DEF_VER=v2.1.4
+DEF_VER=v2.1.4.oomfix
LF='
'
diff -ur orig/git-2.1.4/configure git-2.1.4/configure
--- orig/git-2.1.4/configure 2014-12-18 18:42:19.000000000 +0000
+++ git-2.1.4/configure 2019-08-29 20:27:45.896380015 +0100
@@ -580,8 +580,8 @@
# Identity of this package.
PACKAGE_NAME='git'
PACKAGE_TARNAME='git'
-PACKAGE_VERSION='2.1.4'
-PACKAGE_STRING='git 2.1.4'
+PACKAGE_VERSION='2.1.4.oomfix'
+PACKAGE_STRING='git 2.1.4.oomfix'
PACKAGE_BUGREPORT='git@vger.kernel.org'
PACKAGE_URL=''
diff -ur orig/git-2.1.4/version git-2.1.4/version
--- orig/git-2.1.4/version 2014-12-18 18:42:19.000000000 +0000
+++ git-2.1.4/version 2019-08-29 20:06:17.572545210 +0100
@@ -1 +1 @@
-2.1.4
+2.1.4.oomfix
2019-08-29 18:12:45 +00:00
-- git before 2.22 would OOM running git status on a large file.
--
-- Older versions of git that are patched (with
-- commit 02156ab031e430bc45ce6984dfc712de9962dec8)
-- can include "oomfix" in their version to indicate it.
gitWillOOM :: Annex Bool
gitWillOOM = liftIO $ do
v <- Git . Version . installed
return $ v < Git . Version . normalize " 2.22 " &&
not ( " oomfix " ` isInfixOf ` fromDottedVersion v )
-- configureSmudgeFilter has to run git status, and direct mode files
-- are unlocked, so avoid the upgrade failing half way through.
checkGitVersionForDirectUpgrade :: Annex ()
checkGitVersionForDirectUpgrade = whenM gitWillOOM $
giveup " You must upgrade git to version 2.22 or newer in order to use this version of git-annex in this repository. "
checkGitVersionForIndirectUpgrade :: Annex ()
checkGitVersionForIndirectUpgrade = whenM gitWillOOM $
warning " Git is older than version 2.22 and so it has a memory leak that affects using unlocked files. Recommend you upgrade git before unlocking any files in your repository. "
2019-08-27 16:32:44 +00:00
convertDirect :: Annex ()
convertDirect = do
2019-08-26 17:46:58 +00:00
{- Direct mode makes the same tradeoff of using less disk
- space , with less preservation of old versions of files
- as does annex . thin . - }
setConfig ( annexConfig " thin " ) ( boolConfig True )
2019-08-26 19:52:19 +00:00
Direct . setIndirect
2019-08-26 17:46:58 +00:00
cur <- fromMaybe ( error " Somehow no branch is checked out " )
<$> inRepo Git . Branch . current
upgradeDirectWorkTree
removeDirectCruft
{- Create adjusted branch where all files are unlocked.
- This should have the same content for each file as
- have been staged in upgradeDirectWorkTree . - }
AdjBranch b <- adjustBranch ( LinkAdjustment UnlockAdjustment ) cur
{- Since the work tree was already set up by
- upgradeDirectWorkTree , and contains unlocked file
- contents too , don't use git checkout to check out the
- adjust branch . Instead , update HEAD manually . - }
inRepo $ setHeadRef b
2015-12-15 19:56:37 +00:00
{- Walk work tree from top and convert all annex symlinks to pointer files,
2019-08-27 18:08:46 +00:00
- staging them in the index , and populating the annex objects with
- hard links ( or copies ) of the work tree files ( when not modified or
- deleted ) .
- }
2015-12-15 19:56:37 +00:00
upgradeDirectWorkTree :: Annex ()
upgradeDirectWorkTree = do
top <- fromRepo Git . repoPath
2019-12-09 17:49:05 +00:00
( l , clean ) <- inRepo $ Git . LsFiles . stagedDetails [ top ]
2015-12-15 19:56:37 +00:00
forM_ l go
void $ liftIO clean
where
go ( f , Just _sha , Just mode ) | isSymLink mode = do
2015-12-27 19:59:59 +00:00
-- Cannot use lookupFile here, as we're in between direct
-- mode and v6.
mk <- catKeyFile f
2015-12-15 19:56:37 +00:00
case mk of
Nothing -> noop
Just k -> do
2019-08-26 20:34:07 +00:00
stagePointerFile f Nothing =<< hashPointerFile k
2015-12-15 19:56:37 +00:00
ifM ( isJust <$> getAnnexLinkTarget f )
2019-12-02 16:01:20 +00:00
( writepointer ( fromRawFilePath f ) k
, fromdirect ( fromRawFilePath f ) k
2015-12-15 19:56:37 +00:00
)
2016-01-05 21:22:19 +00:00
Database . Keys . addAssociatedFile k
2019-12-09 17:49:05 +00:00
=<< inRepo ( toTopFilePath f )
2015-12-15 19:56:37 +00:00
go _ = noop
2019-08-27 17:54:21 +00:00
fromdirect f k = ifM ( Direct . goodContent k f )
( do
-- If linkToAnnex fails for some reason, the work tree
-- file still has the content; the annex object file
-- is just not populated with it. Since the work tree
-- file is recorded as an associated file, things will
-- still work that way, it's just not ideal.
2019-12-11 18:12:22 +00:00
ic <- withTSDelta ( liftIO . genInodeCache ( toRawFilePath f ) )
2019-08-27 17:54:21 +00:00
void $ Content . linkToAnnex k f ic
, unlessM ( Content . inAnnex k ) $ do
-- Worktree file was deleted or modified;
-- if there are no other copies of the content
-- then it's been lost.
locs <- Direct . associatedFiles k
unlessM ( anyM ( Direct . goodContent k ) locs ) $ do
u <- getUUID
logChange k u InfoMissing
)
2019-08-26 20:34:07 +00:00
2015-12-15 19:56:37 +00:00
writepointer f k = liftIO $ do
nukeFile f
2019-01-14 19:19:20 +00:00
S . writeFile f ( formatPointer k )
2015-12-15 19:56:37 +00:00
{- Remove all direct mode bookkeeping files. -}
removeDirectCruft :: Annex ()
2019-08-27 16:59:57 +00:00
removeDirectCruft = mapM_ go =<< Content . listKeys Content . InAnywhere
2015-12-15 19:56:37 +00:00
where
go k = do
Direct . removeInodeCache k
Direct . removeAssociatedFiles k