[PATCH 3 of 3 RFC] vfs: use file API via vfs while ensuring repository store
FUJIWARA Katsunori
foozy at lares.dti.ne.jp
Thu Jun 21 05:47:10 CDT 2012
# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1340275263 -32400
# Node ID 3c0f00eedea890880f8834cb62d227da462a5eae
# Parent 72404f12faa06fdc477324d90c84b854a97c7cc8
vfs: use file API via vfs while ensuring repository store
this patch invokes some file API used to ensure repository store in
constructor of localrepository class via vfs.
"join()" is not defined other than "scmutil.opener" class, because it
should not be used with other opener classes yet.
this patch also replaces referring to "self.opener" while ensuring
repository store by "self.vfs".
"dest" check in "clone()" of "hg.py" is added to treat empty string
("") as invalid destination: such path caused infinite self recursive
call of "util.makedirs()" in cases below, and this was reported as
issue 2528.
$ hg clone bundlefile ''
$ hg clone --pull repo ''
this patch choices adding explicit "dest" check to "clone()" in
"hg.py" because:
- "os.path.realpath()" treats "" as "current working directory" itself, so
- "self.wvfs.exists()" returns True for "", then
- with this patch, localrepository constructor accepts "", but
- "" itself is valid as the path to repo for other than "hg clone", so
- it shouldn't be treated as invalid one in localrepository constructor
diff -r 72404f12faa0 -r 3c0f00eedea8 mercurial/hg.py
--- a/mercurial/hg.py Thu Jun 21 19:41:03 2012 +0900
+++ b/mercurial/hg.py Thu Jun 21 19:41:03 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 72404f12faa0 -r 3c0f00eedea8 mercurial/localrepo.py
--- a/mercurial/localrepo.py Thu Jun 21 19:41:03 2012 +0900
+++ b/mercurial/localrepo.py Thu Jun 21 19:41:03 2012 +0900
@@ -54,21 +54,21 @@
except IOError:
pass
- if not os.path.isdir(self.path):
+ if not self.vfs.isdir():
if create:
- if not os.path.exists(path):
- util.makedirs(path)
- util.makedir(self.path, notindexed=True)
+ if not self.wvfs.exists():
+ self.wvfs.makedirs()
+ self.vfs.makedir(notindexed=True)
requirements = ["revlogv1"]
if self.ui.configbool('format', 'usestore', True):
- os.mkdir(os.path.join(self.path, "store"))
+ self.vfs.mkdir("store")
requirements.append("store")
if self.ui.configbool('format', 'usefncache', True):
requirements.append("fncache")
if self.ui.configbool('format', 'dotencode', True):
requirements.append('dotencode')
# create an invalid changelog
- self.opener.append(
+ self.vfs.append(
"00changelog.i",
'\0\0\0\2' # represents revlogv2
' dummy changelog to prevent using the old repo layout'
@@ -82,7 +82,7 @@
raise error.RepoError(_("repository %s already exists") % path)
else:
try:
- requirements = scmutil.readrequires(self.opener, self.supported)
+ requirements = scmutil.readrequires(self.vfs, self.supported)
except IOError, inst:
if inst.errno != errno.ENOENT:
raise
diff -r 72404f12faa0 -r 3c0f00eedea8 mercurial/scmutil.py
--- a/mercurial/scmutil.py Thu Jun 21 19:41:03 2012 +0900
+++ b/mercurial/scmutil.py Thu Jun 21 19:41:03 2012 +0900
@@ -190,6 +190,21 @@
finally:
fp.close()
+ def mkdir(self, path=None):
+ return os.mkdir(self.join(path))
+
+ def exists(self, path=None):
+ return os.path.exists(self.join(path))
+
+ def isdir(self, path=None):
+ return os.path.isdir(self.join(path))
+
+ def makedir(self, path=None, notindexed=True):
+ return util.makedir(self.join(path), notindexed)
+
+ def makedirs(self, path=None, mode=None):
+ return util.makedirs(self.join(path), mode)
+
class opener(abstractopener):
'''Open files relative to a base directory
@@ -293,7 +308,10 @@
self.auditor(path)
def join(self, path):
- return os.path.join(self.base, path)
+ if path:
+ return os.path.join(self.base, path)
+ else:
+ return self.base
class filteropener(abstractopener):
'''Wrapper opener for filtering filenames with a function.'''
More information about the Mercurial-devel
mailing list