[PATCH 4 of 8 RFC] vfs: replace invocation of file APIs of os.path module by ones via vfs
FUJIWARA Katsunori
foozy at lares.dti.ne.jp
Fri Jun 15 09:45:15 CDT 2012
# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1339768794 -32400
# Node ID 779b9800d898a2ae0a9ba4046d1e6efb350903ed
# Parent 649cab17ed60acdffc1d50a0f6cb2c19ac391f98
vfs: replace invocation of file APIs of os.path module by ones via vfs
this patch replaces invocation of below file APIs of os.path module by
ones via vfs.
- abspath
- exists
- expanduser
- expandvars
- getmtime
- getsize
- isdir
- isfile
- islink
- lexists
- realpath
replacements of this patch are done in steps below:
1. replace all invocations of above functions "os.path.XXXX()" by
"util.vfs().XXXX()" mechanically: or adding "vfs()." in
util.py itself
2. check how many times "vfs()" are invoked in each modified
functions
3. introduce "vfs" local var("vfsobj" in util.py itself), and
replace "util.vfs()" invocations by it, if:
- vfs() is invoked more than once in the function,
- vfs() is invoked in the loop, or
- vfs() is invoked in the internal function invoked repeatedly
this patch doesn't replace invocations in i18n.py and lsprof.py to
avoid importing util module in those files.
diff -r 649cab17ed60 -r 779b9800d898 contrib/shrink-revlog.py
--- a/contrib/shrink-revlog.py Fri Jun 15 22:59:53 2012 +0900
+++ b/contrib/shrink-revlog.py Fri Jun 15 22:59:54 2012 +0900
@@ -162,6 +162,7 @@
can determine which works best for your data.
"""
+ vfs = util.vfs()
if not repo.local():
raise util.Abort(_('not a local repository: %s') % repo.root)
@@ -173,7 +174,7 @@
raise util.Abort(_('--revlog option must specify the revlog index '
'file (*.i), not %s') % opts.get('revlog'))
- indexfn = os.path.realpath(fn)
+ indexfn = vfs.realpath(fn)
store = repo.sjoin('')
if not indexfn.startswith(store):
raise util.Abort(_('--revlog option must specify a revlog in %s, '
@@ -185,7 +186,7 @@
except KeyError:
raise util.Abort(_('no such toposort algorithm: %s') % sortname)
- if not os.path.exists(indexfn):
+ if not vfs.exists(indexfn):
raise util.Abort(_('no such file: %s') % indexfn)
if '00changelog' in indexfn:
raise util.Abort(_('shrinking the changelog '
@@ -194,7 +195,6 @@
ui.write(_('shrinking %s\n') % indexfn)
tmpindexfn = util.mktempcopy(indexfn, emptyok=True)
- vfs = util.vfs()
r1 = revlog.revlog(scmutil.opener(vfs.getcwd(), audit=False), indexfn)
r2 = revlog.revlog(scmutil.opener(vfs.getcwd(), audit=False), tmpindexfn)
@@ -202,7 +202,7 @@
oldindexfn = indexfn + '.old'
olddatafn = datafn + '.old'
- if os.path.exists(oldindexfn) or os.path.exists(olddatafn):
+ if vfs.exists(oldindexfn) or vfs.exists(olddatafn):
raise util.Abort(_('one or both of\n'
' %s\n'
' %s\n'
diff -r 649cab17ed60 -r 779b9800d898 hgext/churn.py
--- a/hgext/churn.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/churn.py Fri Jun 15 22:59:54 2012 +0900
@@ -10,7 +10,6 @@
from mercurial.i18n import _
from mercurial import patch, cmdutil, scmutil, util, templater, commands
-import os
import time, datetime
testedwith = 'internal'
@@ -127,7 +126,7 @@
amap = {}
aliases = opts.get('aliases')
- if not aliases and os.path.exists(repo.wjoin('.hgchurn')):
+ if not aliases and util.vfs().exists(repo.wjoin('.hgchurn')):
aliases = repo.wjoin('.hgchurn')
if aliases:
for l in open(aliases, "r"):
diff -r 649cab17ed60 -r 779b9800d898 hgext/convert/bzr.py
--- a/hgext/convert/bzr.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/convert/bzr.py Fri Jun 15 22:59:54 2012 +0900
@@ -36,7 +36,8 @@
def __init__(self, ui, path, rev=None):
super(bzr_source, self).__init__(ui, path, rev=rev)
- if not os.path.exists(os.path.join(path, '.bzr')):
+ vfs = util.vfs()
+ if not vfs.exists(os.path.join(path, '.bzr')):
raise NoRepo(_('%s does not look like a Bazaar repository')
% path)
@@ -46,7 +47,7 @@
except NameError:
raise NoRepo(_('Bazaar modules could not be loaded'))
- path = os.path.abspath(path)
+ path = vfs.abspath(path)
self._checkrepotype(path)
try:
self.sourcerepo = bzrdir.BzrDir.open(path).open_repository()
diff -r 649cab17ed60 -r 779b9800d898 hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/convert/convcmd.py Fri Jun 15 22:59:54 2012 +0900
@@ -111,7 +111,7 @@
# Read first the dst author map if any
authorfile = self.dest.authorfile()
- if authorfile and os.path.exists(authorfile):
+ if authorfile and util.vfs().exists(authorfile):
self.readauthormap(authorfile)
# Extend/Override with new author map if necessary
if opts.get('authormap'):
diff -r 649cab17ed60 -r 779b9800d898 hgext/convert/cvs.py
--- a/hgext/convert/cvs.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/convert/cvs.py Fri Jun 15 22:59:54 2012 +0900
@@ -18,7 +18,7 @@
super(convert_cvs, self).__init__(ui, path, rev=rev)
cvs = os.path.join(path, "CVS")
- if not os.path.exists(cvs):
+ if not util.vfs().exists(cvs):
raise NoRepo(_("%s does not look like a CVS checkout") % path)
checktool('cvs')
@@ -98,6 +98,7 @@
cmd = ['cvs', 'server']
self.ui.status(_("connecting to %s\n") % root)
+ vfs = util.vfs()
if root.startswith(":pserver:"):
root = root[9:]
@@ -117,7 +118,7 @@
if not passw:
passw = "A"
- cvspass = os.path.expanduser("~/.cvspass")
+ cvspass = vfs.expanduser("~/.cvspass")
try:
pf = open(cvspass)
for line in pf.read().splitlines():
@@ -159,7 +160,7 @@
root = root[5:]
m = re.match(r'(?:([^@:/]+)@)?([^:/]+):?(.*)', root)
# Do not take Windows path "c:\foo\bar" for a connection strings
- if os.path.isdir(root) or not m:
+ if vfs.isdir(root) or not m:
conntype = "local"
else:
conntype = "rsh"
diff -r 649cab17ed60 -r 779b9800d898 hgext/convert/cvsps.py
--- a/hgext/convert/cvsps.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/convert/cvsps.py Fri Jun 15 22:59:54 2012 +0900
@@ -147,11 +147,12 @@
# read log cache if one exists
oldlog = []
date = None
+ vfs = util.vfs()
if cache:
- cachedir = os.path.expanduser('~/.hg.cvsps')
- if not os.path.exists(cachedir):
- util.vfs().mkdir(cachedir)
+ cachedir = vfs.expanduser('~/.hg.cvsps')
+ if not vfs.exists(cachedir):
+ vfs.mkdir(cachedir)
# The cvsps cache pickle needs a uniquified name, based on the
# repository location. The address may have all sort of nasties
diff -r 649cab17ed60 -r 779b9800d898 hgext/convert/darcs.py
--- a/hgext/convert/darcs.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/convert/darcs.py Fri Jun 15 22:59:54 2012 +0900
@@ -30,10 +30,11 @@
def __init__(self, ui, path, rev=None):
converter_source.__init__(self, ui, path, rev=rev)
commandline.__init__(self, ui, 'darcs')
+ vfs = util.vfs()
# check for _darcs, ElementTree so that we can easily skip
# test-convert-darcs if ElementTree is not around
- if not os.path.exists(os.path.join(path, '_darcs')):
+ if not vfs.exists(os.path.join(path, '_darcs')):
raise NoRepo(_("%s does not look like a darcs repository") % path)
checktool('darcs')
@@ -45,7 +46,7 @@
if "ElementTree" not in globals():
raise util.Abort(_("Python ElementTree module is not available"))
- self.path = os.path.realpath(path)
+ self.path = vfs.realpath(path)
self.lastrev = None
self.changes = {}
diff -r 649cab17ed60 -r 779b9800d898 hgext/convert/git.py
--- a/hgext/convert/git.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/convert/git.py Fri Jun 15 22:59:54 2012 +0900
@@ -47,9 +47,10 @@
def __init__(self, ui, path, rev=None):
super(convert_git, self).__init__(ui, path, rev=rev)
- if os.path.isdir(path + "/.git"):
+ vfs = util.vfs()
+ if vfs.isdir(path + "/.git"):
path += "/.git"
- if not os.path.exists(path + "/objects"):
+ if not vfs.exists(path + "/objects"):
raise NoRepo(_("%s does not look like a Git repository") % path)
checktool('git', 'git')
diff -r 649cab17ed60 -r 779b9800d898 hgext/convert/gnuarch.py
--- a/hgext/convert/gnuarch.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/convert/gnuarch.py Fri Jun 15 22:59:54 2012 +0900
@@ -30,7 +30,8 @@
def __init__(self, ui, path, rev=None):
super(gnuarch_source, self).__init__(ui, path, rev=rev)
- if not os.path.exists(os.path.join(path, '{arch}')):
+ vfs = util.vfs()
+ if not vfs.exists(os.path.join(path, '{arch}')):
raise NoRepo(_("%s does not look like a GNU Arch repository")
% path)
@@ -46,7 +47,7 @@
commandline.__init__(self, ui, self.execmd)
- self.path = os.path.realpath(path)
+ self.path = vfs.realpath(path)
self.tmppath = None
self.treeversion = None
@@ -138,7 +139,7 @@
raise util.Abort(_('internal calling inconsistency'))
# Raise IOError if necessary (i.e. deleted files).
- if not os.path.lexists(os.path.join(self.tmppath, name)):
+ if not util.vfs().lexists(os.path.join(self.tmppath, name)):
raise IOError
return self._getfile(name, rev)
@@ -232,7 +233,7 @@
# os.walk could be used, but here we avoid internal GNU
# Arch files and directories, thus saving a lot time.
if not self._exclude(p):
- if os.path.isdir(p):
+ if vfs.isdir(p):
contents += [os.path.join(c, f) for f in vfs.listdir(p)]
else:
files.append(c)
diff -r 649cab17ed60 -r 779b9800d898 hgext/convert/hg.py
--- a/hgext/convert/hg.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/convert/hg.py Fri Jun 15 22:59:54 2012 +0900
@@ -32,7 +32,8 @@
self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False)
self.tagsbranch = ui.config('convert', 'hg.tagsbranch', 'default')
self.lastbranch = None
- if os.path.isdir(path) and len(util.vfs().listdir(path)) > 0:
+ vfs = util.vfs()
+ if vfs.isdir(path) and len(vfs.listdir(path)) > 0:
try:
self.repo = hg.repository(self.ui, path)
if not self.repo.local():
diff -r 649cab17ed60 -r 779b9800d898 hgext/convert/monotone.py
--- a/hgext/convert/monotone.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/convert/monotone.py Fri Jun 15 22:59:54 2012 +0900
@@ -24,7 +24,7 @@
norepo = NoRepo(_("%s does not look like a monotone repository")
% path)
- if not os.path.exists(os.path.join(path, '_MTN')):
+ if not util.vfs().exists(os.path.join(path, '_MTN')):
# Could be a monotone repository (SQLite db file)
try:
f = file(path, 'rb')
diff -r 649cab17ed60 -r 779b9800d898 hgext/convert/subversion.py
--- a/hgext/convert/subversion.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/convert/subversion.py Fri Jun 15 22:59:54 2012 +0900
@@ -63,8 +63,9 @@
except SubversionException:
# svn.client.url_from_path() fails with local repositories
pass
- if os.path.isdir(path):
- path = os.path.normpath(os.path.abspath(path))
+ vfs = util.vfs()
+ if vfs.isdir(path):
+ path = os.path.normpath(vfs.abspath(path))
if os.name == 'nt':
path = '/' + util.normpath(path)
# Module URL is later compared with the repository URL returned
@@ -156,7 +157,7 @@
# directory.
def filecheck(ui, path, proto):
for x in ('locks', 'hooks', 'format', 'db'):
- if not os.path.exists(os.path.join(path, x)):
+ if not util.vfs().exists(os.path.join(path, x)):
return False
return True
@@ -192,7 +193,7 @@
path = urllib.url2pathname(path)
except ValueError:
proto = 'file'
- path = os.path.abspath(url)
+ path = util.vfs().abspath(url)
if proto == 'file':
path = util.pconvert(path)
check = protomap.get(proto, lambda *args: False)
@@ -220,9 +221,10 @@
def __init__(self, ui, url, rev=None):
super(svn_source, self).__init__(ui, url, rev=rev)
+ vfs = util.vfs()
if not (url.startswith('svn://') or url.startswith('svn+ssh://') or
- (os.path.exists(url) and
- os.path.exists(os.path.join(url, '.svn'))) or
+ (vfs.exists(url) and
+ vfs.exists(os.path.join(url, '.svn'))) or
issvnurl(ui, url)):
raise NoRepo(_("%s does not look like a Subversion repository")
% url)
@@ -298,7 +300,7 @@
self._changescache = None
- if os.path.exists(os.path.join(url, '.svn/entries')):
+ if vfs.exists(os.path.join(url, '.svn/entries')):
self.wc = url
else:
self.wc = None
@@ -1014,18 +1016,18 @@
vfs = util.vfs()
self.cwd = vfs.getcwd()
- path = os.path.realpath(path)
+ path = vfs.realpath(path)
created = False
- if os.path.isfile(os.path.join(path, '.svn', 'entries')):
+ if vfs.isfile(os.path.join(path, '.svn', 'entries')):
self.wc = path
self.run0('update')
else:
wcpath = os.path.join(vfs.getcwd(),
os.path.basename(path) + '-wc')
- if os.path.isdir(os.path.dirname(path)):
- if not os.path.exists(os.path.join(path, 'db', 'fs-type')):
+ if vfs.isdir(os.path.dirname(path)):
+ if not vfs.exists(os.path.join(path, 'db', 'fs-type')):
ui.status(_('initializing svn repository %r\n') %
os.path.basename(path))
commandline(ui, 'svnadmin').run0('create', path)
@@ -1085,9 +1087,10 @@
if 'l' in flags:
self.wopener.symlink(data, filename)
else:
+ vfs = util.vfs()
try:
- if os.path.islink(self.wjoin(filename)):
- util.vfs().unlink(filename)
+ if vfs.islink(self.wjoin(filename)):
+ vfs.unlink(filename)
except OSError:
pass
self.wopener.write(filename, data)
@@ -1114,7 +1117,7 @@
# already occurred. Cross the semantic gap.
vfs = util.vfs()
wdest = self.wjoin(dest)
- exists = os.path.lexists(wdest)
+ exists = vfs.lexists(wdest)
if exists:
fd, tempname = tempfile.mkstemp(
prefix='hg-copy-', dir=os.path.dirname(wdest))
@@ -1134,8 +1137,9 @@
def dirs_of(self, files):
dirs = set()
+ vfs = util.vfs()
for f in files:
- if os.path.isdir(self.wjoin(f)):
+ if vfs.isdir(self.wjoin(f)):
dirs.add(f)
for i in strutil.rfindall(f, '/'):
dirs.add(f[:i])
diff -r 649cab17ed60 -r 779b9800d898 hgext/eol.py
--- a/hgext/eol.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/eol.py Fri Jun 15 22:59:54 2012 +0900
@@ -296,13 +296,14 @@
self._eolfile = util.never
return
+ vfs = util.vfs()
try:
- cachemtime = os.path.getmtime(self.join("eol.cache"))
+ cachemtime = vfs.getmtime(self.join("eol.cache"))
except OSError:
cachemtime = 0
try:
- eolmtime = os.path.getmtime(self.wjoin(".hgeol"))
+ eolmtime = vfs.getmtime(self.wjoin(".hgeol"))
except OSError:
eolmtime = 0
diff -r 649cab17ed60 -r 779b9800d898 hgext/extdiff.py
--- a/hgext/extdiff.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/extdiff.py Fri Jun 15 22:59:54 2012 +0900
@@ -153,6 +153,7 @@
return 0
tmproot = tempfile.mkdtemp(prefix='extdiff.')
+ vfs = util.vfs()
try:
# Always make a copy of node1a (and node1b, if applicable)
dir1a_files = mod_a | rem_a | ((mod_b | add_b) - add_a)
@@ -195,12 +196,12 @@
common_file = util.localpath(common.pop())
dir1a = os.path.join(tmproot, dir1a, common_file)
label1a = common_file + rev1a
- if not os.path.isfile(dir1a):
+ if not vfs.isfile(dir1a):
dir1a = os.devnull
if do3way:
dir1b = os.path.join(tmproot, dir1b, common_file)
label1b = common_file + rev1b
- if not os.path.isfile(dir1b):
+ if not vfs.isfile(dir1b):
dir1b = os.devnull
dir2 = os.path.join(dir2root, dir2, common_file)
label2 = common_file + rev2
@@ -228,7 +229,6 @@
ui.debug('running %r in %s\n' % (cmdline, tmproot))
util.system(cmdline, cwd=tmproot, out=ui.fout)
- vfs = util.vfs()
for copy_fn, working_fn, mtime in fns_and_mtime:
if vfs.lstat(copy_fn).st_mtime != mtime:
ui.debug('file changed while diffing. '
diff -r 649cab17ed60 -r 779b9800d898 hgext/inotify/server.py
--- a/hgext/inotify/server.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/inotify/server.py Fri Jun 15 22:59:54 2012 +0900
@@ -335,8 +335,8 @@
self.realsockpath = self.sockpath
vfs = util.vfs()
- if os.path.islink(self.sockpath):
- if os.path.exists(self.sockpath):
+ if vfs.islink(self.sockpath):
+ if vfs.exists(self.sockpath):
self.realsockpath = vfs.readlink(self.sockpath)
else:
raise util.Abort('inotify-server: cannot start: '
diff -r 649cab17ed60 -r 779b9800d898 hgext/keyword.py
--- a/hgext/keyword.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/keyword.py Fri Jun 15 22:59:54 2012 +0900
@@ -86,7 +86,7 @@
from mercurial import scmutil
from mercurial.hgweb import webcommands
from mercurial.i18n import _
-import os, re, shutil, tempfile
+import re, shutil, tempfile
commands.optionalrepo += ' kwdemo'
@@ -657,6 +657,7 @@
return
wctx = repo[None]
cwd = repo.getcwd()
+ vfs = util.vfs()
def haskwsource(dest):
'''Returns true if dest is a regular file and configured for
@@ -665,7 +666,7 @@
source = repo.dirstate.copied(dest)
if 'l' in wctx.flags(source):
source = scmutil.canonpath(repo.root, cwd,
- os.path.realpath(source))
+ vfs.realpath(source))
return kwt.match(source)
candidates = [f for f in repo.dirstate.copies() if
diff -r 649cab17ed60 -r 779b9800d898 hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/largefiles/lfcommands.py Fri Jun 15 22:59:54 2012 +0900
@@ -89,12 +89,12 @@
lfiles, normalfiles, matcher, size, lfiletohash)
ui.progress(_('converting revisions'), None)
- if os.path.exists(rdst.wjoin(lfutil.shortname)):
+ vfs = util.vfs()
+ if vfs.exists(rdst.wjoin(lfutil.shortname)):
shutil.rmtree(rdst.wjoin(lfutil.shortname))
- vfs = util.vfs()
for f in lfiletohash.keys():
- if os.path.isfile(rdst.wjoin(f)):
+ if vfs.isfile(rdst.wjoin(f)):
vfs.unlink(rdst.wjoin(f))
try:
vfs.removedirs(os.path.dirname(rdst.wjoin(f)))
@@ -382,6 +382,7 @@
if filelist:
lfiles = set(lfiles) & set(filelist)
toget = []
+ vfs = util.vfs()
for lfile in lfiles:
# If we are mid-merge, then we have to trust the standin that is in the
@@ -389,7 +390,7 @@
# original hg.merge() already updated the standin as part of the normal
# merge process -- we just have to udpate the largefile to match.
if (getattr(repo, "_ismerging", False) and
- os.path.exists(repo.wjoin(lfutil.standin(lfile)))):
+ vfs.exists(repo.wjoin(lfutil.standin(lfile)))):
expectedhash = lfutil.readstandin(repo, lfile)
else:
expectedhash = repo[node][lfutil.standin(lfile)].data().strip()
@@ -397,7 +398,7 @@
# if it exists and its hash matches, it might have been locally
# modified before updating and the user chose 'local'. in this case,
# it will not be in any store, so don't look for it.
- if ((not os.path.exists(repo.wjoin(lfile)) or
+ if ((not vfs.exists(repo.wjoin(lfile)) or
expectedhash != lfutil.hashfile(repo.wjoin(lfile))) and
not lfutil.findfile(repo, expectedhash)):
toget.append((lfile, expectedhash))
@@ -469,12 +470,12 @@
abslfile = repo.wjoin(lfile)
absstandin = repo.wjoin(lfutil.standin(lfile))
vfs = util.vfs()
- if os.path.exists(absstandin):
- if os.path.exists(absstandin+'.orig'):
+ if vfs.exists(absstandin):
+ if vfs.exists(absstandin+'.orig'):
shutil.copyfile(abslfile, abslfile+'.orig')
expecthash = lfutil.readstandin(repo, lfile)
if (expecthash != '' and
- (not os.path.exists(abslfile) or
+ (not vfs.exists(abslfile) or
expecthash != lfutil.hashfile(abslfile))):
if not lfutil.copyfromcache(repo, expecthash, lfile):
# use normallookup() to allocate entry in largefiles dirstate,
@@ -492,7 +493,7 @@
# lfile is added to the repository again. This happens when a
# largefile is converted back to a normal file: the standin
# disappears, but a new (normal) file appears as the lfile.
- if os.path.exists(abslfile) and lfile not in repo[None]:
+ if vfs.exists(abslfile) and lfile not in repo[None]:
util.unlinkpath(abslfile)
ret = -1
state = repo.dirstate[lfutil.standin(lfile)]
diff -r 649cab17ed60 -r 779b9800d898 hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/largefiles/lfutil.py Fri Jun 15 22:59:54 2012 +0900
@@ -111,7 +111,7 @@
def inusercache(ui, hash):
path = usercachepath(ui, hash)
- return path and os.path.exists(path)
+ return path and util.vfs().exists(path)
def findfile(repo, hash):
if instore(repo, hash):
@@ -154,7 +154,7 @@
# If the largefiles dirstate does not exist, populate and create
# it. This ensures that we create it on the first meaningful
# largefiles operation in a new clone.
- if not os.path.exists(os.path.join(admin, 'dirstate')):
+ if not util.vfs().exists(os.path.join(admin, 'dirstate')):
util.makedirs(admin)
matcher = getstandinmatcher(repo)
for standin in dirstatewalk(repo.dirstate, matcher):
@@ -195,7 +195,7 @@
if rev is not None or repo.dirstate[f] != '?']
def instore(repo, hash):
- return os.path.exists(storepath(repo, hash))
+ return util.vfs().exists(storepath(repo, hash))
def storepath(repo, hash):
return repo.join(os.path.join(longname, hash))
@@ -260,7 +260,7 @@
# work relative to the repository root in this case
cwd = ''
pats = [os.path.join(standindir, cwd, pat) for pat in pats]
- elif os.path.isdir(standindir):
+ elif util.vfs().isdir(standindir):
# no patterns: relative to repo root
pats = [standindir]
else:
@@ -321,7 +321,7 @@
def updatestandin(repo, standin):
file = repo.wjoin(splitstandin(standin))
- if os.path.exists(file):
+ if util.vfs().exists(file):
hash = hashfile(file)
executable = getexecutable(file)
writestandin(repo, standin, hash, executable)
@@ -355,7 +355,7 @@
return hashfile(repo.wjoin(file))
def hashfile(file):
- if not os.path.exists(file):
+ if not util.vfs().exists(file):
return ''
hasher = util.sha1('')
fd = open(file, 'rb')
diff -r 649cab17ed60 -r 779b9800d898 hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/largefiles/overrides.py Fri Jun 15 22:59:54 2012 +0900
@@ -154,13 +154,14 @@
wlock = repo.wlock()
try:
lfdirstate = lfutil.openlfdirstate(ui, repo)
+ vfs = util.vfs()
for f in remove:
if not after:
# If this is being called by addremove, notify the user that we
# are removing the file.
if getattr(repo, "_isaddremove", False):
ui.status(_('removing %s\n') % f)
- if os.path.exists(repo.wjoin(f)):
+ if vfs.exists(repo.wjoin(f)):
util.unlinkpath(repo.wjoin(f))
lfdirstate.remove(f)
lfdirstate.write()
@@ -421,8 +422,8 @@
dest = fullpats[-1]
vfs = util.vfs()
- if os.path.isdir(dest):
- if not os.path.isdir(makestandin(dest)):
+ if vfs.isdir(dest):
+ if not vfs.isdir(makestandin(dest)):
vfs.makedirs(makestandin(dest))
# This could copy both lfiles and normal files in one command,
# but we don't want to do that. First replace their matcher to
@@ -494,7 +495,7 @@
if (lfutil.shortname in src and
dest.startswith(repo.wjoin(lfutil.shortname))):
destlfile = dest.replace(lfutil.shortname, '')
- if not opts['force'] and os.path.exists(destlfile):
+ if not opts['force'] and vfs.exists(destlfile):
raise IOError('',
_('destination largefile already exists'))
copiedfiles.append((src, dest))
@@ -512,7 +513,7 @@
srclfile = src.replace(repo.wjoin(lfutil.standin('')), '')
destlfile = dest.replace(repo.wjoin(lfutil.standin('')), '')
destlfiledir = os.path.dirname(destlfile) or '.'
- if not os.path.isdir(destlfiledir):
+ if not vfs.isdir(destlfiledir):
vfs.makedirs(destlfiledir)
if rename:
vfs.rename(repo.wjoin(srclfile), repo.wjoin(destlfile))
@@ -546,6 +547,7 @@
# resulting standins update the largefiles. Then return the standins
# to their proper state
def overriderevert(orig, ui, repo, *pats, **opts):
+# vfs
# Because we put the standins in a bad state (by updating them)
# and then return them to a correct state we need to lock to
# prevent others from changing them in their incorrect state.
@@ -558,7 +560,7 @@
lfutil.updatestandin(repo, lfutil.standin(lfile))
vfs = util.vfs()
for lfile in missing:
- if (os.path.exists(repo.wjoin(lfutil.standin(lfile)))):
+ if (vfs.exists(repo.wjoin(lfutil.standin(lfile)))):
vfs.unlink(repo.wjoin(lfutil.standin(lfile)))
try:
@@ -611,7 +613,7 @@
repo._lfilestoupdate = []
for lfile in modified:
if lfile in lfileslist:
- if os.path.exists(repo.wjoin(lfutil.standin(lfile))) and lfile\
+ if vfs.exists(repo.wjoin(lfutil.standin(lfile))) and lfile\
in repo['.']:
lfutil.writestandin(repo, lfutil.standin(lfile),
repo['.'][lfile].data().strip(),
@@ -891,9 +893,10 @@
forget = sorted(s[0] + s[1] + s[3] + s[6])
forget = [f for f in forget if lfutil.standin(f) in repo[None].manifest()]
+ vfs = util.vfs()
for f in forget:
if lfutil.standin(f) not in repo.dirstate and not \
- os.path.isdir(m.rel(lfutil.standin(f))):
+ vfs.isdir(m.rel(lfutil.standin(f))):
ui.warn(_('not removing %s: file is already untracked\n')
% m.rel(f))
diff -r 649cab17ed60 -r 779b9800d898 hgext/largefiles/reposetup.py
--- a/hgext/largefiles/reposetup.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/largefiles/reposetup.py Fri Jun 15 22:59:54 2012 +0900
@@ -327,22 +327,23 @@
lfiles = lfutil.listlfiles(self)
# this only loops through largefiles that exist (not
# removed/renamed)
+ vfs = util.vfs()
for lfile in lfiles:
if lfile in modifiedfiles:
- if os.path.exists(
+ if vfs.exists(
self.wjoin(lfutil.standin(lfile))):
# this handles the case where a rebase is being
# performed and the working copy is not updated
# yet.
- if os.path.exists(self.wjoin(lfile)):
+ if vfs.exists(self.wjoin(lfile)):
lfutil.updatestandin(self,
lfutil.standin(lfile))
lfdirstate.normal(lfile)
for lfile in lfdirstate:
if lfile in modifiedfiles:
- if (not os.path.exists(repo.wjoin(
+ if (not vfs.exists(repo.wjoin(
lfutil.standin(lfile)))) or \
- (not os.path.exists(repo.wjoin(lfile))):
+ (not vfs.exists(repo.wjoin(lfile))):
lfdirstate.drop(lfile)
result = orig(text=text, user=user, date=date, match=match,
diff -r 649cab17ed60 -r 779b9800d898 hgext/mq.py
--- a/hgext/mq.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/mq.py Fri Jun 15 22:59:54 2012 +0900
@@ -562,18 +562,20 @@
def removeundo(self, repo):
undo = repo.sjoin('undo')
- if not os.path.exists(undo):
+ vfs = util.vfs()
+ if not vfs.exists(undo):
return
try:
- util.vfs().unlink(undo)
+ vfs.unlink(undo)
except OSError, inst:
self.ui.warn(_('error removing undo: %s\n') % str(inst))
def backup(self, repo, files, copy=False):
# backup local changes in --force case
+ vfs = util.vfs()
for f in sorted(files):
absf = repo.wjoin(f)
- if os.path.lexists(absf):
+ if vfs.lexists(absf):
self.ui.note(_('saving current version of %s as %s\n') %
(f, f + '.orig'))
if copy:
@@ -739,6 +741,7 @@
patchdir = self.path
err = 0
n = None
+ vfs = util.vfs()
for patchname in series:
pushable, reason = self.pushable(patchname)
if not pushable:
@@ -786,7 +789,7 @@
removed = []
merged = []
for f in files:
- if os.path.lexists(repo.wjoin(f)):
+ if vfs.lexists(repo.wjoin(f)):
merged.append(f)
else:
removed.append(f)
@@ -975,8 +978,9 @@
def checkpatchname(self, name, force=False):
self.checkreservedname(name)
- if not force and os.path.exists(self.join(name)):
- if os.path.isdir(self.join(name)):
+ vfs = util.vfs()
+ if not force and vfs.exists(self.join(name)):
+ if vfs.isdir(self.join(name)):
raise util.Abort(_('"%s" already exists as a directory')
% name)
else:
@@ -1144,7 +1148,7 @@
if patch in self.series:
return patch
- if not os.path.isfile(self.join(patch)):
+ if not util.vfs().isfile(self.join(patch)):
try:
sno = int(patch)
except (ValueError, OverflowError):
@@ -1659,10 +1663,11 @@
self.removeundo(repo)
def init(self, repo, create=False):
- if not create and os.path.isdir(self.path):
+ vfs = util.vfs()
+ if not create and vfs.isdir(self.path):
raise util.Abort(_("patch queue directory already exists"))
try:
- util.vfs().mkdir(self.path)
+ vfs.mkdir(self.path)
except OSError, inst:
if inst.errno != errno.EEXIST or not create:
raise
@@ -1748,7 +1753,7 @@
ui = self.ui.copy()
ui.setconfig('paths', 'default', '', overlay=False)
ui.setconfig('paths', 'default-push', '', overlay=False)
- if create or os.path.isdir(self.join(".hg")):
+ if create or util.vfs().isdir(self.join(".hg")):
return hg.repository(ui, path=self.path, create=create)
def restore(self, repo, rev, delete=None, qupdate=None):
@@ -1951,6 +1956,7 @@
self.applieddirty = True
self.seriesdirty = True
+ vfs = util.vfs()
for i, filename in enumerate(files):
if existing:
if filename == '-':
@@ -1958,7 +1964,7 @@
filename = normname(filename)
self.checkreservedname(filename)
originpath = self.join(filename)
- if not os.path.isfile(originpath):
+ if not vfs.isfile(originpath):
raise util.Abort(_("patch %s does not exist") % filename)
if patchname:
@@ -2159,8 +2165,9 @@
q = repo.mq
r = q.init(repo, create)
q.savedirty()
+ vfs = util.vfs()
if r:
- if not os.path.exists(r.wjoin('.hgignore')):
+ if not vfs.exists(r.wjoin('.hgignore')):
fp = r.wopener('.hgignore', 'w')
fp.write('^\\.hg\n')
fp.write('^\\.mq\n')
@@ -2168,7 +2175,7 @@
fp.write('status\n')
fp.write('guards\n')
fp.close()
- if not os.path.exists(r.wjoin('series')):
+ if not vfs.exists(r.wjoin('series')):
r.wopener('series', 'w').close()
r[None].add(['.hgignore', 'series'])
commands.add(ui, r)
@@ -2794,7 +2801,8 @@
return
patch = q.lookup('qtip')
absdest = q.join(name)
- if os.path.isdir(absdest):
+ vfs = util.vfs()
+ if vfs.isdir(absdest):
name = normname(os.path.join(name, os.path.basename(patch)))
absdest = q.join(name)
q.checkpatchname(name)
@@ -2812,8 +2820,8 @@
q.applieddirty = True
destdir = os.path.dirname(absdest)
- if not os.path.isdir(destdir):
- util.vfs().makedirs(destdir)
+ if not vfs.isdir(destdir):
+ vfs.makedirs(destdir)
util.rename(q.join(patch), absdest)
r = q.qrepo()
if r and patch in r.dirstate:
@@ -2863,12 +2871,13 @@
if ret:
return ret
q.savedirty() # save to .hg/patches before copying
+ vfs = util.vfs()
if opts.get('copy'):
path = q.path
if opts.get('name'):
newpath = os.path.join(q.basepath, opts.get('name'))
- if os.path.exists(newpath):
- if not os.path.isdir(newpath):
+ if vfs.exists(newpath):
+ if not vfs.isdir(newpath):
raise util.Abort(_('destination %s exists and is not '
'a directory') % newpath)
if not opts.get('force'):
@@ -3299,6 +3308,7 @@
_('invalid queue name, may not contain the characters ":\\/."'))
existing = _getqueues()
+ vfs = util.vfs()
if opts.get('create'):
if name in existing:
@@ -3317,7 +3327,7 @@
olddir = _queuedir(current)
newdir = _queuedir(name)
- if os.path.exists(newdir):
+ if vfs.exists(newdir):
raise util.Abort(_('non-queue directory "%s" already exists') %
newdir)
@@ -3325,7 +3335,7 @@
for queue in existing:
if queue == current:
fh.write('%s\n' % (name,))
- if os.path.exists(olddir):
+ if vfs.exists(olddir):
util.rename(olddir, newdir)
else:
fh.write('%s\n' % (queue,))
@@ -3338,7 +3348,7 @@
if name in existing:
_delete(name)
qdir = _queuedir(name)
- if os.path.exists(qdir):
+ if vfs.exists(qdir):
shutil.rmtree(qdir)
else:
if name not in existing:
diff -r 649cab17ed60 -r 779b9800d898 hgext/rebase.py
--- a/hgext/rebase.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/rebase.py Fri Jun 15 22:59:54 2012 +0900
@@ -333,7 +333,7 @@
clearstatus(repo)
ui.note(_("rebase completed\n"))
- if os.path.exists(repo.sjoin('undo')):
+ if util.vfs().exists(repo.sjoin('undo')):
util.unlinkpath(repo.sjoin('undo'))
if skipped:
ui.note(_("%d revisions have been skipped\n") % len(skipped))
@@ -518,7 +518,7 @@
def clearstatus(repo):
'Remove the status files'
- if os.path.exists(repo.join("rebasestate")):
+ if util.vfs().exists(repo.join("rebasestate")):
util.unlinkpath(repo.join("rebasestate"))
def restorestatus(repo):
diff -r 649cab17ed60 -r 779b9800d898 hgext/schemes.py
--- a/hgext/schemes.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/schemes.py Fri Jun 15 22:59:54 2012 +0900
@@ -91,9 +91,10 @@
def extsetup(ui):
schemes.update(dict(ui.configitems('schemes')))
t = templater.engine(lambda x: x)
+ vfs = util.vfs()
for scheme, url in schemes.items():
if (os.name == 'nt' and len(scheme) == 1 and scheme.isalpha()
- and os.path.exists('%s:\\' % scheme)):
+ and vfs.exists('%s:\\' % scheme)):
raise util.Abort(_('custom scheme %s:// conflicts with drive '
'letter %s:\\\n') % (scheme, scheme.upper()))
hg.schemes[scheme] = ShortRepository(url, scheme, t)
diff -r 649cab17ed60 -r 779b9800d898 hgext/transplant.py
--- a/hgext/transplant.py Fri Jun 15 22:59:53 2012 +0900
+++ b/hgext/transplant.py Fri Jun 15 22:59:54 2012 +0900
@@ -46,7 +46,7 @@
def read(self):
abspath = os.path.join(self.path, self.transplantfile)
- if self.transplantfile and os.path.exists(abspath):
+ if self.transplantfile and util.vfs().exists(abspath):
for line in self.opener.read(self.transplantfile).splitlines():
lnode, rnode = map(revlog.bin, line.split(':'))
list = self.transplants.setdefault(rnode, [])
@@ -54,8 +54,9 @@
def write(self):
if self.dirty and self.transplantfile:
- if not os.path.isdir(self.path):
- util.vfs().mkdir(self.path)
+ vfs = util.vfs()
+ if not vfs.isdir(self.path):
+ vfs.mkdir(self.path)
fp = self.opener(self.transplantfile, 'w')
for list in self.transplants.itervalues():
for t in list:
@@ -264,8 +265,9 @@
return None
except Exception, inst:
seriespath = os.path.join(self.path, 'series')
- if os.path.exists(seriespath):
- util.vfs().unlink(seriespath)
+ vfs = util.vfs()
+ if vfs.exists(seriespath):
+ vfs.unlink(seriespath)
p1 = repo.dirstate.p1()
p2 = node
self.log(user, date, message, p1, p2, merge=merge)
@@ -299,19 +301,20 @@
def resume(self, repo, source, opts=None):
'''recover last transaction and apply remaining changesets'''
- if os.path.exists(os.path.join(self.path, 'journal')):
+ vfs = util.vfs()
+ if vfs.exists(os.path.join(self.path, 'journal')):
n, node = self.recover(repo)
self.ui.status(_('%s transplanted as %s\n') % (short(node),
short(n)))
seriespath = os.path.join(self.path, 'series')
- if not os.path.exists(seriespath):
+ if not vfs.exists(seriespath):
self.transplants.write()
return
nodes, merges = self.readseries()
revmap = {}
for n in nodes:
revmap[source.changelog.rev(n)] = n
- util.vfs().unlink(seriespath)
+ vfs.unlink(seriespath)
self.apply(repo, source, revmap, merges, opts)
@@ -371,8 +374,9 @@
if not revmap:
return
- if not os.path.isdir(self.path):
- util.vfs().mkdir(self.path)
+ vfs = util.vfs()
+ if not vfs.isdir(self.path):
+ vfs.mkdir(self.path)
series = self.opener('series', 'w')
for rev in sorted(revmap):
series.write(revlog.hex(revmap[rev]) + '\n')
@@ -410,8 +414,9 @@
def log(self, user, date, message, p1, p2, merge=False):
'''journal changelog metadata for later recover'''
- if not os.path.isdir(self.path):
- util.vfs().mkdir(self.path)
+ vfs = util.vfs()
+ if not vfs.isdir(self.path):
+ vfs.mkdir(self.path)
fp = self.opener('journal', 'w')
fp.write('# User %s\n' % user)
fp.write('# Date %s\n' % date)
@@ -428,8 +433,9 @@
def unlog(self):
'''remove changelog journal'''
absdst = os.path.join(self.path, 'journal')
- if os.path.exists(absdst):
- util.vfs().unlink(absdst)
+ vfs = util.vfs()
+ if vfs.exists(absdst):
+ vfs.unlink(absdst)
def transplantfilter(self, repo, source, root):
def matchfn(node):
diff -r 649cab17ed60 -r 779b9800d898 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/cmdutil.py Fri Jun 15 22:59:54 2012 +0900
@@ -69,7 +69,8 @@
raise error.UnknownCommand(cmd)
def findrepo(p):
- while not os.path.isdir(os.path.join(p, ".hg")):
+ vfs = util.vfs()
+ while not vfs.isdir(os.path.join(p, ".hg")):
oldp, p = p, os.path.dirname(p)
if p == oldp:
return None
@@ -223,12 +224,13 @@
filelog = repo.file(file_)
if len(filelog):
r = filelog
+ vfs = util.vfs()
if not r:
if not file_:
raise error.CommandError(cmd, _('invalid arguments'))
- if not os.path.isfile(file_):
+ if not vfs.isfile(file_):
raise util.Abort(_("revlog '%s' not found") % file_)
- r = revlog.revlog(scmutil.opener(util.vfs().getcwd(), audit=False),
+ r = revlog.revlog(scmutil.opener(vfs.getcwd(), audit=False),
file_[:-2] + ".i")
return r
@@ -290,7 +292,7 @@
return
# check for overwrites
- exists = os.path.lexists(target)
+ exists = vfs.lexists(target)
samefile = False
if exists and abssrc != abstarget:
if (repo.dirstate.normalize(abssrc) ==
@@ -321,7 +323,7 @@
if exists:
vfs.unlink(target)
targetdir = os.path.dirname(target) or '.'
- if not os.path.isdir(targetdir):
+ if not vfs.isdir(targetdir):
vfs.makedirs(targetdir)
if samefile:
tmp = target + "~hgrename"
@@ -360,7 +362,7 @@
# srcs: list of (hgsep, hgsep, ossep, bool)
# return: function that takes hgsep and returns ossep
def targetpathfn(pat, dest, srcs):
- if os.path.isdir(pat):
+ if vfs.isdir(pat):
abspfx = scmutil.canonpath(repo.root, cwd, pat)
abspfx = util.localpath(abspfx)
if destdirexists:
@@ -395,7 +397,7 @@
score = 0
for s in srcs:
t = os.path.join(dest, util.localpath(s[0])[striplen:])
- if os.path.lexists(t):
+ if vfs.lexists(t):
score += 1
return score
@@ -403,7 +405,7 @@
striplen = len(abspfx)
if striplen:
striplen += len(os.sep)
- if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])):
+ if vfs.isdir(os.path.join(dest, os.path.split(abspfx)[1])):
score = evalpath(striplen)
striplen1 = len(os.path.split(abspfx)[0])
if striplen1:
@@ -428,7 +430,7 @@
if len(pats) == 1:
raise util.Abort(_('no destination specified'))
dest = pats.pop()
- destdirexists = os.path.isdir(dest) and not os.path.islink(dest)
+ destdirexists = vfs.isdir(dest) and not vfs.islink(dest)
if not destdirexists:
if len(pats) > 1 or matchmod.patkind(pats[0]):
raise util.Abort(_('with multiple sources, destination must be an '
@@ -482,7 +484,7 @@
del runargs[i:i + 2]
break
def condfn():
- return not os.path.exists(lockpath)
+ return not vfs.exists(lockpath)
pid = util.rundetached(runargs, condfn)
if pid < 0:
raise util.Abort(_('child process failed to start'))
@@ -1256,11 +1258,12 @@
ui.status(_("skipping missing subrepository: %s\n")
% join(subpath))
+ vfs = util.vfs()
if not explicitonly:
for f in match.files():
- if f not in repo.dirstate and not os.path.isdir(match.rel(join(f))):
+ if f not in repo.dirstate and not vfs.isdir(match.rel(join(f))):
if f not in forgot:
- if os.path.exists(match.rel(join(f))):
+ if vfs.exists(match.rel(join(f))):
ui.warn(_('not removing %s: '
'file is already untracked\n')
% match.rel(join(f)))
@@ -1543,13 +1546,14 @@
(deleted, revert, remove, False, False),
)
+ vfs = util.vfs()
for abs, (rel, exact) in sorted(names.items()):
mfentry = mf.get(abs)
target = repo.wjoin(abs)
def handle(xlist, dobackup):
xlist[0].append(abs)
if (dobackup and not opts.get('no_backup') and
- os.path.lexists(target)):
+ vfs.lexists(target)):
bakname = "%s.orig" % rel
ui.note(_('saving current version of %s as %s\n') %
(rel, bakname))
diff -r 649cab17ed60 -r 779b9800d898 mercurial/commands.py
--- a/mercurial/commands.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/commands.py Fri Jun 15 22:59:54 2012 +0900
@@ -358,7 +358,7 @@
raise util.Abort(_('no working directory: please specify a revision'))
node = ctx.node()
dest = cmdutil.makefilename(repo, dest, node)
- if os.path.realpath(dest) == repo.root:
+ if util.vfs().realpath(dest) == repo.root:
raise util.Abort(_('repository root cannot be destination'))
kind = opts.get('type') or archival.guesskind(dest) or 'files'
@@ -645,8 +645,9 @@
if reset:
p = repo.join("bisect.state")
- if os.path.exists(p):
- util.vfs().unlink(p)
+ vfs = util.vfs()
+ if vfs.exists(p):
+ vfs.unlink(p)
return
state = hbisect.load_state(repo)
@@ -2789,7 +2790,7 @@
wlock.release()
# remove state when we complete successfully
- if not opts.get('dry_run') and os.path.exists(repo.join('graftstate')):
+ if not opts.get('dry_run') and util.vfs().exists(repo.join('graftstate')):
util.unlinkpath(repo.join('graftstate'))
return 0
@@ -4697,9 +4698,10 @@
s = repo.status(match=m, clean=True)
modified, added, deleted, clean = s[0], s[1], s[3], s[6]
+ vfs = util.vfs()
for f in m.files():
- if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
- if os.path.exists(m.rel(f)):
+ if f not in repo.dirstate and not vfs.isdir(m.rel(f)):
+ if vfs.exists(m.rel(f)):
ui.warn(_('not removing %s: file is untracked\n') % m.rel(f))
ret = 1
diff -r 649cab17ed60 -r 779b9800d898 mercurial/context.py
--- a/mercurial/context.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/context.py Fri Jun 15 22:59:54 2012 +0900
@@ -1040,9 +1040,10 @@
def copy(self, source, dest):
p = self._repo.wjoin(dest)
- if not os.path.lexists(p):
+ vfs = util.vfs()
+ if not vfs.lexists(p):
self._repo.ui.warn(_("%s does not exist!\n") % dest)
- elif not (os.path.isfile(p) or os.path.islink(p)):
+ elif not (vfs.isfile(p) or vfs.islink(p)):
self._repo.ui.warn(_("copy failed: %s is not a file or a "
"symbolic link\n") % dest)
else:
diff -r 649cab17ed60 -r 779b9800d898 mercurial/dirstate.py
--- a/mercurial/dirstate.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/dirstate.py Fri Jun 15 22:59:54 2012 +0900
@@ -153,10 +153,11 @@
return self._rootdir + f
def flagfunc(self, buildfallback):
+ vfs = util.vfs()
if self._checklink and self._checkexec:
def f(x):
p = self._join(x)
- if os.path.islink(p):
+ if vfs.islink(p):
return 'l'
if util.isexec(p):
return 'x'
@@ -166,7 +167,7 @@
fallback = buildfallback()
if self._checklink:
def f(x):
- if os.path.islink(self._join(x)):
+ if vfs.islink(self._join(x)):
return 'l'
if 'x' in fallback(x):
return 'x'
@@ -428,7 +429,7 @@
folded = path
else:
if exists is None:
- exists = os.path.lexists(os.path.join(self._root, path))
+ exists = util.vfs().lexists(os.path.join(self._root, path))
if not exists:
# Maybe a path component exists
if not ignoremissing and '/' in path:
diff -r 649cab17ed60 -r 779b9800d898 mercurial/extensions.py
--- a/mercurial/extensions.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/extensions.py Fri Jun 15 22:59:54 2012 +0900
@@ -36,7 +36,7 @@
def loadpath(path, module_name):
module_name = module_name.replace('.', '_')
path = util.expandpath(path)
- if os.path.isdir(path):
+ if util.vfs().isdir(path):
# module/__init__.py style
d, f = os.path.split(path.rstrip('/'))
fd, fpath, desc = imp.find_module(f, [d])
@@ -192,9 +192,10 @@
'''find paths of disabled extensions. returns a dict of {name: path}
removes /__init__.py from packages if strip_init is True'''
import hgext
- extpath = os.path.dirname(os.path.abspath(hgext.__file__))
+ vfs = util.vfs()
+ extpath = os.path.dirname(vfs.abspath(hgext.__file__))
try: # might not be a filesystem path
- files = util.vfs().listdir(extpath)
+ files = vfs.listdir(extpath)
except OSError:
return {}
@@ -206,7 +207,7 @@
else:
name = e
path = os.path.join(extpath, e, '__init__.py')
- if not os.path.exists(path):
+ if not vfs.exists(path):
continue
if strip_init:
path = os.path.dirname(path)
diff -r 649cab17ed60 -r 779b9800d898 mercurial/hbisect.py
--- a/mercurial/hbisect.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/hbisect.py Fri Jun 15 22:59:54 2012 +0900
@@ -8,7 +8,7 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
-import os, error
+import error
from i18n import _
from node import short, hex
import util
@@ -133,7 +133,7 @@
def load_state(repo):
state = {'current': [], 'good': [], 'bad': [], 'skip': []}
- if os.path.exists(repo.join("bisect.state")):
+ if util.vfs().exists(repo.join("bisect.state")):
for l in repo.opener("bisect.state"):
kind, node = l[:-1].split()
node = repo.lookup(node)
diff -r 649cab17ed60 -r 779b9800d898 mercurial/help.py
--- a/mercurial/help.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/help.py Fri Jun 15 22:59:54 2012 +0900
@@ -124,9 +124,10 @@
module = __file__
base = os.path.dirname(module)
+ vfs = util.vfs()
for dir in ('.', '..'):
docdir = os.path.join(base, dir, 'help')
- if os.path.isdir(docdir):
+ if vfs.isdir(docdir):
break
path = os.path.join(docdir, topic + ".txt")
diff -r 649cab17ed60 -r 779b9800d898 mercurial/hg.py
--- a/mercurial/hg.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/hg.py Fri Jun 15 22:59:54 2012 +0900
@@ -18,7 +18,7 @@
def _local(path):
path = util.expandpath(util.urllocalpath(path))
- return (os.path.isfile(path) and bundlerepo or localrepo)
+ return (util.vfs().isfile(path) and bundlerepo or localrepo)
def addbranchrevs(lrepo, repo, branches, revs):
hashbranch, branches = branches
@@ -130,14 +130,15 @@
sharedpath = srcrepo.sharedpath # if our source is already sharing
- root = os.path.realpath(dest)
+ vfs = util.vfs()
+ root = vfs.realpath(dest)
roothg = os.path.join(root, '.hg')
- if os.path.exists(roothg):
+ if vfs.exists(roothg):
raise util.Abort(_('destination already exists'))
- if not os.path.isdir(root):
- util.vfs().mkdir(root)
+ if not vfs.isdir(root):
+ vfs.mkdir(root)
util.makedir(roothg, notindexed=True)
requirements = ''
@@ -191,9 +192,9 @@
src = os.path.join(srcrepo.sharedpath, f)
dst = os.path.join(destpath, f)
dstbase = os.path.dirname(dst)
- if dstbase and not os.path.exists(dstbase):
+ if dstbase and not vfs.exists(dstbase):
vfs.mkdir(dstbase)
- if os.path.exists(src):
+ if vfs.exists(src):
if dst.endswith('data'):
# lock to avoid premature writing to the target
destlock = lock.lock(os.path.join(dstbase, "lock"))
@@ -265,8 +266,8 @@
dest = util.urllocalpath(dest)
source = util.urllocalpath(source)
- if os.path.exists(dest):
- if not os.path.isdir(dest):
+ if vfs.exists(dest):
+ if not vfs.isdir(dest):
raise util.Abort(_("destination '%s' already exists") % dest)
elif vfs.listdir(dest):
raise util.Abort(_("destination '%s' is not empty") % dest)
@@ -285,7 +286,7 @@
try:
abspath = origsource
if islocal(origsource):
- abspath = os.path.abspath(util.urllocalpath(origsource))
+ abspath = vfs.abspath(util.urllocalpath(origsource))
if islocal(dest):
dircleanup = DirCleanup(dest)
@@ -306,8 +307,8 @@
if copy:
srcrepo.hook('preoutgoing', throw=True, source='clone')
- hgdir = os.path.realpath(os.path.join(dest, ".hg"))
- if not os.path.exists(dest):
+ hgdir = vfs.realpath(os.path.join(dest, ".hg"))
+ if not vfs.exists(dest):
vfs.mkdir(dest)
else:
# only clean up directories we create ourselves
diff -r 649cab17ed60 -r 779b9800d898 mercurial/hgweb/__init__.py
--- a/mercurial/hgweb/__init__.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/hgweb/__init__.py Fri Jun 15 22:59:54 2012 +0900
@@ -6,7 +6,7 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
-import os
+from mercurial import util
import hgweb_mod, hgwebdir_mod
def hgweb(config, name=None, baseui=None):
@@ -20,7 +20,7 @@
- list of virtual:real tuples (multi-repo view)
'''
- if ((isinstance(config, str) and not os.path.isdir(config)) or
+ if ((isinstance(config, str) and not util.vfs().isdir(config)) or
isinstance(config, dict) or isinstance(config, list)):
# create a multi-dir interface
return hgwebdir_mod.hgwebdir(config, baseui=baseui)
diff -r 649cab17ed60 -r 779b9800d898 mercurial/hgweb/common.py
--- a/mercurial/hgweb/common.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/hgweb/common.py Fri Jun 15 22:59:54 2012 +0900
@@ -110,7 +110,7 @@
"""stat changelog if it exists, spath otherwise"""
cl_path = os.path.join(spath, "00changelog.i")
vfs = util.vfs()
- if os.path.exists(cl_path):
+ if vfs.exists(cl_path):
return vfs.stat(cl_path)
else:
return vfs.stat(spath)
@@ -135,14 +135,15 @@
fpath = os.path.join(*parts)
if isinstance(directory, str):
directory = [directory]
+ vfs = util.vfs()
for d in directory:
path = os.path.join(d, fpath)
- if os.path.exists(path):
+ if vfs.exists(path):
break
try:
- util.vfs().stat(path)
+ vfs.stat(path)
ct = mimetypes.guess_type(path)[0] or "text/plain"
- req.respond(HTTP_OK, ct, length = os.path.getsize(path))
+ req.respond(HTTP_OK, ct, length = vfs.getsize(path))
fp = open(path, 'rb')
data = fp.read()
fp.close()
diff -r 649cab17ed60 -r 779b9800d898 mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/hgweb/hgwebdir_mod.py Fri Jun 15 22:59:54 2012 +0900
@@ -21,6 +21,7 @@
def findrepos(paths):
repos = []
+ vfs = util.vfs()
for prefix, root in cleannames(paths):
roothead, roottail = os.path.split(root)
# "foo = /bar/*" makes every subrepo of /bar/ to be
@@ -32,7 +33,7 @@
except KeyError:
repos.append((prefix, root))
continue
- roothead = os.path.normpath(os.path.abspath(roothead))
+ roothead = os.path.normpath(vfs.abspath(roothead))
paths = scmutil.walkrepos(roothead, followsym=True, recurse=recurse)
repos.extend(urlrepos(prefix, roothead, paths))
return repos
@@ -101,7 +102,7 @@
if not isinstance(self.conf, (dict, list, tuple)):
map = {'paths': 'hgweb-paths'}
- if not os.path.exists(self.conf):
+ if not util.vfs().exists(self.conf):
raise util.Abort(_('config file %s not found!') % self.conf)
u.readconfig(self.conf, remap=map, trust=True)
paths = []
diff -r 649cab17ed60 -r 779b9800d898 mercurial/localrepo.py
--- a/mercurial/localrepo.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/localrepo.py Fri Jun 15 22:59:54 2012 +0900
@@ -33,7 +33,8 @@
def __init__(self, baseui, path=None, create=False):
repo.repository.__init__(self)
- self.root = os.path.realpath(util.expandpath(path))
+ vfs = util.vfs()
+ self.root = vfs.realpath(util.expandpath(path))
self.path = os.path.join(self.root, ".hg")
self.origroot = path
self.auditor = scmutil.pathauditor(self.root, self._checknested)
@@ -52,14 +53,14 @@
except IOError:
pass
- if not os.path.isdir(self.path):
+ if not vfs.isdir(self.path):
if create:
- if not os.path.exists(path):
+ if not vfs.exists(path):
util.makedirs(path)
util.makedir(self.path, notindexed=True)
requirements = ["revlogv1"]
if self.ui.configbool('format', 'usestore', True):
- util.vfs().mkdir(os.path.join(self.path, "store"))
+ vfs.mkdir(os.path.join(self.path, "store"))
requirements.append("store")
if self.ui.configbool('format', 'usefncache', True):
requirements.append("fncache")
@@ -88,8 +89,8 @@
self.sharedpath = self.path
try:
- s = os.path.realpath(self.opener.read("sharedpath").rstrip('\n'))
- if not os.path.exists(s):
+ s = vfs.realpath(self.opener.read("sharedpath").rstrip('\n'))
+ if not vfs.exists(s):
raise error.RepoError(
_('.hg/sharedpath points to nonexistent directory %s') % s)
self.sharedpath = s
@@ -664,7 +665,7 @@
return self.wopener(f, mode)
def _link(self, f):
- return os.path.islink(self.wjoin(f))
+ return util.vfs().islink(self.wjoin(f))
def _loadfilter(self, filter):
if filter not in self.filterpats:
@@ -735,7 +736,7 @@
return tr.nest()
# abort here if the journal already exists
- if os.path.exists(self.sjoin("journal")):
+ if util.vfs().exists(self.sjoin("journal")):
raise error.RepoError(
_("abandoned transaction found - run hg recover"))
@@ -773,7 +774,7 @@
def recover(self):
lock = self.lock()
try:
- if os.path.exists(self.sjoin("journal")):
+ if util.vfs().exists(self.sjoin("journal")):
self.ui.status(_("rolling back interrupted transaction\n"))
transaction.rollback(self.sopener, self.sjoin("journal"),
self.ui.warn)
@@ -790,7 +791,7 @@
try:
wlock = self.wlock()
lock = self.lock()
- if os.path.exists(self.sjoin("undo")):
+ if util.vfs().exists(self.sjoin("undo")):
return self._rollback(dryrun, force)
else:
self.ui.warn(_("no rollback information available\n"))
@@ -830,10 +831,11 @@
parents = self.dirstate.parents()
transaction.rollback(self.sopener, self.sjoin('undo'), ui.warn)
- if os.path.exists(self.join('undo.bookmarks')):
+ vfs = util.vfs()
+ if vfs.exists(self.join('undo.bookmarks')):
util.rename(self.join('undo.bookmarks'),
self.join('bookmarks'))
- if os.path.exists(self.sjoin('undo.phaseroots')):
+ if vfs.exists(self.sjoin('undo.phaseroots')):
util.rename(self.sjoin('undo.phaseroots'),
self.sjoin('phaseroots'))
self.invalidate()
diff -r 649cab17ed60 -r 779b9800d898 mercurial/merge.py
--- a/mercurial/merge.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/merge.py Fri Jun 15 22:59:54 2012 +0900
@@ -8,7 +8,7 @@
from node import nullid, nullrev, hex, bin
from i18n import _
import error, scmutil, util, filemerge, copies, subrepo
-import errno, os, shutil
+import errno, shutil
class mergestate(object):
'''track 3-way merge state of individual files'''
@@ -83,7 +83,7 @@
def _checkunknownfile(repo, wctx, mctx, f):
return (not repo.dirstate._ignore(f)
- and os.path.isfile(repo.wjoin(f))
+ and util.vfs().isfile(repo.wjoin(f))
and repo.dirstate.normalize(f) not in repo.dirstate
and mctx[f].cmp(wctx[f]))
@@ -340,7 +340,7 @@
# remove renamed files after safely stored
for f in moves:
- if os.path.lexists(repo.wjoin(f)):
+ if vfs.lexists(repo.wjoin(f)):
repo.ui.debug("removing %s\n" % f)
audit(f)
vfs.unlink(repo.wjoin(f))
@@ -380,7 +380,7 @@
else:
merged += 1
if (move and repo.dirstate.normalize(fd) != f
- and os.path.lexists(repo.wjoin(f))):
+ and vfs.lexists(repo.wjoin(f))):
repo.ui.debug("removing %s\n" % f)
audit(f)
vfs.unlink(repo.wjoin(f))
diff -r 649cab17ed60 -r 779b9800d898 mercurial/patch.py
--- a/mercurial/patch.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/patch.py Fri Jun 15 22:59:54 2012 +0900
@@ -418,7 +418,7 @@
def getfile(self, fname):
path = self._join(fname)
vfs = util.vfs()
- if os.path.islink(path):
+ if vfs.islink(path):
return (vfs.readlink(path), (True, False))
isexec = False
try:
@@ -457,7 +457,7 @@
fp.close()
def exists(self, fname):
- return os.path.lexists(self._join(fname))
+ return util.vfs().lexists(self._join(fname))
class workingbackend(fsbackend):
def __init__(self, ui, repo, similarity):
diff -r 649cab17ed60 -r 779b9800d898 mercurial/repair.py
--- a/mercurial/repair.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/repair.py Fri Jun 15 22:59:54 2012 +0900
@@ -16,8 +16,9 @@
"""create a bundle with the specified revisions as a backup"""
cg = repo.changegroupsubset(bases, heads, 'strip')
backupdir = repo.join("strip-backup")
- if not os.path.isdir(backupdir):
- util.vfs().mkdir(backupdir)
+ vfs = util.vfs()
+ if not vfs.isdir(backupdir):
+ vfs.mkdir(backupdir)
name = os.path.join(backupdir, "%s-%s.hg" % (short(node), suffix))
if compress:
bundletype = "HG10BZ"
diff -r 649cab17ed60 -r 779b9800d898 mercurial/scmutil.py
--- a/mercurial/scmutil.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/scmutil.py Fri Jun 15 22:59:54 2012 +0900
@@ -84,7 +84,7 @@
self.auditeddir = set()
self.root = root
self.callback = callback
- if os.path.lexists(root) and not util.checkcase(root):
+ if util.vfs().lexists(root) and not util.checkcase(root):
self.normcase = util.normcase
else:
self.normcase = lambda x: x
@@ -140,7 +140,7 @@
_('path %r traverses symbolic link %r')
% (path, prefix))
elif (stat.S_ISDIR(st.st_mode) and
- os.path.isdir(os.path.join(curpath, '.hg'))):
+ vfs.isdir(os.path.join(curpath, '.hg'))):
if not self.callback or not self.callback(curpath):
raise util.Abort(_("path '%s' is inside nested "
"repo %r")
@@ -231,9 +231,10 @@
dirname, basename = os.path.split(f)
# If basename is empty, then the path is malformed because it points
# to a directory. Let the posixfile() call below raise IOError.
+ vfs = util.vfs()
if basename and mode not in ('r', 'rb'):
if atomictemp:
- if not os.path.isdir(dirname):
+ if not vfs.isdir(dirname):
util.makedirs(dirname, self.createmode)
return util.atomictempfile(f, mode, self.createmode)
try:
@@ -252,7 +253,7 @@
if e.errno != errno.ENOENT:
raise
nlink = 0
- if not os.path.isdir(dirname):
+ if not vfs.isdir(dirname):
util.makedirs(dirname, self.createmode)
if nlink > 0:
if self._trustnlink is None:
@@ -274,7 +275,7 @@
pass
dirname = os.path.dirname(linkname)
- if not os.path.exists(dirname):
+ if not vfs.exists(dirname):
util.makedirs(dirname, self.createmode)
if self._cansymlink:
@@ -383,7 +384,7 @@
if '.hg' in dirs:
yield root # found a repository
qroot = os.path.join(root, '.hg', 'patches')
- if os.path.isdir(os.path.join(qroot, '.hg')):
+ if vfs.isdir(os.path.join(qroot, '.hg')):
yield qroot # we have a patch queue repo here
if recurse:
# avoid recursing inside the .hg directory
@@ -395,7 +396,7 @@
for d in dirs:
fname = os.path.join(root, d)
if adddir(seen_dirs, fname):
- if os.path.islink(fname):
+ if vfs.islink(fname):
for hgname in walkrepos(fname, True, seen_dirs):
yield hgname
else:
@@ -421,11 +422,12 @@
if _rcpath is None:
if 'HGRCPATH' in os.environ:
_rcpath = []
+ vfs = util.vfs()
for p in os.environ['HGRCPATH'].split(os.pathsep):
if not p:
continue
p = util.expandpath(p)
- if os.path.isdir(p):
+ if vfs.isdir(p):
for f, kind in osutil.listdir(p):
if f.endswith('.rc'):
_rcpath.append(os.path.join(p, f))
@@ -465,7 +467,7 @@
if sys.platform == 'plan9':
return [os.environ['home'] + '/lib/hgrc']
else:
- return [os.path.expanduser('~/.hgrc')]
+ return [util.vfs().expanduser('~/.hgrc')]
else:
@@ -477,12 +479,13 @@
filename = util.executablepath()
# Use mercurial.ini found in directory with hg.exe
progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
- if os.path.isfile(progrc):
+ vfs = util.vfs()
+ if vfs.isfile(progrc):
rcpath.append(progrc)
return rcpath
# Use hgrc.d found in directory with hg.exe
progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d')
- if os.path.isdir(progrcd):
+ if vfs.isdir(progrcd):
for f, kind in osutil.listdir(progrcd):
if f.endswith('.rc'):
rcpath.append(os.path.join(progrcd, f))
@@ -496,7 +499,7 @@
for p in value.split(os.pathsep):
if p.lower().endswith('mercurial.ini'):
rcpath.append(p)
- elif os.path.isdir(p):
+ elif vfs.isdir(p):
for f, kind in osutil.listdir(p):
if f.endswith('.rc'):
rcpath.append(os.path.join(p, f))
@@ -504,7 +507,7 @@
def userrcpath():
'''return os-specific hgrc search path to the user dir'''
- home = os.path.expanduser('~')
+ home = util.vfs().expanduser('~')
path = [os.path.join(home, 'mercurial.ini'),
os.path.join(home, '.hgrc')]
userprofile = os.environ.get('USERPROFILE')
@@ -647,6 +650,7 @@
m = match(repo[None], pats, opts)
rejected = []
m.bad = lambda x, y: rejected.append(x)
+ vfs = util.vfs()
for abs in repo.walk(m):
target = repo.wjoin(abs)
@@ -662,8 +666,8 @@
if repo.ui.verbose or not exact:
repo.ui.status(_('adding %s\n') % ((pats and rel) or abs))
elif (repo.dirstate[abs] != 'r' and
- (not good or not os.path.lexists(target) or
- (os.path.isdir(target) and not os.path.islink(target)))):
+ (not good or not vfs.lexists(target) or
+ (vfs.isdir(target) and not vfs.islink(target)))):
deleted.append(abs)
if repo.ui.verbose or not exact:
repo.ui.status(_('removing %s\n') % ((pats and rel) or abs))
@@ -726,13 +730,14 @@
if (not similarity) and removes:
wctx.remove(sorted(removes), True)
+ vfs = util.vfs()
for f in patches:
gp = patches[f]
if gp and gp.mode:
islink, isexec = gp.mode
dst = repo.wjoin(gp.path)
# patch won't create empty files
- if gp.op == 'ADD' and not os.path.lexists(dst):
+ if gp.op == 'ADD' and not vfs.lexists(dst):
flags = (isexec and 'x' or '') + (islink and 'l' or '')
repo.wwrite(gp.path, '', flags)
util.setflags(dst, islink, isexec)
diff -r 649cab17ed60 -r 779b9800d898 mercurial/simplemerge.py
--- a/mercurial/simplemerge.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/simplemerge.py Fri Jun 15 22:59:54 2012 +0900
@@ -430,7 +430,7 @@
except util.Abort:
return 1
- local = os.path.realpath(local)
+ local = util.vfs().realpath(local)
if not opts.get('print'):
opener = scmutil.opener(os.path.dirname(local))
out = opener(os.path.basename(local), "w", atomictemp=True)
diff -r 649cab17ed60 -r 779b9800d898 mercurial/sslutil.py
--- a/mercurial/sslutil.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/sslutil.py Fri Jun 15 22:59:54 2012 +0900
@@ -6,7 +6,6 @@
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
-import os
from mercurial import util
from mercurial.i18n import _
@@ -87,7 +86,7 @@
hostfingerprint = ui.config('hostfingerprints', host)
if cacerts and not hostfingerprint:
cacerts = util.expandpath(cacerts)
- if not os.path.exists(cacerts):
+ if not util.vfs().exists(cacerts):
raise util.Abort(_('could not find web.cacerts: %s') % cacerts)
return {'ca_certs': cacerts,
'cert_reqs': CERT_REQUIRED,
diff -r 649cab17ed60 -r 779b9800d898 mercurial/store.py
--- a/mercurial/store.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/store.py Fri Jun 15 22:59:54 2012 +0900
@@ -253,7 +253,7 @@
path += '/' + relpath
striplen = len(self.path) + 1
l = []
- if os.path.isdir(path):
+ if util.vfs().isdir(path):
visit = [path]
while visit:
p = visit.pop()
diff -r 649cab17ed60 -r 779b9800d898 mercurial/subrepo.py
--- a/mercurial/subrepo.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/subrepo.py Fri Jun 15 22:59:54 2012 +0900
@@ -389,7 +389,7 @@
r = ctx._repo
root = r.wjoin(path)
create = False
- if not os.path.exists(os.path.join(root, '.hg')):
+ if not util.vfs().exists(os.path.join(root, '.hg')):
create = True
util.makedirs(root)
self._repo = hg.repository(r.ui, root, create=create)
@@ -893,7 +893,7 @@
return retdata, p.returncode
def _gitmissing(self):
- return not os.path.exists(os.path.join(self._abspath, '.git'))
+ return not util.vfs().exists(os.path.join(self._abspath, '.git'))
def _gitstate(self):
return self._gitcommand(['rev-parse', 'HEAD'])
@@ -1180,7 +1180,7 @@
if f == '.git':
continue
path = os.path.join(self._abspath, f)
- if os.path.isdir(path) and not os.path.islink(path):
+ if vfs.isdir(path) and not vfs.islink(path):
shutil.rmtree(path)
else:
vfs.remove(path)
diff -r 649cab17ed60 -r 779b9800d898 mercurial/templater.py
--- a/mercurial/templater.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/templater.py Fri Jun 15 22:59:54 2012 +0900
@@ -288,7 +288,7 @@
if not mapfile:
return
- if not os.path.exists(mapfile):
+ if not util.vfs().exists(mapfile):
raise util.Abort(_('style not found: %s') % mapfile)
conf = config.config()
@@ -345,6 +345,7 @@
module = sys.executable
else:
module = __file__
+ vfs = util.vfs()
for f in path:
if f.startswith('/'):
p = f
@@ -353,9 +354,9 @@
p = os.path.join(os.path.dirname(module), *fl)
if name:
p = os.path.join(p, name)
- if name and os.path.exists(p):
+ if name and vfs.exists(p):
return os.path.normpath(p)
- elif os.path.isdir(p):
+ elif vfs.isdir(p):
normpaths.append(os.path.normpath(p))
return normpaths
@@ -377,6 +378,7 @@
if isinstance(styles, str):
styles = [styles]
+ vfs = util.vfs()
for style in styles:
if not style:
continue
@@ -386,7 +388,7 @@
for path in paths:
for location in locations:
mapfile = os.path.join(path, location)
- if os.path.isfile(mapfile):
+ if vfs.isfile(mapfile):
return style, mapfile
raise RuntimeError("No hgweb templates found in %r" % paths)
diff -r 649cab17ed60 -r 779b9800d898 mercurial/transaction.py
--- a/mercurial/transaction.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/transaction.py Fri Jun 15 22:59:54 2012 +0900
@@ -12,7 +12,7 @@
# GNU General Public License version 2 or any later version.
from i18n import _
-import os, errno
+import errno
import error, util
def active(func):
@@ -136,7 +136,7 @@
self.entries = []
if self.after:
self.after()
- if os.path.isfile(self.journal):
+ if util.vfs().isfile(self.journal):
util.unlink(self.journal)
self.journal = None
diff -r 649cab17ed60 -r 779b9800d898 mercurial/ui.py
--- a/mercurial/ui.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/ui.py Fri Jun 15 22:59:54 2012 +0900
@@ -108,7 +108,7 @@
self._ucfg.update(self._ocfg)
if root is None:
- root = os.path.expanduser('~')
+ root = util.vfs().expanduser('~')
self.fixconfig(root=root)
def fixconfig(self, root=None, section=None):
@@ -197,7 +197,7 @@
src = self.configsource(section, name, untrusted)
if ':' in src:
base = os.path.dirname(src.rsplit(':')[0])
- v = os.path.join(base, os.path.expanduser(v))
+ v = os.path.join(base, util.vfs().expanduser(v))
return v
def configbool(self, section, name, default=False, untrusted=False):
@@ -401,7 +401,7 @@
if user is None:
user = self.config("ui", "username")
if user is not None:
- user = os.path.expandvars(user)
+ user = util.vfs().expandvars(user)
if user is None:
user = os.environ.get("EMAIL")
if user is None and self.configbool("ui", "askusername"):
@@ -426,7 +426,7 @@
def expandpath(self, loc, default=None):
"""Return repository location relative to cwd or from [paths]"""
- if util.hasscheme(loc) or os.path.isdir(os.path.join(loc, '.hg')):
+ if util.hasscheme(loc) or util.vfs().isdir(os.path.join(loc, '.hg')):
return loc
path = self.config('paths', loc)
diff -r 649cab17ed60 -r 779b9800d898 mercurial/url.py
--- a/mercurial/url.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/url.py Fri Jun 15 22:59:54 2012 +0900
@@ -468,7 +468,7 @@
u.scheme = u.scheme.lower()
url_, authinfo = u.authinfo()
else:
- path = util.normpath(os.path.abspath(url_))
+ path = util.normpath(util.vfs().abspath(url_))
url_ = 'file://' + urllib.pathname2url(path)
authinfo = None
return opener(ui, authinfo).open(url_, data)
diff -r 649cab17ed60 -r 779b9800d898 mercurial/util.py
--- a/mercurial/util.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/util.py Fri Jun 15 22:59:54 2012 +0900
@@ -484,7 +484,7 @@
def copyfile(src, dest):
"copy a file, preserving mode and atime/mtime"
vfsobj = vfs()
- if os.path.islink(src):
+ if vfsobj.islink(src):
try:
vfsobj.unlink(dest)
except OSError:
@@ -506,7 +506,7 @@
vfsobj.stat(os.path.dirname(dst)).st_dev)
num = 0
- if os.path.isdir(src):
+ if vfsobj.isdir(src):
vfsobj.mkdir(dst)
for name, kind in osutil.listdir(src):
srcname = os.path.join(src, name)
@@ -712,7 +712,8 @@
# testfile may be open, so we need a separate file for checking to
# work around issue2543 (or testfile may get lost on Samba shares)
f1 = testfile + ".hgtmp1"
- if os.path.lexists(f1):
+ vfsobj = vfs()
+ if vfsobj.lexists(f1):
return False
try:
posixfile(f1, 'w').close()
@@ -736,7 +737,7 @@
fd.close()
for f in (f1, f2):
try:
- vfs().unlink(f)
+ vfsobj.unlink(f)
except OSError:
pass
@@ -854,7 +855,7 @@
return
if err.errno != errno.ENOENT or not name:
raise
- parent = os.path.dirname(os.path.abspath(name))
+ parent = os.path.dirname(vfsobj.abspath(name))
if parent == name:
raise
makedirs(parent, mode)
@@ -1365,7 +1366,8 @@
yield line
def expandpath(path):
- return os.path.expanduser(os.path.expandvars(path))
+ vfsobj = vfs()
+ return vfsobj.expanduser(vfsobj.expandvars(path))
def hgcmd():
"""Return the command used to execute current hg
@@ -1848,6 +1850,29 @@
def walk(self, *args, **kwargs):
return self._osmod.walk(*args, **kwargs)
+ def abspath(self, *args, **kwargs):
+ return self._osmod.path.abspath(*args, **kwargs)
+ def exists(self, *args, **kwargs):
+ return self._osmod.path.exists(*args, **kwargs)
+ def expanduser(self, *args, **kwargs):
+ return self._osmod.path.expanduser(*args, **kwargs)
+ def expandvars(self, *args, **kwargs):
+ return self._osmod.path.expandvars(*args, **kwargs)
+ def getmtime(self, *args, **kwargs):
+ return self._osmod.path.getmtime(*args, **kwargs)
+ def getsize(self, *args, **kwargs):
+ return self._osmod.path.getsize(*args, **kwargs)
+ def isdir(self, *args, **kwargs):
+ return self._osmod.path.isdir(*args, **kwargs)
+ def isfile(self, *args, **kwargs):
+ return self._osmod.path.isfile(*args, **kwargs)
+ def islink(self, *args, **kwargs):
+ return self._osmod.path.islink(*args, **kwargs)
+ def lexists(self, *args, **kwargs):
+ return self._osmod.path.lexists(*args, **kwargs)
+ def realpath(self, *args, **kwargs):
+ return self._osmod.path.realpath(*args, **kwargs)
+
_bvfs = _vfs()
def vfs(mode=None):
diff -r 649cab17ed60 -r 779b9800d898 mercurial/verify.py
--- a/mercurial/verify.py Fri Jun 15 22:59:53 2012 +0900
+++ b/mercurial/verify.py Fri Jun 15 22:59:54 2012 +0900
@@ -7,7 +7,6 @@
from node import nullid, short
from i18n import _
-import os
import revlog, util, error
def verify(repo):
@@ -108,7 +107,7 @@
seen[n] = i
return lr
- if os.path.exists(repo.sjoin("journal")):
+ if util.vfs().exists(repo.sjoin("journal")):
ui.warn(_("abandoned transaction found - run hg recover\n"))
revlogv1 = cl.version != revlog.REVLOGV0
More information about the Mercurial-devel
mailing list