Patchwork [2,of,3] context: collapse complex condition to see if filelog have to be compared

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 16, 2018, 8:24 a.m.
Message ID <913fdd3fccc6c99def4b.1544948661@mimosa>
Download mbox | patch
Permalink /patch/37203/
State New
Headers show

Comments

Yuya Nishihara - Dec. 16, 2018, 8:24 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1544945085 -32400
#      Sun Dec 16 16:24:45 2018 +0900
# Node ID 913fdd3fccc6c99def4b1ac8cd60abba1f7aa81d
# Parent  79dc95eb84b0f09a39fb396c65ec591f9f0de224
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.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -702,14 +702,20 @@  class basefilectx(object):
         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):