# HG changeset patch # User Nicolas Dumazet # Date 1278323026 -32400 # Node ID 2370e270a29a34c2e7f9fb22270bc6d6a6da55c8 # Parent a463e3c50212c6b2249fb55728425757da6ad8a9 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 -r a463e3c50212 -r 2370e270a29a mercurial/filelog.py --- 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): diff -r a463e3c50212 -r 2370e270a29a tests/test-filelog --- /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.' diff -r a463e3c50212 -r 2370e270a29a tests/test-filelog.out --- /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.