# HG changeset patch # User Jun Wu # Date 2017-04-30 04:39:47 # Node ID 71e735bd8170bccd74f556388b7c4d491f890701 # Parent 7d0c69505a662c85bb65a4e88e3bd65010ad7f00 dispatch: make request accept additional reposetups chg needs special logic around repo object creation (like, collecting and reporting repo path to the master server). Adding "reposetup" to dispatch.request seems to be an easy and reasonably clean way to allow that. diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -47,7 +47,7 @@ from . import ( class request(object): def __init__(self, args, ui=None, repo=None, fin=None, fout=None, - ferr=None): + ferr=None, prereposetups=None): self.args = args self.ui = ui self.repo = repo @@ -57,6 +57,10 @@ class request(object): self.fout = fout self.ferr = ferr + # reposetups which run before extensions, useful for chg to pre-fill + # low-level repo state (for example, changelog) before extensions. + self.prereposetups = prereposetups or [] + def _runexithandlers(self): exc = None handlers = self.ui._exithandlers @@ -875,7 +879,8 @@ def _dispatch(req): repo.ui.ferr = ui.ferr else: try: - repo = hg.repository(ui, path=path) + repo = hg.repository(ui, path=path, + presetupfuncs=req.prereposetups) if not repo.local(): raise error.Abort(_("repository '%s' is not local") % path) diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -148,10 +148,12 @@ def openpath(ui, path): # a list of (ui, repo) functions called for wire peer initialization wirepeersetupfuncs = [] -def _peerorrepo(ui, path, create=False): +def _peerorrepo(ui, path, create=False, presetupfuncs=None): """return a repository object for the specified path""" obj = _peerlookup(path).instance(ui, path, create) ui = getattr(obj, "ui", ui) + for f in presetupfuncs or []: + f(ui, obj) for name, module in extensions.extensions(ui): hook = getattr(module, 'reposetup', None) if hook: @@ -161,9 +163,9 @@ def _peerorrepo(ui, path, create=False): f(ui, obj) return obj -def repository(ui, path='', create=False): +def repository(ui, path='', create=False, presetupfuncs=None): """return a repository object for the specified path""" - peer = _peerorrepo(ui, path, create) + peer = _peerorrepo(ui, path, create, presetupfuncs=presetupfuncs) repo = peer.local() if not repo: raise error.Abort(_("repository '%s' is not local") %