sim: implement addtree
authorJoey Hess <joeyh@joeyh.name>
Fri, 20 Sep 2024 14:34:52 +0000 (10:34 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 20 Sep 2024 14:34:52 +0000 (10:34 -0400)
Annex/Sim.hs
doc/git-annex-sim.mdwn
doc/todo/git-annex_proxies.mdwn

index edd63d47d2902c37f3f437861603f4d23524515e..89a85d469a438943d98a9266660f42d8e1da8cd1 100644 (file)
@@ -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 $
index 55d8e3ea6e7f2894128ca76362af35b1e78b6491..6bd477e999a064599c1461f298d104f3635d62f3 100644 (file)
@@ -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,
index 18883e516bdd1c85467dbbd907d186da22d54efe..9948788eca012da5bb2584f7e744210cddae58e4 100644 (file)
@@ -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