2011-07-01 19:24:07 +00:00
|
|
|
{- git-annex presence log
|
|
|
|
-
|
|
|
|
- This is used to store presence information in the git-annex branch in
|
|
|
|
- a way that can be union merged.
|
|
|
|
-
|
|
|
|
- A line of the log will look like: "date N INFO"
|
2015-10-12 18:46:28 +00:00
|
|
|
- Where N=1 when the INFO is present, 0 otherwise.
|
2011-07-01 19:24:07 +00:00
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010-2014 Joey Hess <id@joeyh.name>
|
2011-07-01 19:24:07 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2011-07-01 19:24:07 +00:00
|
|
|
-}
|
|
|
|
|
2011-10-15 20:21:08 +00:00
|
|
|
module Logs.Presence (
|
2013-08-31 21:38:33 +00:00
|
|
|
module X,
|
2011-07-01 21:15:46 +00:00
|
|
|
addLog,
|
2015-10-12 18:46:28 +00:00
|
|
|
maybeAddLog,
|
2011-07-01 19:24:07 +00:00
|
|
|
readLog,
|
|
|
|
logNow,
|
2014-02-06 16:43:56 +00:00
|
|
|
currentLog,
|
2015-04-01 21:53:16 +00:00
|
|
|
currentLogInfo,
|
|
|
|
historicalLogInfo,
|
2011-07-01 19:24:07 +00:00
|
|
|
) where
|
|
|
|
|
2013-08-31 21:38:33 +00:00
|
|
|
import Logs.Presence.Pure as X
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2017-08-14 17:55:38 +00:00
|
|
|
import Annex.VectorClock
|
2011-10-04 04:40:47 +00:00
|
|
|
import qualified Annex.Branch
|
2014-02-06 16:43:56 +00:00
|
|
|
import Git.Types (RefDate)
|
2011-07-01 19:24:07 +00:00
|
|
|
|
2015-10-12 18:46:28 +00:00
|
|
|
{- Adds a LogLine to the log, removing any LogLines that are obsoleted by
|
|
|
|
- adding it. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
addLog :: RawFilePath -> LogLine -> Annex ()
|
2019-01-03 17:21:48 +00:00
|
|
|
addLog file line = Annex.Branch.change file $ \b ->
|
|
|
|
buildLog $ compactLog (line : parseLog b)
|
2011-07-01 21:15:46 +00:00
|
|
|
|
2015-10-12 18:46:28 +00:00
|
|
|
{- When a LogLine already exists with the same status and info, but an
|
|
|
|
- older timestamp, that LogLine is preserved, rather than updating the log
|
|
|
|
- with a newer timestamp.
|
|
|
|
-}
|
2019-11-26 19:27:22 +00:00
|
|
|
maybeAddLog :: RawFilePath -> LogLine -> Annex ()
|
2015-10-12 18:46:28 +00:00
|
|
|
maybeAddLog file line = Annex.Branch.maybeChange file $ \s -> do
|
|
|
|
m <- insertNewStatus line $ logMap $ parseLog s
|
2019-01-03 17:21:48 +00:00
|
|
|
return $ buildLog $ mapLog m
|
2015-10-12 18:46:28 +00:00
|
|
|
|
2011-07-01 19:24:07 +00:00
|
|
|
{- Reads a log file.
|
|
|
|
- Note that the LogLines returned may be in any order. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
readLog :: RawFilePath -> Annex [LogLine]
|
2012-06-29 14:00:05 +00:00
|
|
|
readLog = parseLog <$$> Annex.Branch.get
|
2011-07-01 19:24:07 +00:00
|
|
|
|
2017-08-14 17:55:38 +00:00
|
|
|
{- Generates a new LogLine with the current time. -}
|
2019-01-03 17:21:48 +00:00
|
|
|
logNow :: LogStatus -> LogInfo -> Annex LogLine
|
2011-07-01 19:24:07 +00:00
|
|
|
logNow s i = do
|
2020-12-23 19:21:33 +00:00
|
|
|
c <- currentVectorClock
|
2017-08-14 17:55:38 +00:00
|
|
|
return $ LogLine c s i
|
2011-07-01 19:24:07 +00:00
|
|
|
|
|
|
|
{- Reads a log and returns only the info that is still in effect. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
currentLogInfo :: RawFilePath -> Annex [LogInfo]
|
2015-04-01 21:53:16 +00:00
|
|
|
currentLogInfo file = map info <$> currentLog file
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
currentLog :: RawFilePath -> Annex [LogLine]
|
2015-04-01 21:53:16 +00:00
|
|
|
currentLog file = filterPresent <$> readLog file
|
2014-02-06 16:43:56 +00:00
|
|
|
|
|
|
|
{- Reads a historical version of a log and returns the info that was in
|
|
|
|
- effect at that time.
|
|
|
|
-
|
|
|
|
- The date is formatted as shown in gitrevisions man page.
|
|
|
|
-}
|
2019-11-26 19:27:22 +00:00
|
|
|
historicalLogInfo :: RefDate -> RawFilePath -> Annex [LogInfo]
|
2015-04-01 21:53:16 +00:00
|
|
|
historicalLogInfo refdate file = map info . filterPresent . parseLog
|
2014-02-06 16:43:56 +00:00
|
|
|
<$> Annex.Branch.getHistorical refdate file
|