git-annex sim log
authorJoey Hess <joeyh@joeyh.name>
Tue, 17 Sep 2024 17:43:11 +0000 (13:43 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 17 Sep 2024 17:43:11 +0000 (13:43 -0400)
Annex/Sim.hs
Command/Sim.hs
doc/git-annex-sim.mdwn

index b0536387ff70a6d9a2c2909a1d05315a55737a4f..ecbdfbafa0c9c803158465e4af229b4f9aa6ab1a 100644 (file)
@@ -67,7 +67,7 @@ data SimState t = SimState
        , simRebalance :: Bool
        , simHistory :: [SimCommand]
        , simVectorClock :: VectorClock
-       , simFile :: Maybe FilePath
+       , simLogFile :: Maybe FilePath
        , simRootDirectory :: FilePath
        }
        deriving (Show, Read)
@@ -90,7 +90,7 @@ emptySimState rngseed rootdir = SimState
        , simRebalance = False
        , simHistory = []
        , simVectorClock = VectorClock 0
-       , simFile = Nothing
+       , simLogFile = Nothing
        , simRootDirectory = rootdir
        }
 
index a3e096ceff76e3bbebb6d47451d56b19768f06d8..a4eef730d9a6cf3ddb8806fa5297edde9b0efb68 100644 (file)
@@ -30,6 +30,7 @@ seek ("end":[]) = do
        simdir <- fromRawFilePath <$> fromRepo gitAnnexSimDir
        whenM (liftIO $ doesDirectoryExist simdir) $ do
                liftIO $ removeDirectoryRecursive simdir
+       showLongNote $ UnquotedString "Sim ended."
 seek ("visit":reponame:[]) = do
        simdir <- fromRepo gitAnnexSimDir
        liftIO (restoreSim simdir) >>= \case
@@ -51,6 +52,13 @@ seek ("visit":reponame:[]) = do
                                , "Choose from:" 
                                , unwords $ map fromRepoName $ M.keys (simRepos st)
                                ]
+seek ("show":[]) = do
+       simdir <- fromRepo gitAnnexSimDir
+       liftIO (restoreSim simdir) >>= \case
+               Left err -> giveup err
+               Right st -> case simLogFile st of
+                       Just f -> liftIO $ putStr =<< readFile f
+                       Nothing -> return ()
 seek ps = case parseSimCommand ps of
        Left err -> giveup err
        Right simcmd -> do
@@ -74,15 +82,14 @@ start simfile = do
        
        rng <- fst . random <$> initStdGen
        let st = (emptySimState rng simdir)
-               { simFile = Just simlogfile }
+               { simLogFile = Just simlogfile }
        case simfile of
                Nothing -> startup simdir st []
                Just f -> liftIO (readFile f) >>= \c -> 
                        case parseSimFile c of
                                Left err -> giveup err
                                Right cs -> startup simdir st cs
-       showLongNote $ UnquotedString "Sim started, logging to sim file " 
-               <> QuotedPath (toRawFilePath simlogfile)
+       showLongNote $ UnquotedString "Sim started."
   where
        startup simdir st cs = do
                repobyname <- mkGetExistingRepoByName
@@ -98,6 +105,6 @@ start simfile = do
 saveState :: SimState SimRepo -> IO ()
 saveState st = do
        suspendSim st
-       case simFile st of
+       case simLogFile st of
                Just f -> writeFile f $ generateSimFile $ reverse $ simHistory st
                Nothing -> noop
index 9b86a041fefafe53f607957cdc9ebb81d710685a..55d8e3ea6e7f2894128ca76362af35b1e78b6491 100644 (file)
@@ -10,6 +10,8 @@ git annex sim command
 
 git annex sim visit repo
 
+git annex sim show
+
 git annex sim end
 
 # DESCRIPTION
@@ -24,17 +26,18 @@ run after starting it. These are in the form "git annex sim command"
 with the command in the same format used in the sim file (see sim commands
 list below). For example, "git annex sim step 1" runs the simulation one step.
 
-The simulation writes to an output sim file as it runs, which contains the
+The simulation keeps a log as it runs, which contains the
 entire simulation input, as well as the actions performed in the
-simulation, and the results of the simulation.
-This allows re-running the same simulation later, as well as analyzing
-the results of the simulation.
+simulation, and the results of the simulation. Use "git-annex sim show"
+to display the log. This allows re-running the same simulation later,
+as well as analyzing the results of the simulation.
 
-While a simulation is running, the command "git annex visit repo", where
+While a simulation is running, the command "git annex sim visit repo", where
 "repo" is the name of one of the repositories in the simulation, will spawn
 a subshell in a git repository whose git-annex branch contains the state of
 that simulated repository. This allows running any git-annex command, such
 as `git-annex whereis` to examine the state of the simulation.
+You should avoid making any changes to git-annex state.
 Exit the subshell to end the visit.
 
 Use "git annex sim end" to finish the simulation, and clean up.