filelog: test behaviour for data starting with "\1\n"
Because "\1\n" is a separator for metadata, data starting with "\1\n" is
handled specifically. It was not tested.
size() call return incorrect data if original data had been "\1\n-escaped".
There's no obvious way to fix it for now, just flag the error in the code
and add an "expected failure" kind of test.
--- a/mercurial/filelog.py Fri Jul 09 11:02:39 2010 +0900
+++ b/mercurial/filelog.py Mon Jul 05 18:43:46 2010 +0900
@@ -53,6 +53,7 @@
if self.renamed(node):
return len(self.read(node))
+ # XXX if self.read(node).startswith("\1\n"), this returns (size+4)
return revlog.revlog.size(self, rev)
def cmp(self, node, text):
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-filelog Mon Jul 05 18:43:46 2010 +0900
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+"""
+Tests the behaviour of filelog w.r.t. data starting with '\1\n'
+"""
+from mercurial import ui, hg
+from mercurial.node import nullid, hex
+
+myui = ui.ui()
+repo = hg.repository(myui, path='.', create=True)
+
+fl = repo.file('foobar')
+
+def addrev(text, renamed=False):
+ if renamed:
+ # data doesnt matter. Just make sure filelog.renamed() returns True
+ meta = dict(copyrev=hex(nullid), copy='bar')
+ else:
+ meta = {}
+
+ t = repo.transaction('commit')
+ try:
+ node = fl.add(text, meta, t, 0, nullid, nullid)
+ return node
+ finally:
+ t.close()
+
+def error(text):
+ print 'ERROR: ' + text
+
+textwith = '\1\nfoo'
+without = 'foo'
+
+node = addrev(textwith)
+if not textwith == fl.read(node):
+ error('filelog.read for data starting with \\1\\n')
+if fl.cmp(node, textwith) or not fl.cmp(node, without):
+ error('filelog.cmp for data starting with \\1\\n')
+if fl.size(0) != len(textwith):
+ error('FIXME: This is a known failure of filelog.size for data starting '
+ 'with \\1\\n')
+
+node = addrev(textwith, renamed=True)
+if not textwith == fl.read(node):
+ error('filelog.read for a renaming + data starting with \\1\\n')
+if fl.cmp(node, textwith) or not fl.cmp(node, without):
+ error('filelog.cmp for a renaming + data starting with \\1\\n')
+if fl.size(1) != len(textwith):
+ error('filelog.size for a renaming + data starting with \\1\\n')
+
+print 'OK.'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-filelog.out Mon Jul 05 18:43:46 2010 +0900
@@ -0,0 +1,2 @@
+ERROR: FIXME: This is a known failure of filelog.size for data starting with \1\n
+OK.