Patchwork [2,of,5,paths,v3] commands.paths: use ui.paths to show paths

login
register
mail settings
Submitter Gregory Szorc
Date March 8, 2015, 7:54 p.m.
Message ID <57681bad997779da8877.1425844455@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/7942/
State Accepted
Delegated to: Pierre-Yves David
Headers show

Comments

Gregory Szorc - March 8, 2015, 7:54 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1423342170 28800
#      Sat Feb 07 12:49:30 2015 -0800
# Node ID 57681bad997779da88778ff95254951c89250441
# Parent  7df546527053a134d03777d89e8c98ec75edaf6f
commands.paths: use ui.paths to show paths

We now have an API for representing a collection of paths. Use it.
Gregory Szorc - March 8, 2015, 8:16 p.m.
On Sun, Mar 8, 2015 at 12:54 PM, Gregory Szorc <gregory.szorc@gmail.com>
wrote:

> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1423342170 28800
> #      Sat Feb 07 12:49:30 2015 -0800
> # Node ID 57681bad997779da88778ff95254951c89250441
> # Parent  7df546527053a134d03777d89e8c98ec75edaf6f
> commands.paths: use ui.paths to show paths
>
> We now have an API for representing a collection of paths. Use it.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -4825,21 +4825,22 @@ def paths(ui, repo, search=None):
>
>      Returns 0 on success.
>      """
>      if search:
> -        for name, path in ui.configitems("paths"):
> +        for name, path in sorted(ui.paths.iteritems()):
>              if name == search:
> -                ui.status("%s\n" % util.hidepassword(path))
> +                ui.status("%s\n" % util.hidepassword(path.loc))
>                  return
>          if not ui.quiet:
>              ui.warn(_("not found!\n"))
>          return 1
>      else:
> -        for name, path in ui.configitems("paths"):
> +        for name, path in sorted(ui.paths.iteritems()):
>              if ui.quiet:
>                  ui.write("%s\n" % name)
>              else:
> -                ui.write("%s = %s\n" % (name, util.hidepassword(path)))
> +                ui.write("%s = %s\n" % (name,
> +                                        util.hidepassword(path.loc)))
>
>  @command('phase',
>      [('p', 'public', False, _('set changeset phase to public')),
>       ('d', 'draft', False, _('set changeset phase to draft')),
>

For the record, I'm not a huge fan of the sorted() here. I'm half tempted
to throw an __iter__ on paths (like how it was done in v2). v3's paths
inherits from dict, which is why the custom __iter__ went away.
Pierre-Yves David - March 10, 2015, 3:06 a.m.
On 03/08/2015 12:54 PM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1423342170 28800
> #      Sat Feb 07 12:49:30 2015 -0800
> # Node ID 57681bad997779da88778ff95254951c89250441
> # Parent  7df546527053a134d03777d89e8c98ec75edaf6f
> commands.paths: use ui.paths to show paths
>
> We now have an API for representing a collection of paths. Use it.

The first two are pushed to the clowncopter.
Pierre-Yves David - March 10, 2015, 3:06 a.m.
On 03/08/2015 01:16 PM, Gregory Szorc wrote:
> On Sun, Mar 8, 2015 at 12:54 PM, Gregory Szorc <gregory.szorc@gmail.com
> <mailto:gregory.szorc@gmail.com>> wrote:
>
>     # HG changeset patch
>     # User Gregory Szorc <gregory.szorc@gmail.com
>     <mailto:gregory.szorc@gmail.com>>
>     # Date 1423342170 28800
>     #      Sat Feb 07 12:49:30 2015 -0800
>     # Node ID 57681bad997779da88778ff95254951c89250441
>     # Parent  7df546527053a134d03777d89e8c98ec75edaf6f
>     commands.paths: use ui.paths to show paths
>
>     We now have an API for representing a collection of paths. Use it.
>
>     diff --git a/mercurial/commands.py b/mercurial/commands.py
>     --- a/mercurial/commands.py
>     +++ b/mercurial/commands.py
>     @@ -4825,21 +4825,22 @@ def paths(ui, repo, search=None):
>
>           Returns 0 on success.
>           """
>           if search:
>     -        for name, path in ui.configitems("paths"):
>     +        for name, path in sorted(ui.paths.iteritems()):
>                   if name == search:
>     -                ui.status("%s\n" % util.hidepassword(path))
>     +                ui.status("%s\n" % util.hidepassword(path.loc))
>                       return
>               if not ui.quiet:
>                   ui.warn(_("not found!\n"))
>               return 1
>           else:
>     -        for name, path in ui.configitems("paths"):
>     +        for name, path in sorted(ui.paths.iteritems()):
>                   if ui.quiet:
>                       ui.write("%s\n" % name)
>                   else:
>     -                ui.write("%s = %s\n" % (name, util.hidepassword(path)))
>     +                ui.write("%s = %s\n" % (name,
>     +                                        util.hidepassword(path.loc)))
>
>       @command('phase',
>           [('p', 'public', False, _('set changeset phase to public')),
>            ('d', 'draft', False, _('set changeset phase to draft')),
>
>
> For the record, I'm not a huge fan of the sorted() here. I'm half
> tempted to throw an __iter__ on paths (like how it was done in v2). v3's
> paths inherits from dict, which is why the custom __iter__ went away.

Having paths be an ordered dict sounds like a good idea.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4825,21 +4825,22 @@  def paths(ui, repo, search=None):
 
     Returns 0 on success.
     """
     if search:
-        for name, path in ui.configitems("paths"):
+        for name, path in sorted(ui.paths.iteritems()):
             if name == search:
-                ui.status("%s\n" % util.hidepassword(path))
+                ui.status("%s\n" % util.hidepassword(path.loc))
                 return
         if not ui.quiet:
             ui.warn(_("not found!\n"))
         return 1
     else:
-        for name, path in ui.configitems("paths"):
+        for name, path in sorted(ui.paths.iteritems()):
             if ui.quiet:
                 ui.write("%s\n" % name)
             else:
-                ui.write("%s = %s\n" % (name, util.hidepassword(path)))
+                ui.write("%s = %s\n" % (name,
+                                        util.hidepassword(path.loc)))
 
 @command('phase',
     [('p', 'public', False, _('set changeset phase to public')),
      ('d', 'draft', False, _('set changeset phase to draft')),