diff mercurial/scmutil.py @ 28226:6a6e78f84cc6 stable

merge: while checking for unknown files don't follow symlinks (issue5027) Previously, we were using Python's native 'os.path.isfile' method which follows symlinks. In this case, since we're operating on repo contents, we don't want to follow symlinks. There's a behaviour change here, as shown by the second part of the added test. Consider a symlink 'f' pointing to a file containing 'abc'. If we try and replace it with a file with contents 'abc', previously we would have let it though. Now we don't. Although this breaks naive inspection with tools like 'cat' and 'diff', on balance I believe this is the right change.
author Siddharth Agarwal <sid0@fb.com>
date Mon, 28 Dec 2015 22:51:37 -0800
parents 88c4e97b9669
children b8405d739149
line wrap: on
line diff
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -312,6 +312,17 @@
     def islink(self, path=None):
         return os.path.islink(self.join(path))
 
+    def isfileorlink(self, path=None):
+        '''return whether path is a regular file or a symlink
+
+        Unlike isfile, this doesn't follow symlinks.'''
+        try:
+            st = self.lstat(path)
+        except OSError:
+            return False
+        mode = st.st_mode
+        return stat.S_ISREG(mode) or stat.S_ISLNK(mode)
+
     def reljoin(self, *paths):
         """join various elements of a path together (as os.path.join would do)