Patchwork [11,of,14,RFC] memfilectx: add cmp method

login
register
mail settings
Submitter Sean Farley
Date July 9, 2013, 9:54 p.m.
Message ID <1fa8870e0ae8dc5f23f5.1373406882@laptop.local>
Download mbox | patch
Permalink /patch/1819/
State Changes Requested
Headers show

Comments

Sean Farley - July 9, 2013, 9:54 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1373323864 18000
#      Mon Jul 08 17:51:04 2013 -0500
# Node ID 1fa8870e0ae8dc5f23f5326470c5fbc93f63a95b
# Parent  15c72f9d02eada7a9811034da42628f30bfd073a
memfilectx: add cmp method

This is directly copied from the filectx with the only change being to call the
"self.data() != fctx.data()" directly instead of going through the filelog. Is
there a better way to do this compare?

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1380,5 +1380,20 @@ 
         return 'x' in self._flags
     def islink(self):
         return 'l' in self._flags
     def renamed(self):
         return self._copied
+
+    def cmp(self, fctx):
+        """compare with other file context or workingfile context
+
+        returns True if different than fctx.
+        """
+        if (fctx._filerev 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()):
+            return self.data() != fctx.data()
+
+        return True