module EVM.Facts.Git
( saveFacts
, loadFacts
, RepoAt (..)
) where
import EVM.Facts (Fact (..), File (..), Path (..), Data (..), fileToFact, factToFile)
import Control.Lens
import Data.Set (Set)
import Data.Maybe (catMaybes)
import qualified Data.Set as Set
import qualified Restless.Git as Git
newtype RepoAt = RepoAt String
deriving (Eq, Ord, Show)
fileRepr :: Iso' File Git.File
fileRepr = iso f g
where
f :: File -> Git.File
f (File (Path ps p) (Data x)) =
Git.File (Git.Path ps p) x
g :: Git.File -> File
g (Git.File (Git.Path ps p) x) =
File (Path ps p) (Data x)
saveFacts :: RepoAt -> Set Fact -> IO ()
saveFacts (RepoAt repo) facts =
Git.save repo "hevm execution"
(Set.map (view fileRepr . factToFile) facts)
prune :: Ord a => Set (Maybe a) -> Set a
prune = Set.fromList . catMaybes . Set.toList
loadFacts :: RepoAt -> IO (Set Fact)
loadFacts (RepoAt src) =
fmap
(prune . Set.map (fileToFact . view (from fileRepr)))
(Git.load src)