newtype MapLog

Noticed that Semigroup instance of Map is not suitable to use
for MapLog. For example, it behaved like this:

ghci>  parseTrustLog "foo 1 timestamp=10\nfoo 2 timestamp=11" <> parseTrustLog "foo X timestamp=12"
fromList [(UUID "foo",LogEntry {changed = VectorClock 11s, value = SemiTrusted})]

Which was wrong, it lost the newer DeadTrusted value.

Luckily, nothing used that Semigroup when operating on a MapLog. And this
provides a safe instance.

Sponsored-by: Graham Spencer on Patreon
This commit is contained in:
Joey Hess 2023-11-13 14:16:55 -04:00
parent 5d8b8a8ad0
commit 38b9ebc5fd
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
8 changed files with 74 additions and 44 deletions

View file

@ -14,6 +14,7 @@ import Annex.Common
import Types.RemoteState
import Logs
import Logs.UUIDBased
import Logs.MapLog
import qualified Annex.Branch
import qualified Annex
@ -39,7 +40,7 @@ buildRemoteState = buildLogNew (byteString . encodeBS)
getRemoteState :: RemoteStateHandle -> Key -> Annex (Maybe RemoteState)
getRemoteState (RemoteStateHandle u) k = do
config <- Annex.getGitConfig
extract . parseRemoteState
extract . fromMapLog . parseRemoteState
<$> Annex.Branch.get (remoteStateLogFile config k)
where
extract m = value <$> M.lookup u m