Mercurial > hg
changeset 49682:1e6c37360527
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.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 29 Nov 2022 18:30:54 +0100 |
parents | c261a628e525 |
children | d9791643aab7 |
files | mercurial/hg.py |
diffstat | 1 files changed, 9 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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(