Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/context.py @ 15848:012b285cf643 stable
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
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 12 Jan 2012 00:49:45 +0900 |
parents | cf5f9df6406b |
children | e5feebc1f3bb a3e2b9a1f063 |
comparison
equal
deleted
inserted
replaced
15845:dffdc8c8f6d6 | 15848:012b285cf643 |
---|---|
366 def cmp(self, fctx): | 366 def cmp(self, fctx): |
367 """compare with other file context | 367 """compare with other file context |
368 | 368 |
369 returns True if different than fctx. | 369 returns True if different than fctx. |
370 """ | 370 """ |
371 if (fctx._filerev is None and self._repo._encodefilterpats | 371 if (fctx._filerev is None |
372 and (self._repo._encodefilterpats | |
373 # if file data starts with '\1\n', empty metadata block is | |
374 # prepended, which adds 4 bytes to fielog.size(). | |
375 or self.size() - 4 == fctx.size()) | |
372 or self.size() == fctx.size()): | 376 or self.size() == fctx.size()): |
373 return self._filelog.cmp(self._filenode, fctx.data()) | 377 return self._filelog.cmp(self._filenode, fctx.data()) |
374 | 378 |
375 return True | 379 return True |
376 | 380 |