2013-08-31 21:38:33 +00:00
|
|
|
{- git-annex branch transitions
|
|
|
|
-
|
2019-01-03 17:21:48 +00:00
|
|
|
- Copyright 2013-2019 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 (
|
|
|
|
FileTransition(..),
|
|
|
|
getTransitionCalculator
|
|
|
|
) 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
|
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
|
2013-08-31 21:38:33 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
2018-09-12 18:10:08 +00:00
|
|
|
import qualified Data.Set as S
|
2019-01-03 17:21:48 +00:00
|
|
|
import qualified Data.ByteString.Lazy as L
|
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
|
|
|
|
|
|
|
data FileTransition
|
2019-01-09 18:10:05 +00:00
|
|
|
= ChangeFile Builder
|
2013-08-31 21:38:33 +00:00
|
|
|
| RemoveFile
|
|
|
|
| PreserveFile
|
|
|
|
|
2019-01-03 17:21:48 +00:00
|
|
|
type TransitionCalculator = FilePath -> L.ByteString -> TrustMap -> FileTransition
|
2013-08-31 21:38:33 +00:00
|
|
|
|
|
|
|
getTransitionCalculator :: Transition -> Maybe TransitionCalculator
|
|
|
|
getTransitionCalculator ForgetGitHistory = Nothing
|
|
|
|
getTransitionCalculator ForgetDeadRemotes = Just dropDead
|
|
|
|
|
2019-01-03 17:21:48 +00:00
|
|
|
dropDead :: FilePath -> L.ByteString -> TrustMap -> FileTransition
|
2013-08-31 21:38:33 +00:00
|
|
|
dropDead f content trustmap = case getLogVariety f of
|
2019-02-21 17:43:21 +00:00
|
|
|
Just OldUUIDBasedLog
|
2014-03-26 17:28:26 +00:00
|
|
|
-- Don't remove the dead repo from the trust log,
|
|
|
|
-- because git remotes may still exist, and they need
|
|
|
|
-- to still know it's dead.
|
|
|
|
| f == trustLog -> PreserveFile
|
2019-01-09 18:10:05 +00:00
|
|
|
| otherwise -> ChangeFile $
|
2019-02-21 17:43:21 +00:00
|
|
|
UUIDBased.buildLogOld byteString $
|
convert old uuid-based log parsers to attoparsec
This preserves the workaround for the old bug that caused NoUUID items
to be stored in the log, prefixing log lines with " ". It's now handled
implicitly, by using takeWhile1 (/= ' ') to get the uuid.
There is a behavior change from the old parser, which split the value
into words and then recombined it. That meant that "foo bar" and "foo\tbar"
came out as "foo bar". That behavior was not documented, and seems
surprising; it meant that after a git-annex describe here "foo bar",
you wouldn't get that same string back out when git-annex displayed repo
descriptions.
Otoh, some other parsers relied on the old behavior, and the attoparsec
rewrites had to deal with the issue themselves...
For group.log, there are some edge cases around the user providing a
group name with a leading or trailing space. The old parser would ignore
such excess whitespace. The new parser does too, because the alternative
is to refuse to parse something like " group1 group2 " due to excess
whitespace, which would be even more confusing behavior.
The only git-annex branch log file that is not converted to attoparsec
and bytestring-builder now is transitions.log.
2019-01-10 18:39:36 +00:00
|
|
|
dropDeadFromMapLog trustmap id $
|
2019-02-21 17:43:21 +00:00
|
|
|
UUIDBased.parseLogOld A.takeByteString content
|
2019-01-09 18:10:05 +00:00
|
|
|
Just NewUUIDBasedLog -> ChangeFile $
|
2019-01-10 17:23:42 +00:00
|
|
|
UUIDBased.buildLogNew byteString $
|
2019-01-09 17:06:37 +00:00
|
|
|
dropDeadFromMapLog trustmap id $
|
2019-01-10 17:23:42 +00:00
|
|
|
UUIDBased.parseLogNew A.takeByteString content
|
2019-01-09 18:10:05 +00:00
|
|
|
Just (ChunkLog _) -> ChangeFile $
|
2019-01-10 17:23:42 +00:00
|
|
|
Chunk.buildLog $ dropDeadFromMapLog trustmap fst $ Chunk.parseLog content
|
2013-08-31 21:38:33 +00:00
|
|
|
Just (PresenceLog _) ->
|
convert old uuid-based log parsers to attoparsec
This preserves the workaround for the old bug that caused NoUUID items
to be stored in the log, prefixing log lines with " ". It's now handled
implicitly, by using takeWhile1 (/= ' ') to get the uuid.
There is a behavior change from the old parser, which split the value
into words and then recombined it. That meant that "foo bar" and "foo\tbar"
came out as "foo bar". That behavior was not documented, and seems
surprising; it meant that after a git-annex describe here "foo bar",
you wouldn't get that same string back out when git-annex displayed repo
descriptions.
Otoh, some other parsers relied on the old behavior, and the attoparsec
rewrites had to deal with the issue themselves...
For group.log, there are some edge cases around the user providing a
group name with a leading or trailing space. The old parser would ignore
such excess whitespace. The new parser does too, because the alternative
is to refuse to parse something like " group1 group2 " due to excess
whitespace, which would be even more confusing behavior.
The only git-annex branch log file that is not converted to attoparsec
and bytestring-builder now is transitions.log.
2019-01-10 18:39:36 +00:00
|
|
|
let newlog = Presence.compactLog $
|
|
|
|
dropDeadFromPresenceLog trustmap $ Presence.parseLog content
|
2013-08-31 21:38:33 +00:00
|
|
|
in if null newlog
|
|
|
|
then RemoveFile
|
2019-01-09 18:10:05 +00:00
|
|
|
else ChangeFile $ Presence.buildLog newlog
|
2018-09-05 17:20:10 +00:00
|
|
|
Just RemoteMetaDataLog ->
|
2019-01-07 19:51:05 +00:00
|
|
|
let newlog = dropDeadFromRemoteMetaDataLog trustmap $ MetaData.simplifyLog $ MetaData.parseLog content
|
2018-09-12 18:10:08 +00:00
|
|
|
in if S.null newlog
|
2018-09-05 17:20:10 +00:00
|
|
|
then RemoveFile
|
2019-01-09 18:10:05 +00:00
|
|
|
else ChangeFile $ MetaData.buildLog newlog
|
2014-02-13 01:12:22 +00:00
|
|
|
Just OtherLog -> PreserveFile
|
2013-08-31 21:38:33 +00:00
|
|
|
Nothing -> PreserveFile
|
|
|
|
|
2016-01-27 13:44:38 +00:00
|
|
|
dropDeadFromMapLog :: TrustMap -> (k -> UUID) -> M.Map k v -> M.Map k v
|
2018-09-05 17:20:10 +00:00
|
|
|
dropDeadFromMapLog trustmap getuuid =
|
|
|
|
M.filterWithKey $ \k _v -> notDead trustmap getuuid k
|
2013-08-31 21:38:33 +00:00
|
|
|
|
|
|
|
{- Presence logs can contain UUIDs or other values. Any line that matches
|
|
|
|
- a dead uuid is dropped; any other values are passed through. -}
|
|
|
|
dropDeadFromPresenceLog :: TrustMap -> [Presence.LogLine] -> [Presence.LogLine]
|
2018-09-05 17:20:10 +00:00
|
|
|
dropDeadFromPresenceLog trustmap =
|
2019-01-03 17:21:48 +00:00
|
|
|
filter $ notDead trustmap (toUUID . Presence.fromLogInfo . Presence.info)
|
2018-09-05 17:20:10 +00:00
|
|
|
|
|
|
|
dropDeadFromRemoteMetaDataLog :: TrustMap -> MetaData.Log MetaData -> MetaData.Log MetaData
|
|
|
|
dropDeadFromRemoteMetaDataLog trustmap =
|
|
|
|
MetaData.filterOutEmpty . MetaData.filterRemoteMetaData (notDead trustmap id)
|
2013-08-31 21:38:33 +00:00
|
|
|
|
|
|
|
notDead :: TrustMap -> (v -> UUID) -> v -> Bool
|
2014-10-14 18:10:22 +00:00
|
|
|
notDead trustmap a v = M.findWithDefault def (a v) trustmap /= DeadTrusted
|