1{- git-annex difference log
2 -
3 - Copyright 2015 Joey Hess <id@joeyh.name>
4 -
5 - Licensed under the GNU AGPL version 3 or higher.
6 -}
7
8module Logs.Difference (
9	recordDifferences,
10	recordedDifferences,
11	recordedDifferencesFor,
12	module Logs.Difference.Pure
13) where
14
15import qualified Data.Map as M
16import qualified Data.Attoparsec.ByteString as A
17import Data.ByteString.Builder
18
19import Annex.Common
20import Types.Difference
21import qualified Annex.Branch
22import Logs
23import Logs.UUIDBased
24import Logs.Difference.Pure
25
26recordDifferences :: Differences -> UUID -> Annex ()
27recordDifferences ds@(Differences {}) uuid = do
28	c <- currentVectorClock
29	Annex.Branch.change (Annex.Branch.RegardingUUID [uuid]) differenceLog $
30		buildLogOld byteString
31			. changeLog c uuid (encodeBS $ showDifferences ds)
32			. parseLogOld A.takeByteString
33recordDifferences UnknownDifferences _ = return ()
34
35-- Map of UUIDs that have Differences recorded.
36-- If a new version of git-annex has added a Difference this version
37-- doesn't know about, it will contain UnknownDifferences.
38recordedDifferences :: Annex (M.Map UUID Differences)
39recordedDifferences = parseDifferencesLog <$> Annex.Branch.get differenceLog
40
41recordedDifferencesFor :: UUID -> Annex Differences
42recordedDifferencesFor u = fromMaybe mempty . M.lookup u <$> recordedDifferences
43