[PATCH 2 of 2] keyword: only use expensive fctx.cmp when needed

Christian Ebert blacktrash at gmx.net
Thu Oct 14 16:40:51 CDT 2010


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1287089597 -7200
# Node ID 46bc128663f229f66f75ca756dbf86fb1ff9015b
# Parent  b8d25bf4d45c03cdb43124452eb4149261e95396
keyword: only use expensive fctx.cmp when needed

Restrict expensive cmp to cases when:

- comparing against working directory
and
  - encode filters active
  or
  - path is configured for keyword expansion

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -594,9 +594,14 @@
     def kwfilectx_cmp(orig, self, fctx):
         # keyword affects data size, comparing wdir and filelog size does
         # not make sense
-        return self._filelog.cmp(self._filenode, fctx.data())
+        if (isinstance(fctx, context.workingfilectx) and
+            (self._repo._encodefilterpats or
+             kwt.match(fctx.path()) and not 'l' in fctx.flags()) or
+            self.size() == fctx.size()):
+            return self._filelog.cmp(self._filenode, fctx.data())
+        return True
+
     extensions.wrapfunction(context.filectx, 'cmp', kwfilectx_cmp)
-
     extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init)
     extensions.wrapfunction(patch, 'diff', kw_diff)
     extensions.wrapfunction(cmdutil, 'copy', kw_copy)


More information about the Mercurial-devel mailing list