changeset 32379:71e735bd8170

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.
author Jun Wu <quark@fb.com>
date Sat, 29 Apr 2017 21:39:47 -0700
parents 7d0c69505a66
children 5db6d70fd30b
files mercurial/dispatch.py mercurial/hg.py
diffstat 2 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dispatch.py	Sat May 20 14:01:05 2017 -0700
+++ b/mercurial/dispatch.py	Sat Apr 29 21:39:47 2017 -0700
@@ -47,7 +47,7 @@
 
 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 @@
         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 @@
                 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)
--- a/mercurial/hg.py	Sat May 20 14:01:05 2017 -0700
+++ b/mercurial/hg.py	Sat Apr 29 21:39:47 2017 -0700
@@ -148,10 +148,12 @@
 # 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 @@
             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") %