addmulti
authorJoey Hess <joeyh@joeyh.name>
Tue, 17 Sep 2024 15:19:59 +0000 (11:19 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 17 Sep 2024 15:22:14 +0000 (11:22 -0400)
Annex/Sim.hs
Annex/Sim/File.hs
doc/git-annex-sim.mdwn
doc/todo/git-annex_proxies.mdwn

index ea66cea3e076bc72920a2a5026c73a2ba9a1d3da..f1843760746ad323094cee9c5d0d6656849506a8 100644 (file)
@@ -199,6 +199,7 @@ data SimCommand
        | CommandDisconnect Connections
        | CommandAddTree RepoName PreferredContentExpression
        | CommandAdd RawFilePath ByteSize [RepoName]
+       | CommandAddMulti Int String ByteSize ByteSize [RepoName]
        | CommandStep Int
        | CommandAction SimAction
        | CommandSeed Int
@@ -319,6 +320,16 @@ applySimCommand' (CommandAdd file sz repos) st _ =
                        { simFiles = M.insert file k (simFiles st')
                        }
                in go k st'' rest
+applySimCommand' (CommandAddMulti n suffix minsz maxsz repos) st repobyname = 
+       let (sz, st') = simRandom st (randomR (minsz, maxsz)) id
+           file = toRawFilePath (show n ++ suffix)
+       in case applySimCommand' (CommandAdd file sz repos) st' repobyname of
+               Left err -> Left err
+               Right (Right st'') -> 
+                       case pred n of
+                               0 -> Right (Right st'')
+                               n' -> applySimCommand' (CommandAddMulti n' suffix minsz maxsz repos) st'' repobyname
+               Right (Left _) -> error "applySimCommand' CommandAddMulti"
 applySimCommand' (CommandStep _) _ _ = error "applySimCommand' CommandStep"
 applySimCommand' (CommandAction act) st _ =
        case getSimActionComponents act st of
index d9872767100148ddc57e1284997928076cb3f6d3..11c66248c40b5fd2a10ad10f9df7b12234c4ab2c 100644 (file)
@@ -49,6 +49,8 @@ generateSimFile = unlines . map unwords . go
                ["addtree", name, expr] : go rest
        go (CommandAdd f sz repos : rest) =
                (["add", fromRawFilePath f, showsize sz] ++ map fromRepoName repos) : go rest
+       go (CommandAddMulti n suffix minsz maxsz repos : rest) =
+               (["addmulti", show n, suffix, showsize minsz, showsize maxsz] ++ map fromRepoName repos) : go rest
        go (CommandStep n : rest) =
                ["step", show n] : go rest
        go (CommandAction act : rest) = formatAction act : go rest
@@ -127,6 +129,16 @@ parseSimCommand ("add":filename:size:repos) =
                        sz
                        (map RepoName repos)
                Nothing -> Left $ "Unable to parse file size \"" ++ size ++ "\""
+parseSimCommand ("addmulti":num:suffix:minsize:maxsize:repos) =
+       case readSize dataUnits minsize of
+               Just minsz -> case readSize dataUnits maxsize of
+                       Just maxsz -> case readMaybe num of
+                               Just n -> Right $ CommandAddMulti 
+                                       n suffix minsz maxsz
+                                       (map RepoName repos)
+                               Nothing -> Left $ "Unable to parse number \"" ++ num ++ "\""
+                       Nothing -> Left $ "Unable to parse file size \"" ++ maxsize ++ "\""
+               Nothing -> Left $ "Unable to parse file size \"" ++ minsize ++ "\""
 parseSimCommand ("step":n:[]) =
        case readMaybe n of
                        Just n' -> Right $ CommandStep n'
index b87befdf071c1cdcc3fdd6a6533b5a9a25fb8529..eeb3b1cf073d080e05c33de03639490c81f8e954 100644 (file)
@@ -137,6 +137,9 @@ as passed to "git annex sim" while a simulation is running.
   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,
@@ -156,6 +159,23 @@ as passed to "git annex sim" while a simulation is running.
   different repositories. The files in the simulation are the same across
   all simulated repositories.
 
+* `addmulti N suffix minsize maxsize repo [repo ...]
+
+  Add multiple simulated annexed files, with random sizes in the range
+  between minsize and maxsize.
+
+  The files are named by combining the number, which starts at 1 and goes
+  up to N, with the suffix.
+
+  For example:
+
+    addmulti 100 testfile.jpg 100kb 10mb foo
+
+  That adds files named "1testfile.jpg", 2testfile.jpg", etc.
+
+  Note that adding a large number of files to the simulation can slow it
+  down and make it use a lot of memory.
+
 * `step N`
 
   Run the simulation forward by this many steps.
index 1bcaedabaf65f15b30176652a8d0a4b196ab900d..56d15a30bc16d685ba25d043aa36a35b5d4b8ee6 100644 (file)
@@ -34,9 +34,6 @@ Planned schedule of work:
 
 * sim: Test ActionDropUnwanted Nothing
 
-* sim: Command to create a set of files with random sizes in a specified
-  range.
-
 * sim: implement addtree
 
 * sim: implement ActionDropUnwanted