# HG changeset patch # User Pierre-Yves David # Date 2023-03-14 04:30:34 # Node ID 3973b1dc3ee375d7a35ce9ad37618d932848c59a # Parent 10318b88b1d65c0e3301298ba7653643de0a4bf2 clone-bundles: add an option to generate bundles in the background This is what the "on-change" version have been doing from the start, it seems useful to also offer this option in the command. diff --git a/hgext/clonebundles.py b/hgext/clonebundles.py --- a/hgext/clonebundles.py +++ b/hgext/clonebundles.py @@ -942,8 +942,23 @@ def reposetup(ui, repo): repo.__class__ = autobundlesrepo -@command(b'admin::clone-bundles-refresh', [], b'') -def cmd_admin_clone_bundles_refresh(ui, repo: localrepo.localrepository): +@command( + b'admin::clone-bundles-refresh', + [ + ( + b'', + b'background', + False, + _(b'start bundle generation in the background'), + ), + ], + b'', +) +def cmd_admin_clone_bundles_refresh( + ui, + repo: localrepo.localrepository, + background=False, +): """generate clone bundles according to the configuration This runs the logic for automatic generation, removing outdated bundles and @@ -955,28 +970,39 @@ def cmd_admin_clone_bundles_refresh(ui, op_id = b"%d_acbr" % os.getpid() create, delete = auto_bundle_needed_actions(repo, bundles, op_id) - # we clean up outdated bundle before generating new one to keep the last - # two version of the bundle around for a while and avoid having to deal - # client that just got served a manifest. - for o in delete: - delete_bundle(repo, o) - update_bundle_list(repo, del_bundles=delete) + # if some bundles are scheduled for creation in the background, they will + # deal with garbage collection too, so no need to synchroniously do it. + # + # However if no bundles are scheduled for creation, we need to explicitly do + # it here. + if not (background and create): + # we clean up outdated bundles before generating new ones to keep the + # last two versions of the bundle around for a while and avoid having to + # deal with clients that just got served a manifest. + for o in delete: + delete_bundle(repo, o) + update_bundle_list(repo, del_bundles=delete) if create: fpath = repo.vfs.makedirs(b'tmp-bundles') - for requested_bundle in create: - if debug: - msg = b'clone-bundles: starting bundle generation: %s\n' - repo.ui.write(msg % requested_bundle.bundle_type) - fname = requested_bundle.suggested_filename - fpath = repo.vfs.join(b'tmp-bundles', fname) - generating_bundle = requested_bundle.generating(fpath) - update_bundle_list(repo, new_bundles=[generating_bundle]) - requested_bundle.generate_bundle(repo, fpath) - result = upload_bundle(repo, generating_bundle) - update_bundle_list(repo, new_bundles=[result]) - update_ondisk_manifest(repo) - cleanup_tmp_bundle(repo, generating_bundle) + + if background: + for requested_bundle in create: + start_one_bundle(repo, requested_bundle) + else: + for requested_bundle in create: + if debug: + msg = b'clone-bundles: starting bundle generation: %s\n' + repo.ui.write(msg % requested_bundle.bundle_type) + fname = requested_bundle.suggested_filename + fpath = repo.vfs.join(b'tmp-bundles', fname) + generating_bundle = requested_bundle.generating(fpath) + update_bundle_list(repo, new_bundles=[generating_bundle]) + requested_bundle.generate_bundle(repo, fpath) + result = upload_bundle(repo, generating_bundle) + update_bundle_list(repo, new_bundles=[result]) + update_ondisk_manifest(repo) + cleanup_tmp_bundle(repo, generating_bundle) @command(b'admin::clone-bundles-clear', [], b'') diff --git a/tests/test-clonebundles-autogen.t b/tests/test-clonebundles-autogen.t --- a/tests/test-clonebundles-autogen.t +++ b/tests/test-clonebundles-autogen.t @@ -335,3 +335,26 @@ Nothing should remain $ cat ../server/.hg/clonebundles.manifest $ ls -1 ../final-upload $ ls -1 ../server/.hg/tmp-bundles + +background generation +--------------------- + +generate bundle using background subprocess +(since we are in devel mode, the command will still wait for the background +process to end) + + $ hg -R ../server/ admin::clone-bundles-refresh --background + 11 changesets found + 11 changesets found + clone-bundles: starting bundle generation: v1 + clone-bundles: starting bundle generation: v2 + +bundles should have been generated + + $ cat ../server/.hg/clonebundles.manifest + file:/*/$TESTTMP/final-upload/full-v1-11_revs-4226b1cd5fda_tip-*_acbr.hg BUNDLESPEC=v1 REQUIRESNI=true (glob) + file:/*/$TESTTMP/final-upload/full-v2-11_revs-4226b1cd5fda_tip-*_acbr.hg BUNDLESPEC=v2 REQUIRESNI=true (glob) + $ ls -1 ../final-upload + full-v1-11_revs-4226b1cd5fda_tip-*_acbr.hg (glob) + full-v2-11_revs-4226b1cd5fda_tip-*_acbr.hg (glob) + $ ls -1 ../server/.hg/tmp-bundles