Mercurial > public > mercurial-scm > hg-stable
diff mercurial/ui.py @ 46733:66fb04552122
ui: pass a `ui` object to `paths.getpath`
I want to introduce more path's suboption and make it possible to use default
value for them. Processing theses sub-options might result in warnings. We
need a `ui` object to issue such warnings.
To make things simpler, we add an helper method on the `ui` object.
Differential Revision: https://phab.mercurial-scm.org/D10162
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 11 Mar 2021 17:26:49 +0100 |
parents | b91a695b3b08 |
children | e3f15c553522 |
line wrap: on
line diff
--- a/mercurial/ui.py Mon Mar 15 10:57:02 2021 +0100 +++ b/mercurial/ui.py Thu Mar 11 17:26:49 2021 +0100 @@ -1031,7 +1031,7 @@ def expandpath(self, loc, default=None): """Return repository location relative to cwd or from [paths]""" try: - p = self.paths.getpath(loc) + p = self.getpath(loc) if p: return p.rawloc except error.RepoError: @@ -1039,7 +1039,7 @@ if default: try: - p = self.paths.getpath(default) + p = self.getpath(default) if p: return p.rawloc except error.RepoError: @@ -1051,6 +1051,13 @@ def paths(self): return paths(self) + def getpath(self, *args, **kwargs): + """see paths.getpath for details + + This method exist as `getpath` need a ui for potential warning message. + """ + return self.paths.getpath(self, *args, **kwargs) + @property def fout(self): return self._fout @@ -2190,7 +2197,7 @@ loc, sub = ui.configsuboptions(b'paths', name) self[name] = path(ui, name, rawloc=loc, suboptions=sub) - def getpath(self, name, default=None): + def getpath(self, ui, name, default=None): """Return a ``path`` from a string, falling back to default. ``name`` can be a named path or locations. Locations are filesystem @@ -2222,8 +2229,8 @@ except KeyError: # Try to resolve as a local path or URI. try: - # We don't pass sub-options in, so no need to pass ui instance. - return path(None, None, rawloc=name) + # we pass the ui instance are warning might need to be issued + return path(ui, None, rawloc=name) except ValueError: raise error.RepoError(_(b'repository %s does not exist') % name)