# HG changeset patch # User Pierre-Yves David # Date 2022-11-29 17:30:54 # Node ID 1e6c373605272e5e3baabdb634e03530225d67d6 # Parent c261a628e5252f373f78ed40a0702d794a91a1de 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. diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -181,9 +181,13 @@ def _peerorrepo( 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 @@ def _peerorrepo( 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(