From f061ae92fbb9c93761c3700eb80c8001bfcffe5f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 20 Sep 2024 10:34:52 -0400 Subject: [PATCH] sim: implement addtree --- Annex/Sim.hs | 41 ++++++++++++++++++++++++++++++--- doc/git-annex-sim.mdwn | 6 ++--- doc/todo/git-annex_proxies.mdwn | 2 -- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Annex/Sim.hs b/Annex/Sim.hs index edd63d47d2..89a85d469a 100644 --- a/Annex/Sim.hs +++ b/Annex/Sim.hs @@ -17,6 +17,7 @@ import Types.StandardGroups import Types.TrustLevel import Types.Difference import Git +import Git.FilePath import Backend.Hash (genTestKey) import Annex.UUID import Annex.FileMatcher @@ -24,6 +25,7 @@ import Annex.Init import Annex.Startup import Annex.Link import Annex.Wanted +import Annex.CatFile import Logs.Group import Logs.Trust import Logs.PreferredContent @@ -36,6 +38,7 @@ import Logs.Location import qualified Annex import qualified Remote import qualified Git.Construct +import qualified Git.LsFiles import qualified Annex.Queue import System.Random @@ -311,9 +314,39 @@ applySimCommand' (CommandDisconnect connections) st repobyname = Just connections' -> applySimCommand' (CommandDisconnect connections') st' repobyname applySimCommand' (CommandAddTree repo expr) st _ = - checkKnownRepo repo st $ const $ - checkValidPreferredContentExpression expr $ Left $ - error "TODO" -- XXX + checkKnownRepo repo st $ \u -> + checkValidPreferredContentExpression expr $ Left $ do + matcher <- makematcher u + (l, cleanup) <- inRepo $ Git.LsFiles.inRepo [] [] + st' <- go matcher u st l + liftIO $ void cleanup + return st' + where + go _ _ st' [] = return st' + go matcher u st' (f:fs) = catKeyFile f >>= \case + Just k -> do + afile <- AssociatedFile . Just . getTopFilePath + <$> inRepo (toTopFilePath f) + ifM (checkMatcher matcher (Just k) afile NoLiveUpdate mempty (pure False) (pure False)) + ( let st'' = setPresentKey True u k u $ st' + { simFiles = M.insert f k (simFiles st') + } + in go matcher u st'' fs + , go matcher u st' fs + ) + Nothing -> go matcher u st' fs + makematcher :: UUID -> Annex (FileMatcher Annex) + makematcher u = do + groupmap <- groupMap + configmap <- remoteConfigMap + gm <- groupPreferredContentMapRaw + case makeMatcher groupmap configmap gm u id preferredContentTokens parseerr expr of + Right matcher -> return + ( matcher + , MatcherDesc "provided preferred content expression" + ) + Left err -> giveup err + parseerr = Left "preferred content expression parse error" applySimCommand' (CommandAdd file sz repos) st _ = let (k, st') = genSimKey sz st in go k st' repos @@ -990,6 +1023,8 @@ updateSimRepoState newst sr = do stageannexedfile f k = do let f' = annexedfilepath f l <- calcRepo $ gitAnnexLink f' k + liftIO $ createDirectoryIfMissing True $ + takeDirectory $ fromRawFilePath f' addAnnexLink l f' unstageannexedfile f = do liftIO $ removeWhenExistsWith R.removeLink $ diff --git a/doc/git-annex-sim.mdwn b/doc/git-annex-sim.mdwn index 55d8e3ea6e..6bd477e999 100644 --- a/doc/git-annex-sim.mdwn +++ b/doc/git-annex-sim.mdwn @@ -137,12 +137,12 @@ as passed to "git annex sim" while a simulation is running. quantity of files that have the particular properties you are interested in. + When run in a subdirectory of the repository, only files in that + subdirectory are considered for addition. + This can be used with the same files more than once, to make multiple repositories in the simulation contain the same files. - Note that adding a large number of files to the simulation can slow it - down and make it use a lot of memory. - * `add filename size repo [repo ...]` Create a simulated annexed file with the specified filename and size, diff --git a/doc/todo/git-annex_proxies.mdwn b/doc/todo/git-annex_proxies.mdwn index 18883e516b..9948788eca 100644 --- a/doc/todo/git-annex_proxies.mdwn +++ b/doc/todo/git-annex_proxies.mdwn @@ -30,8 +30,6 @@ Planned schedule of work: * Currently working in [[todo/proving_preferred_content_behavior]] -* sim: implement addtree - * sim: May need to use LiveUpdate to make size balanced preferred content work -- 2.30.2