tests/test-rust-revlog.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Sat, 16 May 2020 20:38:31 +0200
branchstable
changeset 44912 4234c9af515d
parent 44012 443dc1655923
child 45942 89a2afe31e82
permissions -rw-r--r--
flags: read flag from dirstate/disk for workingcopyctx (issue5743) In 491855ea9d62, various piece of code are moved from committablectx to workingctx. The reason given is "These read from the dirstate, so they shouldn't be used in other subclasses." At least for `flags` this change introduce a bug, because the value flags end up being read from `_manifest` disregarding the actual state in the working copy (ie: on disk). When merging exec flag change with renames, this means a new files (the local content, renamed) is properly written on disk, with the right flags, but the flags part is later ignored when actually reading flags during merge. It is not clear to me why the `flags` function was moved, because the code does not actually hit the dirstate (the reason given in the changeset description). So I am moving it back to were it comes from and we use a simpler version of that code (that hit the dirstate everytime) in workingcopyctx. This fix the last know bug with merging rename and executable byte changes. Other similar bug might be lurking in 491855ea9d62, but I have not investigated them. Differential Revision: https://phab.mercurial-scm.org/D8534

from __future__ import absolute_import
import unittest

try:
    from mercurial import rustext

    rustext.__name__  # trigger immediate actual import
except ImportError:
    rustext = None
else:
    from mercurial.rustext import revlog

    # this would fail already without appropriate ancestor.__package__
    from mercurial.rustext.ancestor import LazyAncestors

from mercurial.testing import revlog as revlogtesting


@unittest.skipIf(
    rustext is None, "rustext module revlog relies on is not available",
)
class RustRevlogIndexTest(revlogtesting.RevlogBasedTestBase):
    def test_heads(self):
        idx = self.parseindex()
        rustidx = revlog.MixedIndex(idx)
        self.assertEqual(rustidx.headrevs(), idx.headrevs())

    def test_get_cindex(self):
        # drop me once we no longer need the method for shortest node
        idx = self.parseindex()
        rustidx = revlog.MixedIndex(idx)
        cidx = rustidx.get_cindex()
        self.assertTrue(idx is cidx)

    def test_len(self):
        idx = self.parseindex()
        rustidx = revlog.MixedIndex(idx)
        self.assertEqual(len(rustidx), len(idx))

    def test_ancestors(self):
        idx = self.parseindex()
        rustidx = revlog.MixedIndex(idx)
        lazy = LazyAncestors(rustidx, [3], 0, True)
        # we have two more references to the index:
        # - in its inner iterator for __contains__ and __bool__
        # - in the LazyAncestors instance itself (to spawn new iterators)
        self.assertTrue(2 in lazy)
        self.assertTrue(bool(lazy))
        self.assertEqual(list(lazy), [3, 2, 1, 0])
        # a second time to validate that we spawn new iterators
        self.assertEqual(list(lazy), [3, 2, 1, 0])

        # let's check bool for an empty one
        self.assertFalse(LazyAncestors(idx, [0], 0, False))


if __name__ == '__main__':
    import silenttestrunner

    silenttestrunner.main(__name__)