Mercurial > public > mercurial-scm > hg-stable
comparison 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 |
comparison
equal
deleted
inserted
replaced
46732:0732a7264226 | 46733:66fb04552122 |
---|---|
1029 return user | 1029 return user |
1030 | 1030 |
1031 def expandpath(self, loc, default=None): | 1031 def expandpath(self, loc, default=None): |
1032 """Return repository location relative to cwd or from [paths]""" | 1032 """Return repository location relative to cwd or from [paths]""" |
1033 try: | 1033 try: |
1034 p = self.paths.getpath(loc) | 1034 p = self.getpath(loc) |
1035 if p: | 1035 if p: |
1036 return p.rawloc | 1036 return p.rawloc |
1037 except error.RepoError: | 1037 except error.RepoError: |
1038 pass | 1038 pass |
1039 | 1039 |
1040 if default: | 1040 if default: |
1041 try: | 1041 try: |
1042 p = self.paths.getpath(default) | 1042 p = self.getpath(default) |
1043 if p: | 1043 if p: |
1044 return p.rawloc | 1044 return p.rawloc |
1045 except error.RepoError: | 1045 except error.RepoError: |
1046 pass | 1046 pass |
1047 | 1047 |
1048 return loc | 1048 return loc |
1049 | 1049 |
1050 @util.propertycache | 1050 @util.propertycache |
1051 def paths(self): | 1051 def paths(self): |
1052 return paths(self) | 1052 return paths(self) |
1053 | |
1054 def getpath(self, *args, **kwargs): | |
1055 """see paths.getpath for details | |
1056 | |
1057 This method exist as `getpath` need a ui for potential warning message. | |
1058 """ | |
1059 return self.paths.getpath(self, *args, **kwargs) | |
1053 | 1060 |
1054 @property | 1061 @property |
1055 def fout(self): | 1062 def fout(self): |
1056 return self._fout | 1063 return self._fout |
1057 | 1064 |
2188 if not loc: | 2195 if not loc: |
2189 continue | 2196 continue |
2190 loc, sub = ui.configsuboptions(b'paths', name) | 2197 loc, sub = ui.configsuboptions(b'paths', name) |
2191 self[name] = path(ui, name, rawloc=loc, suboptions=sub) | 2198 self[name] = path(ui, name, rawloc=loc, suboptions=sub) |
2192 | 2199 |
2193 def getpath(self, name, default=None): | 2200 def getpath(self, ui, name, default=None): |
2194 """Return a ``path`` from a string, falling back to default. | 2201 """Return a ``path`` from a string, falling back to default. |
2195 | 2202 |
2196 ``name`` can be a named path or locations. Locations are filesystem | 2203 ``name`` can be a named path or locations. Locations are filesystem |
2197 paths or URIs. | 2204 paths or URIs. |
2198 | 2205 |
2220 try: | 2227 try: |
2221 return self[name] | 2228 return self[name] |
2222 except KeyError: | 2229 except KeyError: |
2223 # Try to resolve as a local path or URI. | 2230 # Try to resolve as a local path or URI. |
2224 try: | 2231 try: |
2225 # We don't pass sub-options in, so no need to pass ui instance. | 2232 # we pass the ui instance are warning might need to be issued |
2226 return path(None, None, rawloc=name) | 2233 return path(ui, None, rawloc=name) |
2227 except ValueError: | 2234 except ValueError: |
2228 raise error.RepoError(_(b'repository %s does not exist') % name) | 2235 raise error.RepoError(_(b'repository %s does not exist') % name) |
2229 | 2236 |
2230 | 2237 |
2231 _pathsuboptions = {} | 2238 _pathsuboptions = {} |