2013-08-28 17:19:02 +00:00
|
|
|
{- git-annex transitions log
|
|
|
|
-
|
|
|
|
- This is used to record transitions that have been performed on the
|
|
|
|
- git-annex branch, and when the transition was first started.
|
|
|
|
-
|
|
|
|
- We can quickly detect when the local branch has already had an transition
|
|
|
|
- done that is listed in the remote branch by checking that the local
|
|
|
|
- branch contains the same transition, with the same or newer start time.
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2013 Joey Hess <id@joeyh.name>
|
2013-08-28 17:19:02 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Logs.Transitions where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2017-08-14 17:55:38 +00:00
|
|
|
import Annex.VectorClock
|
2016-05-27 15:45:13 +00:00
|
|
|
import Logs.Line
|
2013-08-28 17:19:02 +00:00
|
|
|
|
2017-08-14 17:55:38 +00:00
|
|
|
import qualified Data.Set as S
|
|
|
|
|
2013-08-28 17:19:02 +00:00
|
|
|
transitionsLog :: FilePath
|
|
|
|
transitionsLog = "transitions.log"
|
|
|
|
|
|
|
|
data Transition
|
|
|
|
= ForgetGitHistory
|
|
|
|
| ForgetDeadRemotes
|
|
|
|
deriving (Show, Ord, Eq, Read)
|
|
|
|
|
|
|
|
data TransitionLine = TransitionLine
|
2017-08-14 17:55:38 +00:00
|
|
|
{ transitionStarted :: VectorClock
|
2013-08-28 17:19:02 +00:00
|
|
|
, transition :: Transition
|
2017-08-14 18:43:56 +00:00
|
|
|
} deriving (Ord, Eq)
|
2013-08-28 17:19:02 +00:00
|
|
|
|
|
|
|
type Transitions = S.Set TransitionLine
|
|
|
|
|
2013-08-28 19:57:42 +00:00
|
|
|
describeTransition :: Transition -> String
|
|
|
|
describeTransition ForgetGitHistory = "forget git history"
|
|
|
|
describeTransition ForgetDeadRemotes = "forget dead remotes"
|
|
|
|
|
2013-08-28 20:38:03 +00:00
|
|
|
noTransitions :: Transitions
|
|
|
|
noTransitions = S.empty
|
|
|
|
|
2017-08-14 17:55:38 +00:00
|
|
|
addTransition :: VectorClock -> Transition -> Transitions -> Transitions
|
|
|
|
addTransition c t = S.insert $ TransitionLine c t
|
2013-08-28 17:19:02 +00:00
|
|
|
|
|
|
|
showTransitions :: Transitions -> String
|
|
|
|
showTransitions = unlines . map showTransitionLine . S.elems
|
|
|
|
|
|
|
|
{- If the log contains new transitions we don't support, returns Nothing. -}
|
|
|
|
parseTransitions :: String -> Maybe Transitions
|
2016-05-27 15:45:13 +00:00
|
|
|
parseTransitions = check . map parseTransitionLine . splitLines
|
2013-08-28 17:19:02 +00:00
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
check l
|
2013-08-28 17:19:02 +00:00
|
|
|
| all isJust l = Just $ S.fromList $ catMaybes l
|
|
|
|
| otherwise = Nothing
|
|
|
|
|
2013-08-28 19:57:42 +00:00
|
|
|
parseTransitionsStrictly :: String -> String -> Transitions
|
|
|
|
parseTransitionsStrictly source = fromMaybe badsource . parseTransitions
|
|
|
|
where
|
2016-11-16 01:29:54 +00:00
|
|
|
badsource = giveup $ "unknown transitions listed in " ++ source ++ "; upgrade git-annex!"
|
2013-08-28 19:57:42 +00:00
|
|
|
|
2013-08-28 17:19:02 +00:00
|
|
|
showTransitionLine :: TransitionLine -> String
|
2017-08-14 18:43:56 +00:00
|
|
|
showTransitionLine (TransitionLine c t) = unwords [show t, formatVectorClock c]
|
2013-08-28 17:19:02 +00:00
|
|
|
|
|
|
|
parseTransitionLine :: String -> Maybe TransitionLine
|
2015-05-10 18:45:55 +00:00
|
|
|
parseTransitionLine s = TransitionLine
|
2017-08-14 18:43:56 +00:00
|
|
|
<$> parseVectorClock cs
|
2015-05-10 18:45:55 +00:00
|
|
|
<*> readish ts
|
2013-08-28 17:19:02 +00:00
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
ws = words s
|
|
|
|
ts = Prelude.head ws
|
2017-08-14 18:43:56 +00:00
|
|
|
cs = unwords $ Prelude.tail ws
|
2013-08-28 17:19:02 +00:00
|
|
|
|
2013-08-28 19:57:42 +00:00
|
|
|
combineTransitions :: [Transitions] -> Transitions
|
|
|
|
combineTransitions = S.unions
|
|
|
|
|
|
|
|
transitionList :: Transitions -> [Transition]
|
2016-05-18 16:26:38 +00:00
|
|
|
transitionList = nub . map transition . S.elems
|
2013-08-28 17:19:02 +00:00
|
|
|
|
|
|
|
{- Typically ran with Annex.Branch.change, but we can't import Annex.Branch
|
|
|
|
- here since it depends on this module. -}
|
2013-08-28 20:38:03 +00:00
|
|
|
recordTransitions :: (FilePath -> (String -> String) -> Annex ()) -> Transitions -> Annex ()
|
2013-09-26 03:19:01 +00:00
|
|
|
recordTransitions changer t = changer transitionsLog $
|
|
|
|
showTransitions . S.union t . parseTransitionsStrictly "local"
|