# HG changeset patch # User Adrian Buehlmann # Date 1351935636 -3600 # Node ID 3cb032d504472967c4cee3d2ed29a6e8e0f3afac # Parent 95fc4ab324df4eeeb7d272134289d25730686570 vfs: optimize __call__ by not calling util.split for reads dirname and basename are not used on reads diff -r 95fc4ab324df -r 3cb032d50447 mercurial/scmutil.py --- a/mercurial/scmutil.py Wed Nov 14 18:08:39 2012 -0600 +++ b/mercurial/scmutil.py Sat Nov 03 10:40:36 2012 +0100 @@ -279,37 +279,38 @@ mode += "b" # for that other OS nlink = -1 - dirname, basename = util.split(f) - # If basename is empty, then the path is malformed because it points - # to a directory. Let the posixfile() call below raise IOError. - if basename and mode not in ('r', 'rb'): - if atomictemp: - if not os.path.isdir(dirname): - util.makedirs(dirname, self.createmode) - return util.atomictempfile(f, mode, self.createmode) - try: - if 'w' in mode: - util.unlink(f) + if mode not in ('r', 'rb'): + dirname, basename = util.split(f) + # If basename is empty, then the path is malformed because it points + # to a directory. Let the posixfile() call below raise IOError. + if basename: + if atomictemp: + if not os.path.isdir(dirname): + util.makedirs(dirname, self.createmode) + return util.atomictempfile(f, mode, self.createmode) + try: + if 'w' in mode: + util.unlink(f) + nlink = 0 + else: + # nlinks() may behave differently for files on Windows + # shares if the file is open. + fd = util.posixfile(f) + nlink = util.nlinks(f) + if nlink < 1: + nlink = 2 # force mktempcopy (issue1922) + fd.close() + except (OSError, IOError), e: + if e.errno != errno.ENOENT: + raise nlink = 0 - else: - # nlinks() may behave differently for files on Windows - # shares if the file is open. - fd = util.posixfile(f) - nlink = util.nlinks(f) - if nlink < 1: - nlink = 2 # force mktempcopy (issue1922) - fd.close() - except (OSError, IOError), e: - if e.errno != errno.ENOENT: - raise - nlink = 0 - if not os.path.isdir(dirname): - util.makedirs(dirname, self.createmode) - if nlink > 0: - if self._trustnlink is None: - self._trustnlink = nlink > 1 or util.checknlink(f) - if nlink > 1 or not self._trustnlink: - util.rename(util.mktempcopy(f), f) + if not os.path.isdir(dirname): + util.makedirs(dirname, self.createmode) + if nlink > 0: + if self._trustnlink is None: + self._trustnlink = nlink > 1 or util.checknlink(f) + if nlink > 1 or not self._trustnlink: + util.rename(util.mktempcopy(f), f) fp = util.posixfile(f, mode) if nlink == 0: self._fixfilemode(f)