[RFC] file aliases in schemes extension

Alexander Solovyov piranha at piranha.org.ua
Thu Dec 3 08:52:57 CST 2009


Hi all,

it's not possible currently to use such scheme:

w = file:~/dev/web/

because ~ here will be not expanded. I see two ways of fixing that
problem and I can't decide which is better, so I'd like to hear your
opinion on that.

One way is to special-handle "file:" urls in schemes.py:

========================================
diff --git a/hgext/schemes.py b/hgext/schemes.py
--- a/hgext/schemes.py
+++ b/hgext/schemes.py
@@ -40,7 +40,7 @@ same name.
 """
 
 import re
-from mercurial import hg, templater
+from mercurial import hg, templater, util
 
 
 class ShortRepository(object):
@@ -66,6 +66,8 @@ class ShortRepository(object):
             tail = ''
         context = dict((str(i), v) for i, v in enumerate(parts))
         url = ''.join(self.templater.process(self.url, context)) + tail
+        if url.startswith('file:'):
+            url = 'file:' + util.expandpath(url[5:])
         return hg._lookup(url).instance(ui, url, create)
 
 schemes = {
========================================


And another way is to expand paths in localrepo and bundlerepo:

========================================
diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -164,7 +164,7 @@ class bundlerepository(localrepo.localre
             localrepo.localrepository.__init__(self, ui, self._tempparent)
 
         if path:
-            self._url = 'bundle:' + path + '+' + bundlename
+            self._url = 'bundle:' + util.expandpath(path) + '+' + bundlename
         else:
             self._url = 'bundle:' + bundlename
 
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -15,8 +15,8 @@ import verify as _verify
 import errno, os, shutil
 
 def _local(path):
-    return (os.path.isfile(util.drop_scheme('file', path)) and
-            bundlerepo or localrepo)
+    path = util.expandpath(util.drop_scheme('file', path))
+    return (os.path.isfile(path) and bundlerepo or localrepo)
 
 def parseurl(url, revs=[]):
     '''parse url#branch, returning url, branch + revs'''
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -24,7 +24,7 @@ class localrepository(repo.repository):
 
     def __init__(self, baseui, path=None, create=0):
         repo.repository.__init__(self)
-        self.root = os.path.realpath(path)
+        self.root = os.path.realpath(util.expandpath(path))
         self.path = os.path.join(self.root, ".hg")
         self.origroot = path
         self.opener = util.opener(self.path)
========================================


-- 
Alexander


More information about the Mercurial-devel mailing list