Mercurial > hg
changeset 32208:d74b0cff94a9
osutil: proxy through util (and platform) modules (API)
See the previous commit for why. Marked as API change since osutil.listdir()
seems widely used in third-party extensions.
The win32mbcs extension is updated to wrap both util. and windows. aliases.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 26 Apr 2017 22:26:28 +0900 |
parents | 0c73634d0570 |
children | 85dc5a25f1fc |
files | hgext/win32mbcs.py mercurial/chgserver.py mercurial/dirstate.py mercurial/rcutil.py mercurial/scmposix.py mercurial/scmwindows.py mercurial/util.py mercurial/vfs.py mercurial/windows.py |
diffstat | 9 files changed, 29 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/win32mbcs.py Wed Apr 26 22:05:59 2017 +0900 +++ b/hgext/win32mbcs.py Wed Apr 26 22:26:28 2017 +0900 @@ -182,7 +182,8 @@ if pycompat.osname == 'nt': for f in winfuncs.split(): wrapname(f, wrapper) - wrapname("mercurial.osutil.listdir", wrapperforlistdir) + wrapname("mercurial.util.listdir", wrapperforlistdir) + wrapname("mercurial.windows.listdir", wrapperforlistdir) # wrap functions to be called with local byte string arguments for f in rfuncs.split(): wrapname(f, reversewrapper)
--- a/mercurial/chgserver.py Wed Apr 26 22:05:59 2017 +0900 +++ b/mercurial/chgserver.py Wed Apr 26 22:26:28 2017 +0900 @@ -54,7 +54,6 @@ encoding, error, extensions, - osutil, pycompat, util, ) @@ -313,7 +312,7 @@ # tell client to sendmsg() with 1-byte payload, which makes it # distinctive from "attachio\n" command consumed by client.read() self.clientsock.sendall(struct.pack('>cI', 'I', 1)) - clientfds = osutil.recvfds(self.clientsock.fileno()) + clientfds = util.recvfds(self.clientsock.fileno()) _log('received fds: %r\n' % clientfds) ui = self.ui @@ -458,12 +457,12 @@ 'setenv': setenv, 'setumask': setumask}) - if util.safehasattr(osutil, 'setprocname'): + if util.safehasattr(util, 'setprocname'): def setprocname(self): """Change process title""" name = self._readstr() _log('setprocname: %r\n' % name) - osutil.setprocname(name) + util.setprocname(name) capabilities['setprocname'] = setprocname def _tempaddress(address):
--- a/mercurial/dirstate.py Wed Apr 26 22:05:59 2017 +0900 +++ b/mercurial/dirstate.py Wed Apr 26 22:26:28 2017 +0900 @@ -18,7 +18,6 @@ encoding, error, match as matchmod, - osutil, parsers, pathutil, pycompat, @@ -988,7 +987,7 @@ matchalways = match.always() matchtdir = match.traversedir dmap = self._map - listdir = osutil.listdir + listdir = util.listdir lstat = os.lstat dirkind = stat.S_IFDIR regkind = stat.S_IFREG
--- a/mercurial/rcutil.py Wed Apr 26 22:05:59 2017 +0900 +++ b/mercurial/rcutil.py Wed Apr 26 22:26:28 2017 +0900 @@ -11,7 +11,6 @@ from . import ( encoding, - osutil, pycompat, util, ) @@ -30,7 +29,7 @@ p = util.expandpath(path) if os.path.isdir(p): join = os.path.join - return [join(p, f) for f, k in osutil.listdir(p) if f.endswith('.rc')] + return [join(p, f) for f, k in util.listdir(p) if f.endswith('.rc')] return [p] def envrcitems(env=None):
--- a/mercurial/scmposix.py Wed Apr 26 22:05:59 2017 +0900 +++ b/mercurial/scmposix.py Wed Apr 26 22:26:28 2017 +0900 @@ -8,8 +8,8 @@ from . import ( encoding, - osutil, pycompat, + util, ) # BSD 'more' escapes ANSI color sequences by default. This can be disabled by @@ -23,7 +23,7 @@ rcdir = os.path.join(path, 'hgrc.d') try: rcs.extend([os.path.join(rcdir, f) - for f, kind in osutil.listdir(rcdir) + for f, kind in util.listdir(rcdir) if f.endswith(".rc")]) except OSError: pass
--- a/mercurial/scmwindows.py Wed Apr 26 22:05:59 2017 +0900 +++ b/mercurial/scmwindows.py Wed Apr 26 22:26:28 2017 +0900 @@ -4,7 +4,6 @@ from . import ( encoding, - osutil, pycompat, util, win32, @@ -29,7 +28,7 @@ # Use hgrc.d found in directory with hg.exe progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d') if os.path.isdir(progrcd): - for f, kind in osutil.listdir(progrcd): + for f, kind in util.listdir(progrcd): if f.endswith('.rc'): rcpath.append(os.path.join(progrcd, f)) # else look for a system rcpath in the registry @@ -42,7 +41,7 @@ if p.lower().endswith('mercurial.ini'): rcpath.append(p) elif os.path.isdir(p): - for f, kind in osutil.listdir(p): + for f, kind in util.listdir(p): if f.endswith('.rc'): rcpath.append(os.path.join(p, f)) return rcpath
--- a/mercurial/util.py Wed Apr 26 22:05:59 2017 +0900 +++ b/mercurial/util.py Wed Apr 26 22:26:28 2017 +0900 @@ -106,6 +106,7 @@ hidewindow = platform.hidewindow isexec = platform.isexec isowner = platform.isowner +listdir = osutil.listdir localpath = platform.localpath lookupreg = platform.lookupreg makedir = platform.makedir @@ -143,6 +144,15 @@ unlink = platform.unlink username = platform.username +try: + recvfds = osutil.recvfds +except AttributeError: + pass +try: + setprocname = osutil.setprocname +except AttributeError: + pass + # Python compatibility _notset = object() @@ -1165,7 +1175,7 @@ os.stat(os.path.dirname(dst)).st_dev) topic = gettopic() os.mkdir(dst) - for name, kind in osutil.listdir(src): + for name, kind in listdir(src): srcname = os.path.join(src, name) dstname = os.path.join(dst, name) def nprog(t, pos):
--- a/mercurial/vfs.py Wed Apr 26 22:05:59 2017 +0900 +++ b/mercurial/vfs.py Wed Apr 26 22:26:28 2017 +0900 @@ -17,7 +17,6 @@ from .i18n import _ from . import ( error, - osutil, pathutil, pycompat, util, @@ -163,7 +162,7 @@ return fd, fname def readdir(self, path=None, stat=None, skip=None): - return osutil.listdir(self.join(path), stat, skip) + return util.listdir(self.join(path), stat, skip) def readlock(self, path): return util.readlock(self.join(path))
--- a/mercurial/windows.py Wed Apr 26 22:05:59 2017 +0900 +++ b/mercurial/windows.py Wed Apr 26 22:26:28 2017 +0900 @@ -136,6 +136,9 @@ # convert to a friendlier exception raise IOError(err.errno, '%s: %s' % (name, err.strerror)) +# may be wrapped by win32mbcs extension +listdir = osutil.listdir + class winstdout(object): '''stdout on windows misbehaves if sent through a pipe''' @@ -349,7 +352,7 @@ if cache is None: try: dmap = dict([(normcase(n), s) - for n, k, s in osutil.listdir(dir, True) + for n, k, s in listdir(dir, True) if getkind(s.st_mode) in _wantedkinds]) except OSError as err: # Python >= 2.5 returns ENOENT and adds winerror field @@ -376,7 +379,7 @@ def removedirs(name): """special version of os.removedirs that does not remove symlinked directories or junction points if they actually contain files""" - if osutil.listdir(name): + if listdir(name): return os.rmdir(name) head, tail = os.path.split(name) @@ -384,7 +387,7 @@ head, tail = os.path.split(head) while head and tail: try: - if osutil.listdir(head): + if listdir(head): return os.rmdir(head) except (ValueError, OSError):