tests/test-parseindex
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
Sun, 23 Mar 2008 21:03:24 -0300
changeset 6370 6440e25a1ba3
parent 3853 c0b449154a90
child 6750 fb42030d79d6
permissions -rwxr-xr-x
localrepo.commit: grab locks before getting the list of files to commit Somebody may change the dirstate after we've determined the parents of the working dir and run repo.status, but before we called wlock(). This should also fix issue997, where backout would change a file without changing its size and then call repo.commit without passing the list of files. If this happened in less than one second, we wouldn't detect any file changes - the in-memory dirstate still has the cached stat data for that file. Grabbing the wlock early causes the dirstate to be invalidated and we end up reading the dirstate file again, which has that file marked for lookup (size == -1). A better fix would be for backout to give repo.commit the exact list of files, but that'll require some changes to the revert operation. A significant user-visible change is that the precommit hook is always run with both locks grabbed - previously, hg commit would run it before grabbing any locks, but hg import would run it after grabbing locks.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2290
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     1
#!/bin/sh
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     2
#
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     3
# revlog.parseindex must be able to parse the index file even if
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     4
# an index entry is split between two 64k blocks.  The ideal test
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     5
# would be to create an index file with inline data where
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     6
# 64k < size < 64k + 64 (64k is the size of the read buffer, 64 is
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     7
# the size of an index entry) and with an index entry starting right
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     8
# before the 64k block boundary, and try to read it.
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     9
#
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    10
# We approximate that by reducing the read buffer to 1 byte.
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    11
#
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    12
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    13
hg init a
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    14
cd a
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    15
echo abc > foo
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    16
hg add foo
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    17
hg commit -m 'add foo' -d '1000000 0'
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    18
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    19
echo >> foo
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    20
hg commit -m 'change foo' -d '1000001 0'
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    21
hg log -r 0:
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    22
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    23
cat >> test.py << EOF
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    24
from mercurial import changelog, util
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    25
from mercurial.node import *
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    26
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    27
class singlebyteread(object):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    28
    def __init__(self, real):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    29
        self.real = real
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    30
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    31
    def read(self, size=-1):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    32
        if size == 65536:
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    33
            size = 1
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    34
        return self.real.read(size)
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    35
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    36
    def __getattr__(self, key):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    37
        return getattr(self.real, key)
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    38
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    39
def opener(*args):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    40
    o = util.opener(*args)
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    41
    def wrapper(*a):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    42
        f = o(*a)
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    43
        return singlebyteread(f)
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    44
    return wrapper
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    45
3853
c0b449154a90 switch to the .hg/store layout, fix the tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2290
diff changeset
    46
cl = changelog.changelog(opener('.hg/store'))
2290
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    47
print cl.count(), 'revisions:'
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    48
for r in xrange(cl.count()):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    49
    print short(cl.node(r))
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    50
EOF
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    51
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    52
python test.py