Patchwork D10162: ui: pass a `ui` objec to `paths.getpath`

login
register
mail settings
Submitter phabricator
Date March 11, 2021, 5:10 p.m.
Message ID <differential-rev-PHID-DREV-zczf6mcngm3wigziaps4-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48478/
State Superseded
Headers show

Comments

phabricator - March 11, 2021, 5:10 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I want to introduce more path's suboption and make it possible to default value for them.
  Processing theses suboption might result in warning and we need a ui objec to
  issue that warning.
  
  To make things simple, we add an helper method on the `ui` object.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10162

AFFECTED FILES
  contrib/perf.py
  hgext/infinitepush/__init__.py
  mercurial/commands.py
  mercurial/hg.py
  mercurial/revset.py
  mercurial/ui.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -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)
 
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1826,9 +1826,9 @@ 
         l and getstring(l[0], _(b"outgoing requires a repository path")) or b''
     )
     if not dest:
-        # ui.paths.getpath() explicitly tests for None, not just a boolean
+        # ui.getpath() explicitly tests for None, not just a boolean
         dest = None
-    path = repo.ui.paths.getpath(dest, default=(b'default-push', b'default'))
+    path = repo.ui.getpath(dest, default=(b'default-push', b'default'))
     if not path:
         raise error.Abort(
             _(b'default repository not configured!'),
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -1317,7 +1317,7 @@ 
 
 
 def _outgoing(ui, repo, dest, opts):
-    path = ui.paths.getpath(dest, default=(b'default-push', b'default'))
+    path = ui.getpath(dest, default=(b'default-push', b'default'))
     if not path:
         raise error.Abort(
             _(b'default repository not configured!'),
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4946,7 +4946,7 @@ 
     """
     # hg._outgoing() needs to re-resolve the path in order to handle #branch
     # style URLs, so don't overwrite dest.
-    path = ui.paths.getpath(dest, default=(b'default-push', b'default'))
+    path = ui.getpath(dest, default=(b'default-push', b'default'))
     if not path:
         raise error.ConfigError(
             _(b'default repository not configured!'),
@@ -5680,7 +5680,7 @@ 
                 # this lets simultaneous -r, -b options continue working
                 opts.setdefault(b'rev', []).append(b"null")
 
-    path = ui.paths.getpath(dest, default=(b'default-push', b'default'))
+    path = ui.getpath(dest, default=(b'default-push', b'default'))
     if not path:
         raise error.ConfigError(
             _(b'default repository not configured!'),
diff --git a/hgext/infinitepush/__init__.py b/hgext/infinitepush/__init__.py
--- a/hgext/infinitepush/__init__.py
+++ b/hgext/infinitepush/__init__.py
@@ -837,7 +837,7 @@ 
                 exchange, b'_localphasemove', _phasemove
             )
         # Copy-paste from `push` command
-        path = ui.paths.getpath(dest, default=(b'default-push', b'default'))
+        path = ui.getpath(dest, default=(b'default-push', b'default'))
         if not path:
             raise error.Abort(
                 _(b'default repository not configured!'),
diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -1407,7 +1407,7 @@ 
     opts = _byteskwargs(opts)
     timer, fm = gettimer(ui, opts)
 
-    path = ui.paths.getpath(dest, default=(b'default-push', b'default'))
+    path = ui.getpath(dest, default=(b'default-push', b'default'))
     if not path:
         raise error.Abort(
             b'default repository not configured!',