[PATCH 4 of 6 V2] localrepo: use the path relative to "self.vfs" instead of "path" argument

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Jul 6 04:45:40 CDT 2012


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1341567927 -32400
# Node ID 7d07867c180e4189f27c60c56a05441d25aa4cc7
# Parent  df4490ac1e9a3cd4dca3a347869b45a24b9218b9
localrepo: use the path relative to "self.vfs" instead of "path" argument

As a part of migration to vfs, this patch uses "self.root", which can
be recognized as the path relative to "self.vfs", instead of "path"
argument.

This fix allows to make invocations of "util.makedirs()" and
"os.path.exists()" while ensuring repository directory in
"localrepository.__init__()" ones indirectly via vfs.

But this fix also raises issue 2528: "hg clone" with empty destination.

"path" argument is empty in many cases, so this issue can't be fixed
in the view of "localrepository.__init__()".

Before this patch, it is fixed by empty-ness check ("not name") of
exception handler in "util.makedirs()".

    try:
        os.mkdir(name)
    except OSError, err:
        if err.errno == errno.EEXIST:
            return
        if err.errno != errno.ENOENT or not name:
            raise

This requires "localrepository.__init__()" to invoke "util.makedirs()"
with "path" instead of "self.root", because empty "path" is treated as
"current directory" and "self.root" becomes valid path.

But "hg clone" with empty destination can be detected also in
"hg.clone()" before "localrepository.__init__()" invocation, so this
patch re-fixes issue2528 by checking it in "hg.clone()".

diff -r df4490ac1e9a -r 7d07867c180e mercurial/hg.py
--- a/mercurial/hg.py	Fri Jul 06 18:45:27 2012 +0900
+++ b/mercurial/hg.py	Fri Jul 06 18:45:27 2012 +0900
@@ -263,6 +263,8 @@
     dest = util.urllocalpath(dest)
     source = util.urllocalpath(source)
 
+    if not dest:
+        raise util.Abort(_("empty destination path is not valid"))
     if os.path.exists(dest):
         if not os.path.isdir(dest):
             raise util.Abort(_("destination '%s' already exists") % dest)
diff -r df4490ac1e9a -r 7d07867c180e mercurial/localrepo.py
--- a/mercurial/localrepo.py	Fri Jul 06 18:45:27 2012 +0900
+++ b/mercurial/localrepo.py	Fri Jul 06 18:45:27 2012 +0900
@@ -55,8 +55,8 @@
 
         if not os.path.isdir(self.path):
             if create:
-                if not os.path.exists(path):
-                    util.makedirs(path)
+                if not os.path.exists(self.root):
+                    util.makedirs(self.root)
                 util.makedir(self.path, notindexed=True)
                 requirements = ["revlogv1"]
                 if self.ui.configbool('format', 'usestore', True):
diff -r df4490ac1e9a -r 7d07867c180e tests/test-bundle.t
--- a/tests/test-bundle.t	Fri Jul 06 18:45:27 2012 +0900
+++ b/tests/test-bundle.t	Fri Jul 06 18:45:27 2012 +0900
@@ -420,7 +420,7 @@
 recurse infinitely (issue 2528)
 
   $ hg clone full.hg ''
-  abort: * (glob)
+  abort: empty destination path is not valid
   [255]
 
 test for http://mercurial.selenic.com/bts/issue216
diff -r df4490ac1e9a -r 7d07867c180e tests/test-clone.t
--- a/tests/test-clone.t	Fri Jul 06 18:45:27 2012 +0900
+++ b/tests/test-clone.t	Fri Jul 06 18:45:27 2012 +0900
@@ -43,7 +43,7 @@
 Invalid dest '' must abort:
 
   $ hg clone . ''
-  abort: * (glob)
+  abort: empty destination path is not valid
   [255]
 
 No update, with debug option:
@@ -112,7 +112,7 @@
 Invalid dest '' with --pull must abort (issue2528):
 
   $ hg clone --pull a ''
-  abort: * (glob)
+  abort: empty destination path is not valid
   [255]
 
 Clone to '.':


More information about the Mercurial-devel mailing list