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.
This commit is contained in:
Joey Hess 2019-01-10 14:39:36 -04:00
parent 66603d6f75
commit 591e4b145f
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
18 changed files with 163 additions and 109 deletions

View file

@ -20,6 +20,7 @@ module Logs.Schedule (
import qualified Data.Map as M
import qualified Data.Set as S
import Data.Time.LocalTime
import qualified Data.Attoparsec.ByteString.Lazy as A
import Data.ByteString.Builder
import Annex.Common
@ -33,19 +34,18 @@ scheduleSet :: UUID -> [ScheduledActivity] -> Annex ()
scheduleSet uuid@(UUID _) activities = do
c <- liftIO currentVectorClock
Annex.Branch.change scheduleLog $
buildLog (byteString . encodeBS)
. changeLog c uuid val
. parseLog Just . decodeBL
buildLog byteString
. changeLog c uuid (encodeBS val)
. parseLog A.takeByteString
where
val = fromScheduledActivities activities
scheduleSet NoUUID _ = error "unknown UUID; cannot modify"
scheduleMap :: Annex (M.Map UUID [ScheduledActivity])
scheduleMap = simpleMap
. parseLog parser . decodeBL
<$> Annex.Branch.get scheduleLog
scheduleMap = simpleMap . parseLog parser <$> Annex.Branch.get scheduleLog
where
parser = eitherToMaybe . parseScheduledActivities
parser = either fail pure . parseScheduledActivities . decodeBS
=<< A.takeByteString
scheduleGet :: UUID -> Annex (S.Set ScheduledActivity)
scheduleGet u = do