follow-on changes from MetaData type changes
Including writing and parsing the metadata log files with bytestring-builder and attoparsec.
This commit is contained in:
parent
16c798b5ef
commit
cb375977a6
14 changed files with 102 additions and 81 deletions
|
@ -78,7 +78,7 @@ getCurrentMetaData' getlogfile k = do
|
|||
let MetaData m = value l
|
||||
ts = lastchangedval l
|
||||
in M.map (const ts) m
|
||||
lastchangedval l = S.singleton $ toMetaValue $ showts $
|
||||
lastchangedval l = S.singleton $ toMetaValue $ encodeBS $ showts $
|
||||
case changed l of
|
||||
VectorClock t -> t
|
||||
Unknown -> 0
|
||||
|
@ -110,9 +110,9 @@ addMetaDataClocked' getlogfile k d@(MetaData m) c
|
|||
| otherwise = do
|
||||
config <- Annex.getGitConfig
|
||||
Annex.Branch.change (getlogfile config k) $
|
||||
encodeBL . showLog . simplifyLog
|
||||
buildLog . simplifyLog
|
||||
. S.insert (LogEntry c metadata)
|
||||
. parseLog . decodeBL
|
||||
. parseLog
|
||||
where
|
||||
metadata = MetaData $ M.filterWithKey (\f _ -> not (isLastChangedField f)) m
|
||||
|
||||
|
@ -145,8 +145,8 @@ copyMetaData oldkey newkey
|
|||
else do
|
||||
config <- Annex.getGitConfig
|
||||
Annex.Branch.change (metaDataLogFile config newkey) $
|
||||
const $ encodeBL $ showLog l
|
||||
const $ buildLog l
|
||||
return True
|
||||
|
||||
readLog :: FilePath -> Annex (Log MetaData)
|
||||
readLog = parseLog . decodeBL <$$> Annex.Branch.get
|
||||
readLog = parseLog <$$> Annex.Branch.get
|
||||
|
|
|
@ -11,7 +11,7 @@ module Logs.MetaData.Pure (
|
|||
Log,
|
||||
LogEntry(..),
|
||||
parseLog,
|
||||
showLog,
|
||||
buildLog,
|
||||
logToCurrentMetaData,
|
||||
simplifyLog,
|
||||
filterRemoteMetaData,
|
||||
|
|
|
@ -20,8 +20,8 @@ import Logs
|
|||
import Logs.SingleValue
|
||||
|
||||
instance SingleValueSerializable NumCopies where
|
||||
serialize (NumCopies n) = show n
|
||||
deserialize = NumCopies <$$> readish
|
||||
serialize (NumCopies n) = encodeBS (show n)
|
||||
deserialize = NumCopies <$$> readish . decodeBS
|
||||
|
||||
setGlobalNumCopies :: NumCopies -> Annex ()
|
||||
setGlobalNumCopies new = do
|
||||
|
|
|
@ -26,7 +26,7 @@ import Annex.VectorClock
|
|||
import qualified Data.Set as S
|
||||
|
||||
readLog :: (Ord v, SingleValueSerializable v) => FilePath -> Annex (Log v)
|
||||
readLog = parseLog . decodeBL <$$> Annex.Branch.get
|
||||
readLog = parseLog <$$> Annex.Branch.get
|
||||
|
||||
getLog :: (Ord v, SingleValueSerializable v) => FilePath -> Annex (Maybe v)
|
||||
getLog = newestValue <$$> readLog
|
||||
|
@ -35,4 +35,4 @@ setLog :: (SingleValueSerializable v) => FilePath -> v -> Annex ()
|
|||
setLog f v = do
|
||||
c <- liftIO currentVectorClock
|
||||
let ent = LogEntry c v
|
||||
Annex.Branch.change f $ \_old -> encodeBL (showLog (S.singleton ent))
|
||||
Annex.Branch.change f $ \_old -> buildLog (S.singleton ent)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{- git-annex single-value log, pure operations
|
||||
-
|
||||
- Copyright 2014 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2014-2019 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
@ -12,10 +12,15 @@ import Logs.Line
|
|||
import Annex.VectorClock
|
||||
|
||||
import qualified Data.Set as S
|
||||
import qualified Data.ByteString as B
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
import qualified Data.Attoparsec.ByteString.Lazy as A
|
||||
import Data.Attoparsec.ByteString.Char8 (char)
|
||||
import Data.ByteString.Builder
|
||||
|
||||
class SingleValueSerializable v where
|
||||
serialize :: v -> String
|
||||
deserialize :: String -> Maybe v
|
||||
serialize :: v -> B.ByteString
|
||||
deserialize :: B.ByteString -> Maybe v
|
||||
|
||||
data LogEntry v = LogEntry
|
||||
{ changed :: VectorClock
|
||||
|
@ -24,20 +29,27 @@ data LogEntry v = LogEntry
|
|||
|
||||
type Log v = S.Set (LogEntry v)
|
||||
|
||||
showLog :: (SingleValueSerializable v) => Log v -> String
|
||||
showLog = unlines . map showline . S.toList
|
||||
buildLog :: (SingleValueSerializable v) => Log v -> Builder
|
||||
buildLog = mconcat . map genline . S.toList
|
||||
where
|
||||
showline (LogEntry c v) = unwords [formatVectorClock c, serialize v]
|
||||
genline (LogEntry c v) =
|
||||
byteString (encodeBS' (formatVectorClock c)) <> sp
|
||||
<> byteString (serialize v)
|
||||
<> nl
|
||||
sp = charUtf8 ' '
|
||||
nl = charUtf8 '\n'
|
||||
|
||||
parseLog :: (Ord v, SingleValueSerializable v) => String -> Log v
|
||||
parseLog = S.fromList . mapMaybe parse . splitLines
|
||||
parseLog :: (Ord v, SingleValueSerializable v) => L.ByteString -> Log v
|
||||
parseLog = S.fromList . fromMaybe []
|
||||
. A.maybeResult . A.parse (logParser <* A.endOfInput)
|
||||
|
||||
logParser :: SingleValueSerializable v => A.Parser [LogEntry v]
|
||||
logParser = parseLogLines $ LogEntry
|
||||
<$> vectorClockParser
|
||||
<* char ' '
|
||||
<*> (parsevalue =<< A.takeByteString)
|
||||
where
|
||||
parse line = do
|
||||
let (sc, s) = splitword line
|
||||
c <- parseVectorClock sc
|
||||
v <- deserialize s
|
||||
Just (LogEntry c v)
|
||||
splitword = separate (== ' ')
|
||||
parsevalue = maybe (fail "log line parse failure") return . deserialize
|
||||
|
||||
newestValue :: Log v -> Maybe v
|
||||
newestValue s
|
||||
|
|
|
@ -28,6 +28,7 @@ import qualified Git.Ref
|
|||
import Git.Types
|
||||
import Logs.File
|
||||
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Set as S
|
||||
import Data.Char
|
||||
|
||||
|
@ -74,15 +75,15 @@ branchView view
|
|||
branchcomp c
|
||||
| viewVisible c = branchcomp' c
|
||||
| otherwise = "(" ++ branchcomp' c ++ ")"
|
||||
branchcomp' (ViewComponent metafield viewfilter _) =concat
|
||||
[ forcelegal (fromMetaField metafield)
|
||||
branchcomp' (ViewComponent metafield viewfilter _) = concat
|
||||
[ forcelegal (T.unpack (fromMetaField metafield))
|
||||
, branchvals viewfilter
|
||||
]
|
||||
branchvals (FilterValues set) = '=' : branchset set
|
||||
branchvals (FilterGlob glob) = '=' : forcelegal glob
|
||||
branchvals (ExcludeValues set) = "!=" ++ branchset set
|
||||
branchset = intercalate ","
|
||||
. map (forcelegal . fromMetaValue)
|
||||
. map (forcelegal . decodeBS . fromMetaValue)
|
||||
. S.toList
|
||||
forcelegal s
|
||||
| Git.Ref.legal True s = s
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue