debug: add a debug::unbundle command that simulate the unbundle from a push
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 23 Feb 2024 04:26:03 +0100
changeset 51400 e2dfa403452d
parent 51398 e9304c39e075
child 51401 8f2ea3fa50fd
debug: add a debug::unbundle command that simulate the unbundle from a push The code have different behavior when the unbundle comes from a push, so we introduce a command that can simulate such unbundle. For our copy of mozilla-try-2023-03-22, this make the unbundle jump from 2.5 seconds (with `hg unbundle`) to 15 seconds (with `hg debug::unbundle`). That 15 seconds timings is consistent with the issue seen in production.
mercurial/commands.py
mercurial/debugcommands.py
tests/test-completion.t
tests/test-debugcommands.t
tests/test-help.t
--- a/mercurial/commands.py	Wed Feb 14 08:14:46 2024 +0100
+++ b/mercurial/commands.py	Fri Feb 23 04:26:03 2024 +0100
@@ -7730,7 +7730,7 @@
     _(b'[-u] FILE...'),
     helpcategory=command.CATEGORY_IMPORT_EXPORT,
 )
-def unbundle(ui, repo, fname1, *fnames, **opts):
+def unbundle(ui, repo, fname1, *fnames, _unbundle_source=b'unbundle', **opts):
     """apply one or more bundle files
 
     Apply one or more bundle files generated by :hg:`bundle`.
@@ -7758,7 +7758,11 @@
                     txnname = b'unbundle\n%s' % urlutil.hidepassword(url)
                 with repo.transaction(txnname) as tr:
                     op = bundle2.applybundle(
-                        repo, gen, tr, source=b'unbundle', url=url
+                        repo,
+                        gen,
+                        tr,
+                        source=_unbundle_source,  # used by debug::unbundle
+                        url=url,
                     )
             except error.BundleUnknownFeatureError as exc:
                 raise error.Abort(
--- a/mercurial/debugcommands.py	Wed Feb 14 08:14:46 2024 +0100
+++ b/mercurial/debugcommands.py	Fri Feb 23 04:26:03 2024 +0100
@@ -4077,6 +4077,30 @@
 
 
 @command(
+    b'debug::unbundle',
+    [
+        (
+            b'u',
+            b'update',
+            None,
+            _(b'update to new branch head if changesets were unbundled'),
+        )
+    ],
+    _(b'[-u] FILE...'),
+    helpcategory=command.CATEGORY_IMPORT_EXPORT,
+)
+def debugunbundle(ui, repo, *args, **kwargs):
+    """same as `hg unbundle`, but pretent to come from a push
+
+    This is useful to debug behavior and performance change in this case.
+    """
+    from . import commands  # avoid cycle
+
+    unbundle = cmdutil.findcmd(b'unbundle', commands.table)[1][0]
+    return unbundle(ui, repo, *args, _unbundle_source=b'push', **kwargs)
+
+
+@command(
     b'debugwalk', cmdutil.walkopts, _(b'[OPTION]... [FILE]...'), inferrepo=True
 )
 def debugwalk(ui, repo, *pats, **opts):
--- a/tests/test-completion.t	Wed Feb 14 08:14:46 2024 +0100
+++ b/tests/test-completion.t	Fri Feb 23 04:26:03 2024 +0100
@@ -82,6 +82,7 @@
   debug-revlog-stats
   debug::stable-tail-sort
   debug::stable-tail-sort-leaps
+  debug::unbundle
   debugancestor
   debugantivirusrunning
   debugapplystreamclonebundle
@@ -280,6 +281,7 @@
   debug-revlog-stats: changelog, manifest, filelogs, template
   debug::stable-tail-sort: template
   debug::stable-tail-sort-leaps: template, specific
+  debug::unbundle: update
   debugancestor: 
   debugantivirusrunning: 
   debugapplystreamclonebundle: 
--- a/tests/test-debugcommands.t	Wed Feb 14 08:14:46 2024 +0100
+++ b/tests/test-debugcommands.t	Fri Feb 23 04:26:03 2024 +0100
@@ -659,6 +659,19 @@
   .hg/cache/branch2-immutable
   .hg/cache/branch2-base
 
+Test debug::unbundle
+
+  $ hg bundle --exact --rev tip foo.hg
+  1 changesets found
+  $ hg debug::unbundle foo.hg
+  adding changesets
+  adding manifests
+  adding file changes
+  added 0 changesets with 0 changes to 1 files (no-pure !)
+  9 local changesets published (no-pure !)
+  3 local changesets published (pure !)
+  (run 'hg update' to get a working copy)
+
 Test debugcolor
 
 #if no-windows
--- a/tests/test-help.t	Wed Feb 14 08:14:46 2024 +0100
+++ b/tests/test-help.t	Fri Feb 23 04:26:03 2024 +0100
@@ -1006,6 +1006,8 @@
    debug::stable-tail-sort-leaps
                  display the leaps in the stable-tail sort of a node, one per
                  line
+   debug::unbundle
+                 same as 'hg unbundle', but pretent to come from a push
    debugancestor
                  find the ancestor revision of two revisions in a given index
    debugantivirusrunning