rename to --unlock-present and better reverse adjusting

An --unlock-present branch reverses back to a branch where
all files that get modified or renamed become locked, even if they were
originally unlocked. This is the same that reversing a --unlock branch
works, and the new name makes that commonality more clear.
This commit is contained in:
Joey Hess 2020-11-13 14:32:06 -04:00
parent 3899e216af
commit e66b7d2e1b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 42 additions and 37 deletions

View file

@ -11,7 +11,7 @@ module Annex.AdjustedBranch (
Adjustment(..), Adjustment(..),
LinkAdjustment(..), LinkAdjustment(..),
PresenceAdjustment(..), PresenceAdjustment(..),
LinkMissingAdjustment(..), LinkPresentAdjustment(..),
adjustmentHidesFiles, adjustmentHidesFiles,
OrigBranch, OrigBranch,
AdjBranch(..), AdjBranch(..),
@ -77,7 +77,7 @@ instance AdjustTreeItem Adjustment where
adjustTreeItem p t >>= \case adjustTreeItem p t >>= \case
Nothing -> return Nothing Nothing -> return Nothing
Just t' -> adjustTreeItem l t' Just t' -> adjustTreeItem l t'
adjustTreeItem (LinkMissingAdjustment l) t = adjustTreeItem l t adjustTreeItem (LinkPresentAdjustment l) t = adjustTreeItem l t
instance AdjustTreeItem LinkAdjustment where instance AdjustTreeItem LinkAdjustment where
adjustTreeItem UnlockAdjustment = adjustTreeItem UnlockAdjustment =
@ -95,11 +95,16 @@ instance AdjustTreeItem PresenceAdjustment where
adjustTreeItem ShowMissingAdjustment = adjustTreeItem ShowMissingAdjustment =
noAdjust noAdjust
instance AdjustTreeItem LinkMissingAdjustment where instance AdjustTreeItem LinkPresentAdjustment where
adjustTreeItem LockMissingAdjustment = adjustTreeItem UnlockPresentAdjustment =
ifPresent adjustToPointer adjustToSymlink ifPresent adjustToPointer adjustToSymlink
adjustTreeItem UnlockMissingAdjustment = adjustTreeItem LockPresentAdjustment =
noAdjust -- Turn all pointers back to symlinks, whether the content
-- is present or not. This is done because the content
-- availability may have changed and the branch not been
-- re-adjusted to keep up, so there may be pointers whose
-- content is not present.
ifSymlink noAdjust adjustToSymlink
ifSymlink ifSymlink
:: (TreeItem -> Annex a) :: (TreeItem -> Annex a)
@ -224,7 +229,7 @@ checkoutAdjustedBranch (AdjBranch b) checkoutparams = do
updateAdjustedBranch :: Adjustment -> AdjBranch -> OrigBranch -> Annex Bool updateAdjustedBranch :: Adjustment -> AdjBranch -> OrigBranch -> Annex Bool
updateAdjustedBranch adj@(PresenceAdjustment _ _) currbranch origbranch = updateAdjustedBranch adj@(PresenceAdjustment _ _) currbranch origbranch =
updateAdjustedBranch' adj currbranch origbranch updateAdjustedBranch' adj currbranch origbranch
updateAdjustedBranch adj@(LinkMissingAdjustment _) currbranch origbranch = updateAdjustedBranch adj@(LinkPresentAdjustment _) currbranch origbranch =
updateAdjustedBranch' adj currbranch origbranch updateAdjustedBranch' adj currbranch origbranch
updateAdjustedBranch adj@(LinkAdjustment _) _ origbranch = updateAdjustedBranch adj@(LinkAdjustment _) _ origbranch =
preventCommits $ \commitlck -> do preventCommits $ \commitlck -> do

View file

@ -37,7 +37,7 @@ instance SerializeAdjustment Adjustment where
serializeAdjustment p serializeAdjustment p
serializeAdjustment (PresenceAdjustment p (Just l)) = serializeAdjustment (PresenceAdjustment p (Just l)) =
serializeAdjustment p <> "-" <> serializeAdjustment l serializeAdjustment p <> "-" <> serializeAdjustment l
serializeAdjustment (LinkMissingAdjustment l) = serializeAdjustment (LinkPresentAdjustment l) =
serializeAdjustment l serializeAdjustment l
deserializeAdjustment s = deserializeAdjustment s =
(LinkAdjustment <$> deserializeAdjustment s) (LinkAdjustment <$> deserializeAdjustment s)
@ -46,7 +46,7 @@ instance SerializeAdjustment Adjustment where
<|> <|>
(PresenceAdjustment <$> deserializeAdjustment s <*> pure Nothing) (PresenceAdjustment <$> deserializeAdjustment s <*> pure Nothing)
<|> <|>
(LinkMissingAdjustment <$> deserializeAdjustment s) (LinkPresentAdjustment <$> deserializeAdjustment s)
where where
(s1, s2) = separate' (== (fromIntegral (ord '-'))) s (s1, s2) = separate' (== (fromIntegral (ord '-'))) s
@ -68,11 +68,11 @@ instance SerializeAdjustment PresenceAdjustment where
deserializeAdjustment "showmissing" = Just ShowMissingAdjustment deserializeAdjustment "showmissing" = Just ShowMissingAdjustment
deserializeAdjustment _ = Nothing deserializeAdjustment _ = Nothing
instance SerializeAdjustment LinkMissingAdjustment where instance SerializeAdjustment LinkPresentAdjustment where
serializeAdjustment LockMissingAdjustment = "lockmissing" serializeAdjustment UnlockPresentAdjustment = "unlockpresent"
serializeAdjustment UnlockMissingAdjustment = "unlockmissing" serializeAdjustment LockPresentAdjustment = "lockpresent"
deserializeAdjustment "lockmissing" = Just LockMissingAdjustment deserializeAdjustment "unlockpresent" = Just UnlockPresentAdjustment
deserializeAdjustment "unlockmissing" = Just UnlockMissingAdjustment deserializeAdjustment "lockpresent" = Just LockPresentAdjustment
deserializeAdjustment _ = Nothing deserializeAdjustment _ = Nothing
newtype AdjBranch = AdjBranch { adjBranch :: Branch } newtype AdjBranch = AdjBranch { adjBranch :: Branch }

View file

@ -10,7 +10,7 @@ git-annex (8.20201104) UNRELEASED; urgency=medium
copied it from some other repository. copied it from some other repository.
* examinekey: Added two new format variables: objectpath and objectpointer * examinekey: Added two new format variables: objectpath and objectpointer
* examinekey: Added --migrate-to-backend * examinekey: Added --migrate-to-backend
* adjust: New --lock-missing mode which locks files whose content is not * adjust: New --unlock-present mode which locks files whose content is not
present (so the broken symlink is visible), while unlocking files whose present (so the broken symlink is visible), while unlocking files whose
content is present. content is present.

View file

@ -19,7 +19,7 @@ optParser :: CmdParamsDesc -> Parser Adjustment
optParser _ = optParser _ =
(LinkAdjustment <$> linkAdjustmentParser) (LinkAdjustment <$> linkAdjustmentParser)
<|> (PresenceAdjustment <$> presenceAdjustmentParser <*> maybeLinkAdjustmentParser) <|> (PresenceAdjustment <$> presenceAdjustmentParser <*> maybeLinkAdjustmentParser)
<|> (LinkMissingAdjustment <$> linkMissingAdjustmentParser) <|> (LinkPresentAdjustment <$> linkPresentAdjustmentParser)
linkAdjustmentParser :: Parser LinkAdjustment linkAdjustmentParser :: Parser LinkAdjustment
linkAdjustmentParser = linkAdjustmentParser =
@ -46,11 +46,11 @@ presenceAdjustmentParser =
<> help "hide annexed files whose content is not present" <> help "hide annexed files whose content is not present"
) )
linkMissingAdjustmentParser :: Parser LinkMissingAdjustment linkPresentAdjustmentParser :: Parser LinkPresentAdjustment
linkMissingAdjustmentParser = linkPresentAdjustmentParser =
flag' LockMissingAdjustment flag' UnlockPresentAdjustment
( long "lock-missing" ( long "unlock-present"
<> help "lock files whose content is present; unlock rest" <> help "unlock files whose content is present; lock rest"
) )
seek :: Adjustment -> CommandSeek seek :: Adjustment -> CommandSeek

View file

@ -10,7 +10,7 @@ module Types.AdjustedBranch where
data Adjustment data Adjustment
= LinkAdjustment LinkAdjustment = LinkAdjustment LinkAdjustment
| PresenceAdjustment PresenceAdjustment (Maybe LinkAdjustment) | PresenceAdjustment PresenceAdjustment (Maybe LinkAdjustment)
| LinkMissingAdjustment LinkMissingAdjustment | LinkPresentAdjustment LinkPresentAdjustment
deriving (Show, Eq) deriving (Show, Eq)
data LinkAdjustment data LinkAdjustment
@ -25,9 +25,9 @@ data PresenceAdjustment
| ShowMissingAdjustment | ShowMissingAdjustment
deriving (Show, Eq) deriving (Show, Eq)
data LinkMissingAdjustment data LinkPresentAdjustment
= LockMissingAdjustment = UnlockPresentAdjustment
| UnlockMissingAdjustment | LockPresentAdjustment
deriving (Show, Eq) deriving (Show, Eq)
-- Adjustments have to be able to be reversed, so that commits made to the -- Adjustments have to be able to be reversed, so that commits made to the
@ -41,8 +41,8 @@ instance ReversableAdjustment Adjustment where
LinkAdjustment (reverseAdjustment l) LinkAdjustment (reverseAdjustment l)
reverseAdjustment (PresenceAdjustment p ml) = reverseAdjustment (PresenceAdjustment p ml) =
PresenceAdjustment (reverseAdjustment p) (fmap reverseAdjustment ml) PresenceAdjustment (reverseAdjustment p) (fmap reverseAdjustment ml)
reverseAdjustment (LinkMissingAdjustment l) = reverseAdjustment (LinkPresentAdjustment l) =
LinkMissingAdjustment (reverseAdjustment l) LinkPresentAdjustment (reverseAdjustment l)
instance ReversableAdjustment LinkAdjustment where instance ReversableAdjustment LinkAdjustment where
reverseAdjustment UnlockAdjustment = LockAdjustment reverseAdjustment UnlockAdjustment = LockAdjustment
@ -55,9 +55,9 @@ instance ReversableAdjustment PresenceAdjustment where
reverseAdjustment HideMissingAdjustment = ShowMissingAdjustment reverseAdjustment HideMissingAdjustment = ShowMissingAdjustment
reverseAdjustment ShowMissingAdjustment = HideMissingAdjustment reverseAdjustment ShowMissingAdjustment = HideMissingAdjustment
instance ReversableAdjustment LinkMissingAdjustment where instance ReversableAdjustment LinkPresentAdjustment where
reverseAdjustment LockMissingAdjustment = UnlockMissingAdjustment reverseAdjustment UnlockPresentAdjustment = LockPresentAdjustment
reverseAdjustment UnlockMissingAdjustment = LockMissingAdjustment reverseAdjustment LockPresentAdjustment = UnlockPresentAdjustment
adjustmentHidesFiles :: Adjustment -> Bool adjustmentHidesFiles :: Adjustment -> Bool
adjustmentHidesFiles (PresenceAdjustment HideMissingAdjustment _) = True adjustmentHidesFiles (PresenceAdjustment HideMissingAdjustment _) = True

View file

@ -4,7 +4,7 @@ git-annex adjust - enter an adjusted branch
# SYNOPSIS # SYNOPSIS
git annex adjust `--unlock|--lock|--fix|--hide-missing [--unlock|--lock|--fix]` git annex adjust `--unlock|--lock|--fix|--hide-missing [--unlock|--lock|--fix]|--unlock-present`
# DESCRIPTION # DESCRIPTION
@ -31,8 +31,8 @@ problems, use `git annex merge otherbranch`.
Re-running this command with the same options Re-running this command with the same options
while inside the adjusted branch will update the adjusted branch while inside the adjusted branch will update the adjusted branch
as necessary (eg for `--hide-missing`), and will also propagate commits as necessary (eg for `--hide-missing` and `--unlock-present`),
back to the original branch. and will also propagate commits back to the original branch.
# OPTIONS # OPTIONS
@ -91,10 +91,10 @@ back to the original branch.
This option can be combined with --unlock, --lock, or --fix. This option can be combined with --unlock, --lock, or --fix.
* `--lock-missing` * `--unlock-present`
Lock files whose content is not present, and unlock files whose content Unlock files whose content is present, and lock files whose content is
is present. This provides the benefits of working with unlocked files, missing. This provides the benefits of working with unlocked files,
but makes it easier to see when the content of a file is not missing, but makes it easier to see when the content of a file is not missing,
since it will be a broken symlink. since it will be a broken symlink.
@ -104,7 +104,7 @@ back to the original branch.
not be broken symlinks. not be broken symlinks.
To update the adjusted branch to reflect changes to content availability, To update the adjusted branch to reflect changes to content availability,
run `git annex adjust --hide-missing` again. Or use `git-annex sync run `git annex adjust --unlock-present` again. Or use `git-annex sync
--content`, which updates the branch after transferring content. --content`, which updates the branch after transferring content.
# SEE ALSO # SEE ALSO