clone-bundles: add a configuration to control auto-generation on changes
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 13 Mar 2023 04:18:45 +0100
changeset 50468 65fb4cedd5ea
parent 50467 d611805e7374
child 50469 23db5f15cc0c
clone-bundles: add a configuration to control auto-generation on changes We are about to introduce a "manual" way to deal with automatic clone management but running a command using some internal API. The first step is to introduce a way to control the "on changes" behavior.
hgext/clonebundles.py
tests/test-clonebundles-autogen.t
--- a/hgext/clonebundles.py	Mon Mar 13 18:44:52 2023 +0100
+++ b/hgext/clonebundles.py	Mon Mar 13 04:18:45 2023 +0100
@@ -223,16 +223,22 @@
 
 See `hg help bundlespec` for details about available options.
 
-Bundles are not generated on each push. By default new bundles are generated
-when 5% of the repository content or at least 1000 revisions are not contained
-in the cached bundles. This option can be controled by the
-`clone-bundles.trigger.below-bundled-ratio` option (default to 0.95) and the
-`clone-bundles.trigger.revs` options (default 1000)::
+By default, new bundles are generated when 5% of the repository contents or at
+least 1000 revisions are not contained in the cached bundles. This option can
+be controlled by the `clone-bundles.trigger.below-bundled-ratio` option
+(default 0.95) and the `clone-bundles.trigger.revs` option (default 1000)::
 
     [clone-bundles]
     trigger.below-bundled-ratio=0.95
     trigger.revs=1000
 
+This logic can be automatically triggered on each repository changes if
+`clone-bundles.auto-generate.on-change` is set to `yes`.
+
+    [clone-bundles]
+    auto-generate.on-change=yes
+    auto-generate.formats= zstd-v2, gzip-v2
+
 Bundles Upload and Serving:
 ...........................
 
@@ -320,6 +326,7 @@
 cmdtable = {}
 command = registrar.command(cmdtable)
 
+configitem(b'clone-bundles', b'auto-generate.on-change', default=False)
 configitem(b'clone-bundles', b'auto-generate.formats', default=list)
 configitem(b'clone-bundles', b'trigger.below-bundled-ratio', default=0.95)
 configitem(b'clone-bundles', b'trigger.revs', default=1000)
@@ -897,10 +904,14 @@
     class autobundlesrepo(repo.__class__):
         def transaction(self, *args, **kwargs):
             tr = super(autobundlesrepo, self).transaction(*args, **kwargs)
+            enabled = repo.ui.configbool(
+                b'clone-bundles',
+                b'auto-generate.on-change',
+            )
             targets = repo.ui.configlist(
                 b'clone-bundles', b'auto-generate.formats'
             )
-            if targets:
+            if enabled and targets:
                 tr.addpostclose(CAT_POSTCLOSE, make_auto_bundler(self))
             return tr
 
--- a/tests/test-clonebundles-autogen.t	Mon Mar 13 18:44:52 2023 +0100
+++ b/tests/test-clonebundles-autogen.t	Mon Mar 13 04:18:45 2023 +0100
@@ -9,6 +9,7 @@
   > clonebundles =
   > 
   > [clone-bundles]
+  > auto-generate.on-change = yes
   > auto-generate.formats = v2
   > upload-command = cp "\$HGCB_BUNDLE_PATH" "$TESTTMP"/final-upload/
   > delete-command = rm -f "$TESTTMP/final-upload/\$HGCB_BASENAME"