# HG changeset patch # User Mads Kiilerich # Date 1421194526 -3600 # Node ID 1ce4c2062ab07617ea4dcd4933dc7062a05ffb36 # Parent b1ce25a40826a024edf46aa11a709e8fbecb23a2 posix: simplify checkexec check Use a slightly simpler logic that in some cases can avoid an unnecessary chmod and stat. Instead of flipping the X bits, make it more clear that we rely on no X bits being set on initial file creation, and that at least some of them stick after they all have been set. diff -r b1ce25a40826 -r 1ce4c2062ab0 mercurial/posix.py --- a/mercurial/posix.py Thu Nov 17 12:59:36 2016 +0100 +++ b/mercurial/posix.py Wed Jan 14 01:15:26 2015 +0100 @@ -166,16 +166,16 @@ fh, fn = tempfile.mkstemp(dir=cachedir, prefix='hg-checkexec-') try: os.close(fh) - m = os.stat(fn).st_mode & 0o777 - new_file_has_exec = m & EXECFLAGS - os.chmod(fn, m ^ EXECFLAGS) - exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0o777) == m) + m = os.stat(fn).st_mode + if m & EXECFLAGS: + return False + os.chmod(fn, m & 0o777 | EXECFLAGS) + return os.stat(fn).st_mode & EXECFLAGS finally: os.unlink(fn) except (IOError, OSError): # we don't care, the user probably won't be able to commit anyway return False - return not (new_file_has_exec or exec_flags_cannot_flip) def checklink(path): """check whether the given path is on a symlink-capable filesystem"""