2013-08-31 21:38:33 +00:00
|
|
|
{- git-annex branch transitions
|
|
|
|
-
|
2021-05-13 18:43:25 +00:00
|
|
|
- Copyright 2013-2021 Joey Hess <id@joeyh.name>
|
2013-08-31 21:38:33 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-08-31 21:38:33 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Annex.Branch.Transitions (
|
2021-05-17 15:06:47 +00:00
|
|
|
getTransitionCalculator,
|
|
|
|
filterBranch,
|
2013-08-31 21:38:33 +00:00
|
|
|
) where
|
|
|
|
|
2019-01-03 17:21:48 +00:00
|
|
|
import Common
|
2013-08-31 21:38:33 +00:00
|
|
|
import Logs
|
|
|
|
import Logs.Transitions
|
2014-07-24 20:23:36 +00:00
|
|
|
import qualified Logs.UUIDBased as UUIDBased
|
|
|
|
import qualified Logs.Presence.Pure as Presence
|
|
|
|
import qualified Logs.Chunk.Pure as Chunk
|
2018-09-05 17:20:10 +00:00
|
|
|
import qualified Logs.MetaData.Pure as MetaData
|
2019-10-15 15:33:33 +00:00
|
|
|
import qualified Logs.Remote.Pure as Remote
|
2023-11-13 18:16:55 +00:00
|
|
|
import Logs.MapLog
|
2013-08-31 21:38:33 +00:00
|
|
|
import Types.TrustLevel
|
|
|
|
import Types.UUID
|
2018-09-05 17:20:10 +00:00
|
|
|
import Types.MetaData
|
2019-10-14 19:38:07 +00:00
|
|
|
import Types.Remote
|
2021-12-28 17:23:32 +00:00
|
|
|
import Types.Transitions
|
2020-02-14 23:38:50 +00:00
|
|
|
import Types.GitConfig (GitConfig)
|
2020-01-10 18:10:20 +00:00
|
|
|
import Types.ProposedAccepted
|
2019-10-14 19:38:07 +00:00
|
|
|
import Annex.SpecialRemote.Config
|
2013-08-31 21:38:33 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
2019-10-15 15:33:33 +00:00
|
|
|
import qualified Data.Set as S
|
2019-01-10 17:23:42 +00:00
|
|
|
import qualified Data.Attoparsec.ByteString.Lazy as A
|
2019-01-03 17:21:48 +00:00
|
|
|
import Data.ByteString.Builder
|
2013-08-31 21:38:33 +00:00
|
|
|
|
2021-12-28 17:23:32 +00:00
|
|
|
getTransitionCalculator :: Transition -> Maybe (TrustMap -> M.Map UUID RemoteConfig -> GitConfig -> TransitionCalculator)
|
2013-08-31 21:38:33 +00:00
|
|
|
getTransitionCalculator ForgetGitHistory = Nothing
|
|
|
|
getTransitionCalculator ForgetDeadRemotes = Just dropDead
|
|
|
|
|
2019-10-14 19:38:07 +00:00
|
|
|
-- Removes data about all dead repos.
|
|
|
|
--
|
|
|
|
-- The trust log is not changed, because other, unmerged clones
|
2021-04-13 19:00:23 +00:00
|
|
|
-- may contain other data about the dead repos. So we need to remember
|
2019-10-14 19:38:07 +00:00
|
|
|
-- which are dead to later remove that.
|
|
|
|
--
|
|
|
|
-- When the remote log contains a sameas-uuid pointing to a dead uuid,
|
|
|
|
-- the uuid of that remote configuration is also effectively dead,
|
|
|
|
-- though not in the trust log. There may be per-remote state stored using
|
2019-10-15 15:33:33 +00:00
|
|
|
-- the latter uuid, that also needs to be removed. The sameas-uuid
|
2019-10-14 19:38:07 +00:00
|
|
|
-- is not removed from the remote log, for the same reason the trust log
|
|
|
|
-- is not changed.
|
2021-12-28 17:23:32 +00:00
|
|
|
dropDead :: TrustMap -> M.Map UUID RemoteConfig -> GitConfig -> TransitionCalculator
|
2021-05-13 18:43:25 +00:00
|
|
|
dropDead trustmap remoteconfigmap gc f content
|
|
|
|
| f == trustLog = PreserveFile
|
|
|
|
| f == remoteLog = ChangeFile $
|
|
|
|
Remote.buildRemoteConfigLog $
|
2023-11-13 18:16:55 +00:00
|
|
|
mapLogWithKey minimizesameasdead $
|
2021-05-13 18:43:25 +00:00
|
|
|
filterMapLog (notdead trustmap) id $
|
|
|
|
Remote.parseRemoteConfigLog content
|
|
|
|
| otherwise = filterBranch (notdead trustmap') gc f content
|
2019-10-14 19:38:07 +00:00
|
|
|
where
|
2021-05-13 18:43:25 +00:00
|
|
|
notdead m u = M.findWithDefault def u m /= DeadTrusted
|
2019-10-14 19:38:07 +00:00
|
|
|
trustmap' = trustmap `M.union`
|
|
|
|
M.map (const DeadTrusted) (M.filter sameasdead remoteconfigmap)
|
|
|
|
sameasdead cm =
|
2020-01-10 18:10:20 +00:00
|
|
|
case toUUID . fromProposedAccepted <$> M.lookup sameasUUIDField cm of
|
2019-10-14 19:38:07 +00:00
|
|
|
Nothing -> False
|
|
|
|
Just u' -> M.lookup u' trustmap == Just DeadTrusted
|
2019-10-15 15:33:33 +00:00
|
|
|
minimizesameasdead u l
|
|
|
|
| M.lookup u trustmap' == Just DeadTrusted =
|
|
|
|
l { UUIDBased.value = minimizesameasdead' (UUIDBased.value l) }
|
|
|
|
| otherwise = l
|
|
|
|
minimizesameasdead' c = M.restrictKeys c (S.singleton sameasUUIDField)
|
2013-08-31 21:38:33 +00:00
|
|
|
|
2021-12-28 17:23:32 +00:00
|
|
|
filterBranch :: (UUID -> Bool) -> GitConfig -> TransitionCalculator
|
2021-05-13 18:43:25 +00:00
|
|
|
filterBranch wantuuid gc f content = case getLogVariety gc f of
|
|
|
|
Just OldUUIDBasedLog -> ChangeFile $
|
|
|
|
UUIDBased.buildLogOld byteString $
|
|
|
|
filterMapLog wantuuid id $
|
|
|
|
UUIDBased.parseLogOld A.takeByteString content
|
|
|
|
Just NewUUIDBasedLog -> ChangeFile $
|
|
|
|
UUIDBased.buildLogNew byteString $
|
|
|
|
filterMapLog wantuuid id $
|
|
|
|
UUIDBased.parseLogNew A.takeByteString content
|
|
|
|
Just (ChunkLog _) -> ChangeFile $
|
|
|
|
Chunk.buildLog $ filterMapLog wantuuid fst $
|
|
|
|
Chunk.parseLog content
|
|
|
|
Just (LocationLog _) -> ChangeFile $ Presence.buildLog $
|
|
|
|
Presence.compactLog $
|
|
|
|
filterLocationLog wantuuid $
|
|
|
|
Presence.parseLog content
|
|
|
|
Just (UrlLog _) -> PreserveFile
|
|
|
|
Just RemoteMetaDataLog -> ChangeFile $ MetaData.buildLog $
|
|
|
|
filterRemoteMetaDataLog wantuuid $
|
|
|
|
MetaData.simplifyLog $ MetaData.parseLog content
|
|
|
|
Just OtherLog -> PreserveFile
|
|
|
|
Nothing -> PreserveFile
|
2013-08-31 21:38:33 +00:00
|
|
|
|
2023-11-13 18:16:55 +00:00
|
|
|
filterMapLog :: (UUID -> Bool) -> (k -> UUID) -> MapLog k v -> MapLog k v
|
|
|
|
filterMapLog wantuuid getuuid = filterMapLogWith (\k _v -> wantuuid (getuuid k))
|
2018-09-05 17:20:10 +00:00
|
|
|
|
2021-05-13 18:43:25 +00:00
|
|
|
filterLocationLog :: (UUID -> Bool) -> [Presence.LogLine] -> [Presence.LogLine]
|
|
|
|
filterLocationLog wantuuid = filter $
|
|
|
|
wantuuid . toUUID . Presence.fromLogInfo . Presence.info
|
2013-08-31 21:38:33 +00:00
|
|
|
|
2021-05-13 18:43:25 +00:00
|
|
|
filterRemoteMetaDataLog :: (UUID -> Bool) -> MetaData.Log MetaData -> MetaData.Log MetaData
|
|
|
|
filterRemoteMetaDataLog wantuuid =
|
|
|
|
MetaData.filterOutEmpty . MetaData.filterRemoteMetaData wantuuid
|