From cf441f3e42520a651992185bd5b05598f1547bab Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Sat, 29 Apr 2017 21:39:47 -0700 Subject: [PATCH] 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. --- mercurial/dispatch.py | 9 +++++++-- mercurial/hg.py | 8 +++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py index cefdebeea4..68a6087c7b 100644 --- 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 index b98dc2fc74..6e04f6739c 100644 --- 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") %