changeset 506:1f81ebff98c9

[PATCH] Add ui.expandpath command -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [PATCH] Add ui.expandpath command From: Bryan O'Sullivan <bos@serpentine.com> Add ui.expandpath function. manifest hash: dd2b9e536b94b453b06604b88ba339d93698b2e0 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCwSbMywK+sNU5EO8RAibuAJ9jAMqhR3cbTqbPG3g9M8INgFmbvACgjAU2 LpalLI+zhalEUIf1Uw8W5l8= =fqB8 -----END PGP SIGNATURE-----
author mpm@selenic.com
date Tue, 28 Jun 2005 02:30:36 -0800
parents dc1f735dfaac
children dd8b19114fe7
files mercurial/commands.py mercurial/ui.py
diffstat 2 files changed, 10 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Tue Jun 28 02:22:45 2005 -0800
+++ b/mercurial/commands.py	Tue Jun 28 02:30:36 2005 -0800
@@ -267,11 +267,7 @@
 
 def clone(ui, source, dest = None, **opts):
     """make a copy of an existing repository"""
-    paths = {}
-    for name, path in ui.configitems("paths"):
-        paths[name] = path
-
-    if source in paths: source = paths[source]
+    source = ui.expandpath(source)
 
     created = success = False
 
@@ -549,12 +545,7 @@
 
 def pull(ui, repo, source="default", **opts):
     """pull changes from the specified source"""
-    paths = {}
-    for name, path in ui.configitems("paths"):
-        paths[name] = path
-
-    if source in paths:
-        source = paths[source]
+    source = ui.expandpath(source)
 
     ui.status('pulling from %s\n' % (source))
 
@@ -571,11 +562,7 @@
 
 def push(ui, repo, dest="default-push"):
     """push changes to the specified destination"""
-    paths = {}
-    for name, path in ui.configitems("paths"):
-        paths[name] = path
-
-    if dest in paths: dest = paths[dest]
+    dest = ui.expandpath(dest)
 
     if not dest.startswith("ssh://"):
         ui.warn("abort: can only push to ssh:// destinations currently\n")
--- a/mercurial/ui.py	Tue Jun 28 02:22:45 2005 -0800
+++ b/mercurial/ui.py	Tue Jun 28 02:30:36 2005 -0800
@@ -41,6 +41,13 @@
             return self.cdata.items(section)
         return []
 
+    def expandpath(self, loc):
+        paths = {}
+        for name, path in self.configitems("paths"):
+            paths[name] = path
+
+        return paths.get(loc, loc)
+
     def write(self, *args):
         for a in args:
             sys.stdout.write(str(a))