Mercurial > hgsubversion
view tests/comprehensive/test_sqlite_revmap.py @ 1550:67b28d657f62
sqliterevmap: break ".hashes()" cycle in a safer way
The `fromsvn()` revset implementation could cause weakref error when using
sqliterevmap like:
File "hgsubversion/util.py", line 357, in <lambda>
return subset.filter(lambda r: tonode(r) in hashes)
File "hgsubversion/maps.py", line 542, in __contains__
return self.get(key) != None
File "hgsubversion/maps.py", line 533, in get
for row in self.revmap._query(
ReferenceError: weakly-referenced object no longer exists
Basically the seemingly harmless assignment could break surprisingly:
# dangerous: `hashes` does not have a reference of `meta.revmap` and may
# become unavailable after `meta`, `revmap` being released by refcount.
hashes = meta.revmap.hashes()
The above syntax is nice to support while avoiding cycles is also nice.
This patch removes `revmap._hashes` so the revmap no longer owns a reference
of a `ReverseRevMap` object so the `ReverseRevMap` object no longer needs to
use weakref for `self.revmap`.
This could actually be caught by `comprehensive/test_sqlite_revmap.py`.
I was not careful enough verifying the "fromsvn()" patch.
author | Jun Wu <quark@fb.com> |
---|---|
date | Thu, 21 Dec 2017 17:39:52 -0800 |
parents | f21605bcda24 |
children |
line wrap: on
line source
import os import unittest import sys # wrapped in a try/except because of weirdness in how # run.py works as compared to nose. try: import test_util except ImportError: sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) import test_util # interesting and fast tests import test_fetch_mappings import test_fetch_renames import test_pull import test_template_keywords import test_utility_commands # comprehensive tests try: import test_custom_layout except ImportError: sys.path.insert(0, os.path.dirname(__file__)) import test_custom_layout import test_rebuildmeta import test_updatemeta from hgsubversion import svnmeta, maps class SqliteRevMapMixIn(object): # do not double the test size by being wrapped again obsolete_mode_tests = False stupid_mode_tests = False def setUp(self): assert svnmeta.SVNMeta._defaultrevmapclass is maps.RevMap svnmeta.SVNMeta._defaultrevmapclass = maps.SqliteRevMap super(SqliteRevMapMixIn, self).setUp() def tearDown(self): assert svnmeta.SVNMeta._defaultrevmapclass is maps.SqliteRevMap svnmeta.SVNMeta._defaultrevmapclass = maps.RevMap super(SqliteRevMapMixIn, self).tearDown() def shortDescription(self): text = super(SqliteRevMapMixIn, self).shortDescription() if text: text += ' (sqlite revmap)' return text def buildtestclass(cls, selector=None): name = 'SqliteRevMap%s' % cls.__name__ newcls = type(name, (SqliteRevMapMixIn, cls,), {}) # remove test cases not selected by selector if selector: for name in dir(newcls): if name.startswith('test_') and not selector(name[5:]): setattr(newcls, name, None) globals()[name] = newcls def svndumpselector(name): return name in ['branch_rename_to_trunk', 'tag_name_same_as_branch'] buildtestclass(test_fetch_mappings.MapTests) buildtestclass(test_fetch_renames.TestFetchRenames) buildtestclass(test_pull.TestPull) buildtestclass(test_template_keywords.TestLogKeywords) buildtestclass(test_utility_commands.UtilityTests) buildtestclass(test_rebuildmeta.RebuildMetaTests, svndumpselector) buildtestclass(test_updatemeta.UpdateMetaTests, svndumpselector)