| 1 |
#!/usr/bin/env python3 |
| 2 |
""" |
| 3 |
Tests the behavior of filelog w.r.t. data starting with '\1\n' |
| 4 |
""" |
| 5 |
|
| 6 |
from mercurial.node import hex |
| 7 |
from mercurial import ( |
| 8 |
ui as uimod, |
| 9 |
) |
| 10 |
from mercurial.repo import factory |
| 11 |
|
| 12 |
myui = uimod.ui.load() |
| 13 |
repo = factory.repository(myui, path=b'.', create=True) |
| 14 |
|
| 15 |
filename = b'foobar' |
| 16 |
|
| 17 |
|
| 18 |
def addrev(text, renamed=False): |
| 19 |
if renamed: |
| 20 |
# data doesn't matter. Just make sure filelog.renamed() returns True |
| 21 |
meta = {b'copyrev': hex(repo.nullid), b'copy': b'bar'} |
| 22 |
else: |
| 23 |
meta = {} |
| 24 |
|
| 25 |
lock = t = None |
| 26 |
try: |
| 27 |
lock = repo.lock() |
| 28 |
t = repo.transaction(b'commit') |
| 29 |
fl = repo.file(b'foobar', writable=True) |
| 30 |
node = fl.add(text, meta, t, 0, repo.nullid, repo.nullid) |
| 31 |
return node |
| 32 |
finally: |
| 33 |
if t: |
| 34 |
t.close() |
| 35 |
if lock: |
| 36 |
lock.release() |
| 37 |
|
| 38 |
|
| 39 |
def error(text): |
| 40 |
print('ERROR: ' + text) |
| 41 |
|
| 42 |
|
| 43 |
textwith = b'\1\nfoo' |
| 44 |
without = b'foo' |
| 45 |
|
| 46 |
node = addrev(textwith) |
| 47 |
fl = repo.file(b'foobar') |
| 48 |
if not textwith == fl.read(node): |
| 49 |
error('filelog.read for data starting with \\1\\n') |
| 50 |
if fl.cmp(node, textwith) or not fl.cmp(node, without): |
| 51 |
error('filelog.cmp for data starting with \\1\\n') |
| 52 |
if fl.size(0) != len(textwith): |
| 53 |
error('filelog.size for data starting with \\1\\n') |
| 54 |
|
| 55 |
node = addrev(textwith, renamed=True) |
| 56 |
fl = repo.file(b'foobar') |
| 57 |
if not textwith == fl.read(node): |
| 58 |
error('filelog.read for a renaming + data starting with \\1\\n') |
| 59 |
if fl.cmp(node, textwith) or not fl.cmp(node, without): |
| 60 |
error('filelog.cmp for a renaming + data starting with \\1\\n') |
| 61 |
if fl.size(1) != len(textwith): |
| 62 |
error('filelog.size for a renaming + data starting with \\1\\n') |
| 63 |
|
| 64 |
print('OK.') |