v7 for all repositories
* Default to v7 for new repositories. * Automatically upgrade v5 repositories to v7.
This commit is contained in:
parent
1558e03014
commit
3f0eef4baa
29 changed files with 127 additions and 482 deletions
|
@ -16,7 +16,6 @@ import qualified Annex.Queue
|
|||
import qualified Database.Keys
|
||||
import Annex.FileMatcher
|
||||
import Annex.Link
|
||||
import Annex.Version
|
||||
import Annex.Tmp
|
||||
import Messages.Progress
|
||||
import Git.FilePath
|
||||
|
@ -69,10 +68,7 @@ seek o = startConcurrency commandStages $ do
|
|||
unless (updateOnly o) $
|
||||
go (withFilesNotInGit (not $ includeDotFiles o))
|
||||
go withFilesMaybeModified
|
||||
ifM versionSupportsUnlockedPointers
|
||||
( go withUnmodifiedUnlockedPointers
|
||||
, go withFilesOldUnlocked
|
||||
)
|
||||
go withUnmodifiedUnlockedPointers
|
||||
|
||||
{- Pass file off to git-add. -}
|
||||
startSmall :: FilePath -> CommandStart
|
||||
|
@ -92,12 +88,8 @@ addFile file = do
|
|||
|
||||
start :: FilePath -> CommandStart
|
||||
start file = do
|
||||
ifM versionSupportsUnlockedPointers
|
||||
( do
|
||||
mk <- liftIO $ isPointerFile file
|
||||
maybe go fixuppointer mk
|
||||
, go
|
||||
)
|
||||
mk <- liftIO $ isPointerFile file
|
||||
maybe go fixuppointer mk
|
||||
where
|
||||
go = ifAnnexed file addpresent add
|
||||
add = liftIO (catchMaybeIO $ getSymbolicLinkStatus file) >>= \case
|
||||
|
@ -109,12 +101,10 @@ start file = do
|
|||
if isSymbolicLink s
|
||||
then next $ addFile file
|
||||
else perform file
|
||||
addpresent key = ifM versionSupportsUnlockedPointers
|
||||
( liftIO (catchMaybeIO $ getSymbolicLinkStatus file) >>= \case
|
||||
addpresent key =
|
||||
liftIO (catchMaybeIO $ getSymbolicLinkStatus file) >>= \case
|
||||
Just s | isSymbolicLink s -> fixuplink key
|
||||
_ -> add
|
||||
, fixuplink key
|
||||
)
|
||||
fixuplink key = starting "add" (ActionItemWorkTreeFile file) $ do
|
||||
-- the annexed symlink is present but not yet added to git
|
||||
liftIO $ removeFile file
|
||||
|
|
|
@ -12,7 +12,6 @@ module Command.Fix where
|
|||
import Command
|
||||
import Config
|
||||
import qualified Annex
|
||||
import Annex.Version
|
||||
import Annex.ReplaceFile
|
||||
import Annex.Content
|
||||
import Annex.Perms
|
||||
|
@ -32,12 +31,8 @@ cmd = noCommit $ withGlobalOptions [annexedMatchingOptions] $
|
|||
|
||||
seek :: CmdParams -> CommandSeek
|
||||
seek ps = unlessM crippledFileSystem $ do
|
||||
fixwhat <- ifM versionSupportsUnlockedPointers
|
||||
( return FixAll
|
||||
, return FixSymlinks
|
||||
)
|
||||
withFilesInGit
|
||||
(commandAction . (whenAnnexed $ start fixwhat))
|
||||
(commandAction . (whenAnnexed $ start FixAll))
|
||||
=<< workTreeItems ps
|
||||
|
||||
data FixWhat = FixSymlinks | FixAll
|
||||
|
|
|
@ -10,7 +10,6 @@ module Command.Lock where
|
|||
import Command
|
||||
import qualified Annex.Queue
|
||||
import qualified Annex
|
||||
import Annex.Version
|
||||
import Annex.Content
|
||||
import Annex.Link
|
||||
import Annex.InodeSentinal
|
||||
|
@ -31,12 +30,7 @@ cmd = withGlobalOptions [jsonOptions, annexedMatchingOptions] $
|
|||
seek :: CmdParams -> CommandSeek
|
||||
seek ps = do
|
||||
l <- workTreeItems ps
|
||||
ifM versionSupportsUnlockedPointers
|
||||
( withFilesInGit (commandAction . (whenAnnexed startNew)) l
|
||||
, do
|
||||
withFilesOldUnlocked (commandAction . startOld) l
|
||||
withFilesOldUnlockedToBeCommitted (commandAction . startOld) l
|
||||
)
|
||||
withFilesInGit (commandAction . (whenAnnexed startNew)) l
|
||||
|
||||
startNew :: FilePath -> Key -> CommandStart
|
||||
startNew file key = ifM (isJust <$> isAnnexLink file)
|
||||
|
|
|
@ -10,21 +10,17 @@
|
|||
module Command.PreCommit where
|
||||
|
||||
import Command
|
||||
import qualified Command.Add
|
||||
import qualified Command.Fix
|
||||
import qualified Command.Smudge
|
||||
import Annex.Hook
|
||||
import Annex.Link
|
||||
import Annex.View
|
||||
import Annex.Version
|
||||
import Annex.View.ViewedFile
|
||||
import Annex.LockFile
|
||||
import Logs.View
|
||||
import Logs.MetaData
|
||||
import Types.View
|
||||
import Types.MetaData
|
||||
import qualified Git.Index as Git
|
||||
import qualified Git.LsFiles as Git
|
||||
|
||||
import qualified Data.Set as S
|
||||
import qualified Data.Text as T
|
||||
|
@ -37,31 +33,14 @@ cmd = command "pre-commit" SectionPlumbing
|
|||
|
||||
seek :: CmdParams -> CommandSeek
|
||||
seek ps = lockPreCommitHook $ do
|
||||
ifM (not <$> versionSupportsUnlockedPointers <&&> liftIO Git.haveFalseIndex)
|
||||
( do
|
||||
(fs, cleanup) <- inRepo $ Git.typeChangedStaged ps
|
||||
whenM (anyM isOldUnlocked fs) $
|
||||
giveup "Cannot make a partial commit with unlocked annexed files. You should `git annex add` the files you want to commit, and then run git commit."
|
||||
void $ liftIO cleanup
|
||||
, do
|
||||
l <- workTreeItems ps
|
||||
-- fix symlinks to files being committed
|
||||
flip withFilesToBeCommitted l $ \f -> commandAction $
|
||||
maybe stop (Command.Fix.start Command.Fix.FixSymlinks f)
|
||||
=<< isAnnexLink f
|
||||
ifM versionSupportsUnlockedPointers
|
||||
-- after a merge conflict or git
|
||||
-- cherry-pick or stash, pointer
|
||||
-- files in the worktree won't
|
||||
-- be populated, so populate them
|
||||
-- here
|
||||
( Command.Smudge.updateSmudged (Restage False)
|
||||
-- inject unlocked files into the annex
|
||||
-- (not needed when repo version uses
|
||||
-- unlocked pointer files)
|
||||
, withFilesOldUnlockedToBeCommitted (commandAction . startInjectUnlocked) l
|
||||
)
|
||||
)
|
||||
l <- workTreeItems ps
|
||||
-- fix symlinks to files being committed
|
||||
flip withFilesToBeCommitted l $ \f -> commandAction $
|
||||
maybe stop (Command.Fix.start Command.Fix.FixSymlinks f)
|
||||
=<< isAnnexLink f
|
||||
-- after a merge conflict or git cherry-pick or stash, pointer
|
||||
-- files in the worktree won't be populated, so populate them here
|
||||
Command.Smudge.updateSmudged (Restage False)
|
||||
|
||||
runAnnexHook preCommitAnnexHook
|
||||
|
||||
|
@ -73,12 +52,6 @@ seek ps = lockPreCommitHook $ do
|
|||
(addViewMetaData v)
|
||||
(removeViewMetaData v)
|
||||
|
||||
startInjectUnlocked :: FilePath -> CommandStart
|
||||
startInjectUnlocked f = startingCustomOutput (ActionItemOther Nothing) $ do
|
||||
unlessM (callCommandAction $ Command.Add.start f) $
|
||||
error $ "failed to add " ++ f ++ "; canceling commit"
|
||||
next $ return True
|
||||
|
||||
addViewMetaData :: View -> ViewedFile -> Key -> CommandStart
|
||||
addViewMetaData v f k = starting "metadata" (mkActionItem (k, f)) $
|
||||
next $ changeMetaData k $ fromView v f
|
||||
|
|
|
@ -11,13 +11,8 @@ import Command
|
|||
import qualified Annex
|
||||
import Annex.Content
|
||||
import Annex.Perms
|
||||
import Annex.Version
|
||||
import qualified Git.Command
|
||||
import qualified Git.Branch
|
||||
import qualified Git.Ref
|
||||
import qualified Git.DiffTree as DiffTree
|
||||
import Utility.CopyFile
|
||||
import Command.PreCommit (lockPreCommitHook)
|
||||
import qualified Database.Keys
|
||||
import Git.FilePath
|
||||
|
||||
|
@ -28,40 +23,7 @@ cmd = withGlobalOptions [annexedMatchingOptions] $
|
|||
paramPaths (withParams seek)
|
||||
|
||||
seek :: CmdParams -> CommandSeek
|
||||
seek ps = wrapUnannex $
|
||||
(withFilesInGit $ commandAction . whenAnnexed start) =<< workTreeItems ps
|
||||
|
||||
wrapUnannex :: Annex a -> Annex a
|
||||
wrapUnannex a = ifM versionSupportsUnlockedPointers
|
||||
( a
|
||||
{- Run with the pre-commit hook disabled, to avoid confusing
|
||||
- behavior if an unannexed file is added back to git as
|
||||
- a normal, non-annexed file and then committed.
|
||||
- Otherwise, the pre-commit hook would think that the file
|
||||
- has been unlocked and needs to be re-annexed.
|
||||
-
|
||||
- At the end, make a commit removing the unannexed files.
|
||||
-}
|
||||
, ifM cleanindex
|
||||
( lockPreCommitHook $ commit `after` a
|
||||
, giveup "Cannot proceed with uncommitted changes staged in the index. Recommend you: git commit"
|
||||
)
|
||||
)
|
||||
where
|
||||
commit = inRepo $ Git.Branch.commitCommand Git.Branch.ManualCommit
|
||||
[ Param "-q"
|
||||
, Param "--allow-empty"
|
||||
, Param "--no-verify"
|
||||
, Param "-m", Param "content removed from git annex"
|
||||
]
|
||||
cleanindex = ifM (inRepo Git.Ref.headExists)
|
||||
( do
|
||||
(diff, reap) <- inRepo $ DiffTree.diffIndex Git.Ref.headRef
|
||||
if null diff
|
||||
then void (liftIO reap) >> return True
|
||||
else void (liftIO reap) >> return False
|
||||
, return False
|
||||
)
|
||||
seek ps = (withFilesInGit $ commandAction . whenAnnexed start) =<< workTreeItems ps
|
||||
|
||||
start :: FilePath -> Key -> CommandStart
|
||||
start file key = stopUnless (inAnnex key) $
|
||||
|
|
|
@ -10,11 +10,8 @@ module Command.Unlock where
|
|||
import Command
|
||||
import Annex.Content
|
||||
import Annex.Perms
|
||||
import Annex.CatFile
|
||||
import Annex.Version
|
||||
import Annex.Link
|
||||
import Annex.ReplaceFile
|
||||
import Utility.CopyFile
|
||||
import Git.FilePath
|
||||
import qualified Database.Keys
|
||||
|
||||
|
@ -37,15 +34,12 @@ seek ps = withFilesInGit (commandAction . whenAnnexed start) =<< workTreeItems p
|
|||
start :: FilePath -> Key -> CommandStart
|
||||
start file key = ifM (isJust <$> isAnnexLink file)
|
||||
( starting "unlock" (mkActionItem (key, AssociatedFile (Just file))) $
|
||||
ifM versionSupportsUnlockedPointers
|
||||
( performNew file key
|
||||
, performOld file key
|
||||
)
|
||||
perform file key
|
||||
, stop
|
||||
)
|
||||
|
||||
performNew :: FilePath -> Key -> CommandPerform
|
||||
performNew dest key = do
|
||||
perform :: FilePath -> Key -> CommandPerform
|
||||
perform dest key = do
|
||||
destmode <- liftIO $ catchMaybeIO $ fileMode <$> getFileStatus dest
|
||||
replaceFile dest $ \tmp ->
|
||||
ifM (inAnnex key)
|
||||
|
@ -57,47 +51,10 @@ performNew dest key = do
|
|||
LinkAnnexFailed -> error "unlock failed"
|
||||
, liftIO $ writePointerFile tmp key destmode
|
||||
)
|
||||
next $ cleanupNew dest key destmode
|
||||
next $ cleanup dest key destmode
|
||||
|
||||
cleanupNew :: FilePath -> Key -> Maybe FileMode -> CommandCleanup
|
||||
cleanupNew dest key destmode = do
|
||||
cleanup :: FilePath -> Key -> Maybe FileMode -> CommandCleanup
|
||||
cleanup dest key destmode = do
|
||||
stagePointerFile dest destmode =<< hashPointerFile key
|
||||
Database.Keys.addAssociatedFile key =<< inRepo (toTopFilePath dest)
|
||||
return True
|
||||
|
||||
performOld :: FilePath -> Key -> CommandPerform
|
||||
performOld file key =
|
||||
ifM (inAnnex key)
|
||||
( ifM (isJust <$> catKeyFileHEAD file)
|
||||
( performOld' file key
|
||||
, do
|
||||
warning "this has not yet been committed to git; cannot unlock it"
|
||||
next $ return False
|
||||
)
|
||||
, do
|
||||
warning "content not present; cannot unlock"
|
||||
next $ return False
|
||||
)
|
||||
|
||||
performOld' :: FilePath -> Key -> CommandPerform
|
||||
performOld' dest key = ifM (checkDiskSpace Nothing key 0 True)
|
||||
( do
|
||||
src <- calcRepo $ gitAnnexLocation key
|
||||
tmpdest <- fromRepo $ gitAnnexTmpObjectLocation key
|
||||
liftIO $ createDirectoryIfMissing True (parentDir tmpdest)
|
||||
showAction "copying"
|
||||
ifM (liftIO $ copyFileExternal CopyAllMetaData src tmpdest)
|
||||
( do
|
||||
liftIO $ do
|
||||
removeFile dest
|
||||
moveFile tmpdest dest
|
||||
thawContent dest
|
||||
next $ return True
|
||||
, do
|
||||
warning "copy failed!"
|
||||
next $ return False
|
||||
)
|
||||
, do
|
||||
warning "not enough disk space to copy file"
|
||||
next $ return False
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue