[PATCH stable] filectx: fix cmp() of file starting with '\1\n'
Yuya Nishihara
yuya at tcha.org
Tue Jan 10 10:46:23 CST 2012
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1326213787 -32400
# Branch stable
# Node ID fc9a58eeb4a6d74768fe8a184638e2d247603d3c
# Parent e4fc0f0b4f7e73f6cbfa132cf09b7027a909d08c
filectx: fix cmp() of file starting with '\1\n'
Because filelog.size() returns size+4 for data starting with '\1\n',
fctx.cmp(workingfcx) happens to return True wrongly. As the result,
`hg status` of a file starting with '\1\n' is always M, even if it isn't
modified.
Since there's no cheap way to fix bug of filelog.size() according to [1],
this patch works around the problem at filectx.cmp().
[1]: http://markmail.org/message/5akdbmmqx7vq2fsg
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -369,7 +369,10 @@ class filectx(object):
returns True if different than fctx.
"""
if (fctx._filerev is None and self._repo._encodefilterpats
- or self.size() == fctx.size()):
+ or self.size() == fctx.size()
+ # filelog.size() may return size+4 if data startswith '\1\n'
+ or (isinstance(fctx, workingfilectx)
+ and self.size() - 4 == fctx.size())):
return self._filelog.cmp(self._filenode, fctx.data())
return True
diff --git a/tests/test-status.t b/tests/test-status.t
--- a/tests/test-status.t
+++ b/tests/test-status.t
@@ -272,3 +272,26 @@ hg status -A --change 1:
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
More information about the Mercurial-devel
mailing list