filectx: fix cmp() of file starting with '\1\n' stable
authorYuya Nishihara <yuya@tcha.org>
Thu, 12 Jan 2012 00:49:45 +0900
branchstable
changeset 15848 012b285cf643
parent 15845 dffdc8c8f6d6
child 15869 e5feebc1f3bb
child 15870 f4c859293ed4
filectx: fix cmp() of file starting with '\1\n' If file data starts with '\1\n', it will be escaped in the revlog to create an empty metadata block, thus adding four bytes to the size in the revlog size index. There's no way to detect that this has happened in filelog.size() faster than decompressing each revision [1]. For filectx.cmp(), we have the size of the file in the working directory available. If it differs by exactly four bytes, it may be this case, so do a full comparison. [1]: http://markmail.org/message/5akdbmmqx7vq2fsg
mercurial/context.py
tests/test-status.t
--- a/mercurial/context.py	Wed Jan 11 09:26:47 2012 -0600
+++ b/mercurial/context.py	Thu Jan 12 00:49:45 2012 +0900
@@ -368,7 +368,11 @@
 
         returns True if different than fctx.
         """
-        if (fctx._filerev is None and self._repo._encodefilterpats
+        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 fielog.size().
+                 or self.size() - 4 == fctx.size())
             or self.size() == fctx.size()):
             return self._filelog.cmp(self._filenode, fctx.data())
 
--- a/tests/test-status.t	Wed Jan 11 09:26:47 2012 -0600
+++ b/tests/test-status.t	Thu Jan 12 00:49:45 2012 +0900
@@ -272,3 +272,26 @@
     modified
   R removed
   C deleted
+
+  $ cd ..
+
+hg status of binary file starting with '\1\n', a separator for metadata:
+
+  $ hg init repo5
+  $ cd repo5
+  $ printf '\1\nfoo' > 010a
+  $ hg ci -q -A -m 'initial checkin'
+  $ hg status -A
+  C 010a
+
+  $ printf '\1\nbar' > 010a
+  $ hg status -A
+  M 010a
+  $ hg ci -q -m 'modify 010a'
+  $ hg status -A --rev 0:1
+  M 010a
+
+  $ touch empty
+  $ hg ci -q -A -m 'add another file'
+  $ hg status -A --rev 1:2 010a
+  C 010a