[PATCH 3 of 4] filelog: test behaviour for data starting with "\1\n"

Nicolas Dumazet nicdumz at gmail.com
Thu Jul 8 22:14:48 CDT 2010


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1278323026 -32400
# Branch stable
# Node ID ec8a19680c658188fa97cc726aefeb2a25bc5060
# Parent  04a22b42c8d77e01c772d74bab7f065824e955ba
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.

diff --git a/mercurial/filelog.py b/mercurial/filelog.py
--- a/mercurial/filelog.py
+++ b/mercurial/filelog.py
@@ -53,6 +53,7 @@
         if self.renamed(node):
             return len(self.read(node))
 
+        # XXX self.read(node).startswith("\1\n"), this returns (size+4)
         return revlog.revlog.size(self, rev)
 
     def cmp(self, node, text):
diff --git a/tests/test-filelog b/tests/test-filelog
new file mode 100644
--- /dev/null
+++ b/tests/test-filelog
@@ -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.'
diff --git a/tests/test-filelog.out b/tests/test-filelog.out
new file mode 100644
--- /dev/null
+++ b/tests/test-filelog.out
@@ -0,0 +1,2 @@
+ERROR: FIXME: This is a known failure of filelog.size for data starting with \1\n
+OK.


More information about the Mercurial-devel mailing list