diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -35,11 +35,13 @@ from .thirdparty import attr from . import ( bookmarks, + bundle2, changelog, copies, crecord as crecordmod, encoding, error, + exchange, formatter, logcmdutil, match as matchmod, @@ -56,6 +58,7 @@ from . import ( rewriteutil, scmutil, state as statemod, + streamclone, subrepoutil, templatekw, templater, @@ -66,6 +69,7 @@ from . import ( from .utils import ( dateutil, stringutil, + urlutil, ) from .revlogutils import ( @@ -4178,3 +4182,47 @@ def postincoming(ui, repo, modheads, opt elif not ui.configbool(b'commands', b'update.requiredest'): ui.status(_(b"(run 'hg update' to get a working copy)\n")) return False + + +def unbundle_files(ui, repo, fnames, unbundle_source=b'unbundle'): + """utility for `hg unbundle` and `hg debug::unbundle`""" + assert fnames + # avoid circular import + from . import hg + + with repo.lock(): + for fname in fnames: + f = hg.openpath(ui, fname) + gen = exchange.readbundle(ui, f, fname) + if isinstance(gen, streamclone.streamcloneapplier): + raise error.InputError( + _( + b'packed bundles cannot be applied with ' + b'"hg unbundle"' + ), + hint=_(b'use "hg debugapplystreamclonebundle"'), + ) + url = b'bundle:' + fname + try: + txnname = b'unbundle' + if not isinstance(gen, bundle2.unbundle20): + txnname = b'unbundle\n%s' % urlutil.hidepassword(url) + with repo.transaction(txnname) as tr: + op = bundle2.applybundle( + repo, + gen, + tr, + source=unbundle_source, # used by debug::unbundle + url=url, + ) + except error.BundleUnknownFeatureError as exc: + raise error.Abort( + _(b'%s: unknown bundle feature, %s') % (fname, exc), + hint=_( + b"see https://mercurial-scm.org/" + b"wiki/BundleFeature for more " + b"information" + ), + ) + modheads = bundle2.combinechangegroupresults(op) + return modheads diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -60,7 +60,6 @@ from . import ( server, shelve as shelvemod, state as statemod, - streamclone, tags as tagsmod, ui as uimod, util, @@ -7692,7 +7691,7 @@ def tip(ui, repo, **opts): _(b'[-u] FILE...'), helpcategory=command.CATEGORY_IMPORT_EXPORT, ) -def unbundle(ui, repo, fname1, *fnames, _unbundle_source=b'unbundle', **opts): +def unbundle(ui, repo, fname1, *fnames, **opts): """apply one or more bundle files Apply one or more bundle files generated by :hg:`bundle`. @@ -7700,42 +7699,7 @@ def unbundle(ui, repo, fname1, *fnames, Returns 0 on success, 1 if an update has unresolved files. """ fnames = (fname1,) + fnames - - with repo.lock(): - for fname in fnames: - f = hg.openpath(ui, fname) - gen = exchange.readbundle(ui, f, fname) - if isinstance(gen, streamclone.streamcloneapplier): - raise error.InputError( - _( - b'packed bundles cannot be applied with ' - b'"hg unbundle"' - ), - hint=_(b'use "hg debugapplystreamclonebundle"'), - ) - url = b'bundle:' + fname - try: - txnname = b'unbundle' - if not isinstance(gen, bundle2.unbundle20): - txnname = b'unbundle\n%s' % urlutil.hidepassword(url) - with repo.transaction(txnname) as tr: - op = bundle2.applybundle( - repo, - gen, - tr, - source=_unbundle_source, # used by debug::unbundle - url=url, - ) - except error.BundleUnknownFeatureError as exc: - raise error.Abort( - _(b'%s: unknown bundle feature, %s') % (fname, exc), - hint=_( - b"see https://mercurial-scm.org/" - b"wiki/BundleFeature for more " - b"information" - ), - ) - modheads = bundle2.combinechangegroupresults(op) + modheads = cmdutil.unbundle_files(ui, repo, fnames) if cmdutil.postincoming(ui, repo, modheads, opts.get('update'), None, None): return 1 diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -4078,26 +4078,17 @@ def debugupgraderepo(ui, repo, run=False @command( b'debug::unbundle', - [ - ( - b'u', - b'update', - None, - _(b'update to new branch head if changesets were unbundled'), - ) - ], - _(b'[-u] FILE...'), + [], + _(b'FILE...'), helpcategory=command.CATEGORY_IMPORT_EXPORT, ) -def debugunbundle(ui, repo, *args, **kwargs): +def debugunbundle(ui, repo, fname1, *fnames): """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) + fnames = (fname1,) + fnames + cmdutil.unbundle_files(ui, repo, fnames) @command( diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -284,7 +284,7 @@ Show all commands + options debug-revlog-stats: changelog, manifest, filelogs, template debug::stable-tail-sort: template debug::stable-tail-sort-leaps: template, specific - debug::unbundle: update + debug::unbundle: debugancestor: debugantivirusrunning: debugapplystreamclonebundle: diff --git a/tests/test-debugcommands.t b/tests/test-debugcommands.t --- a/tests/test-debugcommands.t +++ b/tests/test-debugcommands.t @@ -663,9 +663,6 @@ Test debug::unbundle 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