# HG changeset patch # User Adrian Buehlmann # Date 2011-08-02 11:18:56 # Node ID 5e44e4b3a0a32752d8e1dbf54b2d34f04de60583 # Parent c3114acd8ea20a7f2f786084a7a833b54be43e75 util: move copymode into posix.py and windows.py reducing it to a NOP on Windows. This eliminates a pointless stat call on Windows and reduces the risk of interferring with other processes (e.g. AV-scanners, file change watchers). See also http://mercurial.selenic.com/wiki/UnlinkingFilesOnWindows, item 2d diff --git a/mercurial/posix.py b/mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -84,6 +84,21 @@ def setflags(f, l, x): # Turn off all +x bits os.chmod(f, s & 0666) +def copymode(src, dst, mode=None): + '''Copy the file mode from the file at path src to dst. + If src doesn't exist, we're using mode instead. If mode is None, we're + using umask.''' + try: + st_mode = os.lstat(src).st_mode & 0777 + except OSError, inst: + if inst.errno != errno.ENOENT: + raise + st_mode = mode + if st_mode is None: + st_mode = ~umask + st_mode &= 0666 + os.chmod(dst, st_mode) + def checkexec(path): """ Check whether the given path is on a filesystem with UNIX-like exec flags diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -27,6 +27,7 @@ else: cachestat = platform.cachestat checkexec = platform.checkexec checklink = platform.checklink +copymode = platform.copymode executablepath = platform.executablepath expandglobs = platform.expandglobs explainexit = platform.explainexit @@ -701,21 +702,6 @@ def gui(): else: return os.name == "nt" or os.environ.get("DISPLAY") -def copymode(src, dst, mode=None): - '''Copy the file mode from the file at path src to dst. - If src doesn't exist, we're using mode instead. If mode is None, we're - using umask.''' - try: - st_mode = os.lstat(src).st_mode & 0777 - except OSError, inst: - if inst.errno != errno.ENOENT: - raise - st_mode = mode - if st_mode is None: - st_mode = ~umask - st_mode &= 0666 - os.chmod(dst, st_mode) - def mktempcopy(name, emptyok=False, createmode=None): """Create a temporary file with the same contents from name diff --git a/mercurial/windows.py b/mercurial/windows.py --- a/mercurial/windows.py +++ b/mercurial/windows.py @@ -105,6 +105,9 @@ def sshargs(sshcmd, host, user, port): def setflags(f, l, x): pass +def copymode(src, dst, mode=None): + pass + def checkexec(path): return False