peer-or-repo: move the object setup in its own function
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 29 Nov 2022 18:30:54 +0100
changeset 49682 1e6c37360527
parent 49681 c261a628e525
child 49683 d9791643aab7
peer-or-repo: move the object setup in its own function The `_peerorrepo` function is problematic, because it can build different types of object (repository and peer). This make it hard to adjust the arguments to the type of object we needs. So this patch start a series of change to create peer and repo without going through a common function. We move the part of the function doing object setup it its own function to make it simpler to reuse in others contexts.
mercurial/hg.py
--- a/mercurial/hg.py	Sun Nov 06 17:53:17 2022 -0500
+++ b/mercurial/hg.py	Tue Nov 29 18:30:54 2022 +0100
@@ -181,9 +181,13 @@
     ui, path, create=False, presetupfuncs=None, intents=None, createopts=None
 ):
     """return a repository object for the specified path"""
-    obj = _peerlookup(path).instance(
-        ui, path, create, intents=intents, createopts=createopts
-    )
+    cls = _peerlookup(path)
+    obj = cls.instance(ui, path, create, intents=intents, createopts=createopts)
+    _setup_repo_or_peer(ui, obj, presetupfuncs)
+    return obj
+
+
+def _setup_repo_or_peer(ui, obj, presetupfuncs=None):
     ui = getattr(obj, "ui", ui)
     for f in presetupfuncs or []:
         f(ui, obj)
@@ -195,14 +199,12 @@
             if hook:
                 with util.timedcm('reposetup %r', name) as stats:
                     hook(ui, obj)
-                ui.log(
-                    b'extension', b'  > reposetup for %s took %s\n', name, stats
-                )
+                msg = b'  > reposetup for %s took %s\n'
+                ui.log(b'extension', msg, name, stats)
     ui.log(b'extension', b'> all reposetup took %s\n', allreposetupstats)
     if not obj.local():
         for f in wirepeersetupfuncs:
             f(ui, obj)
-    return obj
 
 
 def repository(