From f5f7b4a936e8dd95d14db5f1a63d9412f5ba86a7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 20 Sep 2024 15:45:05 -0400 Subject: [PATCH] avoid adding redundant present/notpresent to sim history --- Annex/Sim.hs | 65 +++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/Annex/Sim.hs b/Annex/Sim.hs index 7c7252ec31..344dc97e1e 100644 --- a/Annex/Sim.hs +++ b/Annex/Sim.hs @@ -248,12 +248,41 @@ applySimCommand -> SimState SimRepo -> GetExistingRepoByName -> Either String (Either (Annex (SimState SimRepo)) (SimState SimRepo)) -applySimCommand cmd st = - applySimCommand' cmd $ flip addHistory cmd $ st +applySimCommand (CommandPresent repo file) st _ = checkKnownRepo repo st $ \u -> + case (M.lookup file (simFiles st), M.lookup u (simRepoState st)) of + (Just k, Just rst) + | u `S.member` getSimLocations rst k -> + Right $ Right st + | otherwise -> missing + (Just _, Nothing) -> missing + (Nothing, _) -> Left $ "Expected " ++ fromRawFilePath file + ++ " to be present in " ++ fromRepoName repo + ++ ", but the simulation does not include that file." + where + missing = Left $ "Expected " ++ fromRawFilePath file + ++ " to be present in " + ++ fromRepoName repo ++ ", but it is not." +applySimCommand (CommandNotPresent repo file) st _ = checkKnownRepo repo st $ \u -> + case (M.lookup file (simFiles st), M.lookup u (simRepoState st)) of + (Just k, Just rst) + | u `S.notMember` getSimLocations rst k -> + Right $ Right st + | otherwise -> present + (Just _, Nothing) -> present + (Nothing, _) -> Left $ "Expected " ++ fromRawFilePath file + ++ " to not be present in " ++ fromRepoName repo + ++ ", but the simulation does not include that file." + where + present = Left $ "Expected " ++ fromRawFilePath file + ++ " not to be present in " + ++ fromRepoName repo ++ ", but it is present." +applySimCommand cmd st repobyname = + let st' = flip addHistory cmd $ st { simVectorClock = let (VectorClock clk) = simVectorClock st in VectorClock (succ clk) } + in applySimCommand' cmd st' repobyname applySimCommand' :: SimCommand @@ -373,34 +402,6 @@ applySimCommand' (CommandSeed rngseed) st _ = Right $ Right $ st { simRng = rngseed } -applySimCommand' (CommandPresent repo file) st _ = checkKnownRepo repo st $ \u -> - case (M.lookup file (simFiles st), M.lookup u (simRepoState st)) of - (Just k, Just rst) - | u `S.member` getSimLocations rst k -> - Right $ Right st - | otherwise -> missing - (Just _, Nothing) -> missing - (Nothing, _) -> Left $ "Expected " ++ fromRawFilePath file - ++ " to be present in " ++ fromRepoName repo - ++ ", but the simulation does not include that file." - where - missing = Left $ "Expected " ++ fromRawFilePath file - ++ " to be present in " - ++ fromRepoName repo ++ ", but it is not." -applySimCommand' (CommandNotPresent repo file) st _ = checkKnownRepo repo st $ \u -> - case (M.lookup file (simFiles st), M.lookup u (simRepoState st)) of - (Just k, Just rst) - | u `S.notMember` getSimLocations rst k -> - Right $ Right st - | otherwise -> present - (Just _, Nothing) -> present - (Nothing, _) -> Left $ "Expected " ++ fromRawFilePath file - ++ " to not be present in " ++ fromRepoName repo - ++ ", but the simulation does not include that file." - where - present = Left $ "Expected " ++ fromRawFilePath file - ++ " not to be present in " - ++ fromRepoName repo ++ ", but it is present." applySimCommand' (CommandNumCopies n) st _ = Right $ Right $ st { simNumCopies = configuredNumCopies n @@ -452,7 +453,9 @@ applySimCommand' (CommandRebalance b) st _ = } applySimCommand' (CommandComment _) st _ = Right $ Right st applySimCommand' CommandBlank st _ = Right $ Right st - +applySimCommand' (CommandPresent _ _) _ _ = error "applySimCommand' CommandPresent" +applySimCommand' (CommandNotPresent _ _) _ _ = error "applySimCommand' CommandNotPresent" + handleStep :: Int -> Int -> SimState SimRepo -> Annex (SimState SimRepo) handleStep startn n st | n > 0 = do