bundleoperation: optionnaly record the `remote` that produced the bundle
We have the information at hand, and the peer now have knownledge of its `path` object, which constaints useful behavior configuration.
So the simpler seems to be to pass that object around so it can be used if
needed.
--- a/hgext/narrow/narrowcommands.py Mon Dec 05 03:23:46 2022 +0100
+++ b/hgext/narrow/narrowcommands.py Sat Dec 03 01:16:22 2022 +0100
@@ -416,7 +416,7 @@
repo, trmanager.transaction, source=b'widen'
)
# TODO: we should catch error.Abort here
- bundle2.processbundle(repo, bundle, op=op)
+ bundle2.processbundle(repo, bundle, op=op, remote=remote)
if ellipsesremote:
with ds.parentchange():
--- a/mercurial/bundle2.py Mon Dec 05 03:23:46 2022 +0100
+++ b/mercurial/bundle2.py Sat Dec 03 01:16:22 2022 +0100
@@ -315,8 +315,17 @@
* a way to construct a bundle response when applicable.
"""
- def __init__(self, repo, transactiongetter, captureoutput=True, source=b''):
+ def __init__(
+ self,
+ repo,
+ transactiongetter,
+ captureoutput=True,
+ source=b'',
+ remote=None,
+ ):
self.repo = repo
+ # the peer object who produced this bundle if available
+ self.remote = remote
self.ui = repo.ui
self.records = unbundlerecords()
self.reply = None
@@ -363,7 +372,7 @@
raise TransactionUnavailable()
-def applybundle(repo, unbundler, tr, source, url=None, **kwargs):
+def applybundle(repo, unbundler, tr, source, url=None, remote=None, **kwargs):
# transform me into unbundler.apply() as soon as the freeze is lifted
if isinstance(unbundler, unbundle20):
tr.hookargs[b'bundle2'] = b'1'
@@ -371,10 +380,12 @@
tr.hookargs[b'source'] = source
if url is not None and b'url' not in tr.hookargs:
tr.hookargs[b'url'] = url
- return processbundle(repo, unbundler, lambda: tr, source=source)
+ return processbundle(
+ repo, unbundler, lambda: tr, source=source, remote=remote
+ )
else:
# the transactiongetter won't be used, but we might as well set it
- op = bundleoperation(repo, lambda: tr, source=source)
+ op = bundleoperation(repo, lambda: tr, source=source, remote=remote)
_processchangegroup(op, unbundler, tr, source, url, **kwargs)
return op
@@ -450,7 +461,14 @@
)
-def processbundle(repo, unbundler, transactiongetter=None, op=None, source=b''):
+def processbundle(
+ repo,
+ unbundler,
+ transactiongetter=None,
+ op=None,
+ source=b'',
+ remote=None,
+):
"""This function process a bundle, apply effect to/from a repo
It iterates over each part then searches for and uses the proper handling
@@ -466,7 +484,12 @@
if op is None:
if transactiongetter is None:
transactiongetter = _notransaction
- op = bundleoperation(repo, transactiongetter, source=source)
+ op = bundleoperation(
+ repo,
+ transactiongetter,
+ source=source,
+ remote=remote,
+ )
# todo:
# - replace this is a init function soon.
# - exception catching
--- a/mercurial/exchange.py Mon Dec 05 03:23:46 2022 +0100
+++ b/mercurial/exchange.py Sat Dec 03 01:16:22 2022 +0100
@@ -1183,7 +1183,12 @@
trgetter = None
if pushback:
trgetter = pushop.trmanager.transaction
- op = bundle2.processbundle(pushop.repo, reply, trgetter)
+ op = bundle2.processbundle(
+ pushop.repo,
+ reply,
+ trgetter,
+ remote=pushop.remote,
+ )
except error.BundleValueError as exc:
raise error.RemoteError(_(b'missing support for %s') % exc)
except bundle2.AbortFromPart as exc:
@@ -1903,10 +1908,18 @@
try:
op = bundle2.bundleoperation(
- pullop.repo, pullop.gettransaction, source=b'pull'
+ pullop.repo,
+ pullop.gettransaction,
+ source=b'pull',
+ remote=pullop.remote,
)
op.modes[b'bookmarks'] = b'records'
- bundle2.processbundle(pullop.repo, bundle, op=op)
+ bundle2.processbundle(
+ pullop.repo,
+ bundle,
+ op=op,
+ remote=pullop.remote,
+ )
except bundle2.AbortFromPart as exc:
pullop.repo.ui.error(_(b'remote: abort: %s\n') % exc)
raise error.RemoteError(_(b'pull failed on remote'), hint=exc.hint)
@@ -1995,7 +2008,12 @@
).result()
bundleop = bundle2.applybundle(
- pullop.repo, cg, tr, b'pull', pullop.remote.url()
+ pullop.repo,
+ cg,
+ tr,
+ b'pull',
+ pullop.remote.url(),
+ remote=pullop.remote,
)
pullop.cgresult = bundle2.combinechangegroupresults(bundleop)