diff mercurial/context.py @ 34835:14c87708f432

arbitraryfilecontext: skip the cmp fast path if any side is a symlink `filecmp` follows symlinks by default, which a `filectx.cmp()` call should not be doing as it should only compare the requested entry. After this patch, only the contexts' data are compared, which is the correct contract. This is a corrected version of D1122. Differential Revision: https://phab.mercurial-scm.org/D1165
author Phil Cohen <phillco@fb.com>
date Tue, 17 Oct 2017 12:41:24 -0700
parents 07bbb208a924
children f7e4d6c20095
line wrap: on
line diff
--- a/mercurial/context.py	Mon Sep 14 14:17:27 2015 -0400
+++ b/mercurial/context.py	Tue Oct 17 12:41:24 2017 -0700
@@ -2570,9 +2570,13 @@
         self._path = path
 
     def cmp(self, fctx):
-        if isinstance(fctx, workingfilectx) and self._repo:
+        # filecmp follows symlinks whereas `cmp` should not, so skip the fast
+        # path if either side is a symlink.
+        symlinks = ('l' in self.flags() or 'l' in fctx.flags())
+        if not symlinks and isinstance(fctx, workingfilectx) and self._repo:
             # Add a fast-path for merge if both sides are disk-backed.
-            # Note that filecmp uses the opposite return values as cmp.
+            # Note that filecmp uses the opposite return values (True if same)
+            # from our cmp functions (True if different).
             return not filecmp.cmp(self.path(), self._repo.wjoin(fctx.path()))
         return self.data() != fctx.data()