make sync update --unlock-present branch

This commit is contained in:
Joey Hess 2020-11-13 14:58:42 -04:00
parent e66b7d2e1b
commit ccfa9b2dc4
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 47 additions and 36 deletions

View file

@ -13,6 +13,7 @@ module Annex.AdjustedBranch (
PresenceAdjustment(..), PresenceAdjustment(..),
LinkPresentAdjustment(..), LinkPresentAdjustment(..),
adjustmentHidesFiles, adjustmentHidesFiles,
adjustmentIsStable,
OrigBranch, OrigBranch,
AdjBranch(..), AdjBranch(..),
originalToAdjusted, originalToAdjusted,
@ -66,9 +67,11 @@ import qualified Data.Map as M
import qualified Data.ByteString as S import qualified Data.ByteString as S
import qualified System.FilePath.ByteString as P import qualified System.FilePath.ByteString as P
-- How to perform various adjustments to a TreeItem.
class AdjustTreeItem t where class AdjustTreeItem t where
-- How to perform various adjustments to a TreeItem.
adjustTreeItem :: t -> TreeItem -> Annex (Maybe TreeItem) adjustTreeItem :: t -> TreeItem -> Annex (Maybe TreeItem)
-- Will adjusting a given tree always yield the same adjusted tree?
adjustmentIsStable :: t -> Bool
instance AdjustTreeItem Adjustment where instance AdjustTreeItem Adjustment where
adjustTreeItem (LinkAdjustment l) t = adjustTreeItem l t adjustTreeItem (LinkAdjustment l) t = adjustTreeItem l t
@ -79,6 +82,10 @@ instance AdjustTreeItem Adjustment where
Just t' -> adjustTreeItem l t' Just t' -> adjustTreeItem l t'
adjustTreeItem (LinkPresentAdjustment l) t = adjustTreeItem l t adjustTreeItem (LinkPresentAdjustment l) t = adjustTreeItem l t
adjustmentIsStable (LinkAdjustment l) = adjustmentIsStable l
adjustmentIsStable (PresenceAdjustment p _) = adjustmentIsStable p
adjustmentIsStable (LinkPresentAdjustment l) = adjustmentIsStable l
instance AdjustTreeItem LinkAdjustment where instance AdjustTreeItem LinkAdjustment where
adjustTreeItem UnlockAdjustment = adjustTreeItem UnlockAdjustment =
ifSymlink adjustToPointer noAdjust ifSymlink adjustToPointer noAdjust
@ -89,12 +96,17 @@ instance AdjustTreeItem LinkAdjustment where
adjustTreeItem UnFixAdjustment = adjustTreeItem UnFixAdjustment =
ifSymlink (adjustToSymlink' gitAnnexLinkCanonical) noAdjust ifSymlink (adjustToSymlink' gitAnnexLinkCanonical) noAdjust
adjustmentIsStable _ = True
instance AdjustTreeItem PresenceAdjustment where instance AdjustTreeItem PresenceAdjustment where
adjustTreeItem HideMissingAdjustment = adjustTreeItem HideMissingAdjustment =
ifPresent noAdjust hideAdjust ifPresent noAdjust hideAdjust
adjustTreeItem ShowMissingAdjustment = adjustTreeItem ShowMissingAdjustment =
noAdjust noAdjust
adjustmentIsStable HideMissingAdjustment = False
adjustmentIsStable ShowMissingAdjustment = True
instance AdjustTreeItem LinkPresentAdjustment where instance AdjustTreeItem LinkPresentAdjustment where
adjustTreeItem UnlockPresentAdjustment = adjustTreeItem UnlockPresentAdjustment =
ifPresent adjustToPointer adjustToSymlink ifPresent adjustToPointer adjustToSymlink
@ -106,6 +118,9 @@ instance AdjustTreeItem LinkPresentAdjustment where
-- content is not present. -- content is not present.
ifSymlink noAdjust adjustToSymlink ifSymlink noAdjust adjustToSymlink
adjustmentIsStable UnlockPresentAdjustment = False
adjustmentIsStable LockPresentAdjustment = True
ifSymlink ifSymlink
:: (TreeItem -> Annex a) :: (TreeItem -> Annex a)
-> (TreeItem -> Annex a) -> (TreeItem -> Annex a)
@ -222,33 +237,24 @@ checkoutAdjustedBranch (AdjBranch b) checkoutparams = do
] ++ checkoutparams ] ++ checkoutparams
{- Already in a branch with this adjustment, but the user asked to enter it {- Already in a branch with this adjustment, but the user asked to enter it
- again. This should have the same result as checking out the original branch, - again. This should have the same result as propagating any commits
- deleting and rebuilding the adjusted branch, and then checking it out. - back to the original branch, checking out the original branch, deleting
- and rebuilding the adjusted branch, and then checking it out.
- But, it can be implemented more efficiently than that. - But, it can be implemented more efficiently than that.
-} -}
updateAdjustedBranch :: Adjustment -> AdjBranch -> OrigBranch -> Annex Bool updateAdjustedBranch :: Adjustment -> AdjBranch -> OrigBranch -> Annex Bool
updateAdjustedBranch adj@(PresenceAdjustment _ _) currbranch origbranch = updateAdjustedBranch adj (AdjBranch currbranch) origbranch
updateAdjustedBranch' adj currbranch origbranch | not (adjustmentIsStable adj) = do
updateAdjustedBranch adj@(LinkPresentAdjustment _) currbranch origbranch =
updateAdjustedBranch' adj currbranch origbranch
updateAdjustedBranch adj@(LinkAdjustment _) _ origbranch =
preventCommits $ \commitlck -> do
-- Not really needed here, but done for consistency.
_ <- propigateAdjustedCommits' origbranch adj commitlck
-- No need to do anything else, because link adjustments
-- are stable.
return True
updateAdjustedBranch' :: Adjustment -> AdjBranch -> OrigBranch -> Annex Bool
updateAdjustedBranch' adj (AdjBranch currbranch) origbranch = do
b <- preventCommits $ \commitlck -> do b <- preventCommits $ \commitlck -> do
-- Avoid losing any commits that the adjusted branch has that -- Avoid losing any commits that the adjusted branch
-- have not yet been propigated back to the origbranch. -- has that have not yet been propigated back to the
-- origbranch.
_ <- propigateAdjustedCommits' origbranch adj commitlck _ <- propigateAdjustedCommits' origbranch adj commitlck
-- Git normally won't do anything when asked to check out the -- Git normally won't do anything when asked to check
-- currently checked out branch, even when its ref has -- out the currently checked out branch, even when its
-- changed. Work around this by writing a raw sha to .git/HEAD. -- ref has changed. Work around this by writing a raw
-- sha to .git/HEAD.
inRepo (Git.Ref.sha currbranch) >>= \case inRepo (Git.Ref.sha currbranch) >>= \case
Just headsha -> inRepo $ \r -> Just headsha -> inRepo $ \r ->
writeFile (Git.Ref.headFile r) (fromRef headsha) writeFile (Git.Ref.headFile r) (fromRef headsha)
@ -256,9 +262,15 @@ updateAdjustedBranch' adj (AdjBranch currbranch) origbranch = do
adjustBranch adj origbranch adjustBranch adj origbranch
-- Make git checkout quiet to avoid warnings about disconnected -- Make git checkout quiet to avoid warnings about
-- branch tips being lost. -- disconnected branch tips being lost.
checkoutAdjustedBranch b [Param "--quiet"] checkoutAdjustedBranch b [Param "--quiet"]
| otherwise = preventCommits $ \commitlck -> do
-- Done for consistency.
_ <- propigateAdjustedCommits' origbranch adj commitlck
-- No need to actually update the branch because the
-- adjustment is stable.
return True
adjustToCrippledFileSystem :: Annex () adjustToCrippledFileSystem :: Annex ()
adjustToCrippledFileSystem = do adjustToCrippledFileSystem = do

View file

@ -406,13 +406,13 @@ updateBranches (Nothing, _) = noop
updateBranches (Just branch, madj) = do updateBranches (Just branch, madj) = do
-- When in an adjusted branch, propigate any changes made to it -- When in an adjusted branch, propigate any changes made to it
-- back to the original branch. The adjusted branch may also need -- back to the original branch. The adjusted branch may also need
-- to be updated to hide/expose files. -- to be updated, if the adjustment is not stable.
case madj of case madj of
Nothing -> noop Nothing -> noop
Just adj -> do Just adj -> do
let origbranch = branch let origbranch = branch
propigateAdjustedCommits origbranch adj propigateAdjustedCommits origbranch adj
when (adjustmentHidesFiles adj) $ do unless (adjustmentIsStable adj) $ do
showSideAction "updating adjusted branch" showSideAction "updating adjusted branch"
let adjbranch = originalToAdjusted origbranch adj let adjbranch = originalToAdjusted origbranch adj
unlessM (updateAdjustedBranch adj adjbranch origbranch) $ unlessM (updateAdjustedBranch adj adjbranch origbranch) $

View file

@ -62,4 +62,3 @@ instance ReversableAdjustment LinkPresentAdjustment where
adjustmentHidesFiles :: Adjustment -> Bool adjustmentHidesFiles :: Adjustment -> Bool
adjustmentHidesFiles (PresenceAdjustment HideMissingAdjustment _) = True adjustmentHidesFiles (PresenceAdjustment HideMissingAdjustment _) = True
adjustmentHidesFiles _ = False adjustmentHidesFiles _ = False