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.
This commit is contained in:
Jun Wu 2017-04-29 21:39:47 -07:00
parent 9e19911eaa
commit cf441f3e42
2 changed files with 12 additions and 5 deletions

View File

@ -47,7 +47,7 @@ from . import (
class request(object): class request(object):
def __init__(self, args, ui=None, repo=None, fin=None, fout=None, def __init__(self, args, ui=None, repo=None, fin=None, fout=None,
ferr=None): ferr=None, prereposetups=None):
self.args = args self.args = args
self.ui = ui self.ui = ui
self.repo = repo self.repo = repo
@ -57,6 +57,10 @@ class request(object):
self.fout = fout self.fout = fout
self.ferr = ferr 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): def _runexithandlers(self):
exc = None exc = None
handlers = self.ui._exithandlers handlers = self.ui._exithandlers
@ -875,7 +879,8 @@ def _dispatch(req):
repo.ui.ferr = ui.ferr repo.ui.ferr = ui.ferr
else: else:
try: try:
repo = hg.repository(ui, path=path) repo = hg.repository(ui, path=path,
presetupfuncs=req.prereposetups)
if not repo.local(): if not repo.local():
raise error.Abort(_("repository '%s' is not local") raise error.Abort(_("repository '%s' is not local")
% path) % path)

View File

@ -148,10 +148,12 @@ def openpath(ui, path):
# a list of (ui, repo) functions called for wire peer initialization # a list of (ui, repo) functions called for wire peer initialization
wirepeersetupfuncs = [] wirepeersetupfuncs = []
def _peerorrepo(ui, path, create=False): def _peerorrepo(ui, path, create=False, presetupfuncs=None):
"""return a repository object for the specified path""" """return a repository object for the specified path"""
obj = _peerlookup(path).instance(ui, path, create) obj = _peerlookup(path).instance(ui, path, create)
ui = getattr(obj, "ui", ui) ui = getattr(obj, "ui", ui)
for f in presetupfuncs or []:
f(ui, obj)
for name, module in extensions.extensions(ui): for name, module in extensions.extensions(ui):
hook = getattr(module, 'reposetup', None) hook = getattr(module, 'reposetup', None)
if hook: if hook:
@ -161,9 +163,9 @@ def _peerorrepo(ui, path, create=False):
f(ui, obj) f(ui, obj)
return 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""" """return a repository object for the specified path"""
peer = _peerorrepo(ui, path, create) peer = _peerorrepo(ui, path, create, presetupfuncs=presetupfuncs)
repo = peer.local() repo = peer.local()
if not repo: if not repo:
raise error.Abort(_("repository '%s' is not local") % raise error.Abort(_("repository '%s' is not local") %