context: collapse complex condition to see if filelog have to be compared
authorYuya Nishihara <yuya@tcha.org>
Sun, 16 Dec 2018 16:24:45 +0900
changeset 40990 39953bcf1f51
parent 40989 e10adebf8176
child 40991 21ffe6b97a25
context: collapse complex condition to see if filelog have to be compared It's hard to read. I'd rather make the return statement duplicated.
mercurial/context.py
--- a/mercurial/context.py	Tue Dec 18 10:21:25 2018 -0500
+++ b/mercurial/context.py	Sun Dec 16 16:24:45 2018 +0900
@@ -702,14 +702,20 @@
         if fctx._customcmp:
             return fctx.cmp(self)
 
-        if (fctx._filenode is None
-            and (self._repo._encodefilterpats
-                 # if file data starts with '\1\n', empty metadata block is
-                 # prepended, which adds 4 bytes to filelog.size().
-                 or self.size() - 4 == fctx.size())
-            or self.size() == fctx.size()):
+        if fctx._filenode is None:
+            if self._repo._encodefilterpats:
+                # can't rely on size() because wdir content may be decoded
+                return self._filelog.cmp(self._filenode, fctx.data())
+            if self.size() - 4 == fctx.size():
+                # size() can match:
+                # if file data starts with '\1\n', empty metadata block is
+                # prepended, which adds 4 bytes to filelog.size().
+                return self._filelog.cmp(self._filenode, fctx.data())
+        if self.size() == fctx.size():
+            # size() matches: need to compare content
             return self._filelog.cmp(self._filenode, fctx.data())
 
+        # size() differs
         return True
 
     def _adjustlinkrev(self, srcrev, inclusive=False, stoprev=None):