# HG changeset patch # User Jun Wu # Date 1502154736 25200 # Node ID fbc22592f4fa63e386f9ff0daf587b1dc259f558 # Parent 106716ed2ed09a8370881ac5b992022213147836 push: lock repo before calling createmarkers Previously, when devel.all-warnings is set to True, hg subversion will crash when pushing with the error: ProgrammingError: transaction requires locking Tracking that down, that is because "createmarkers" was called without locking. A comprehensive test was added to run test_push_command with obsstore turned on to cover the code paths. diff --git a/hgsubversion/wrappers.py b/hgsubversion/wrappers.py --- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -351,17 +351,18 @@ def push(repo, dest, force, revs): finally: util.swap_out_encoding() - if hasobsolete: - for marker in obsmarkers: - obsolete.createmarkers(repo, marker) - beforepush = marker[0][0] - afterpush = marker[0][1][0] - ui.note('marking %s as obsoleted by %s\n' % - (beforepush.hex(), afterpush.hex())) - else: - # strip the original changesets since the push was - # successful and changeset obsolescence is unavailable - util.strip(ui, repo, outgoing, "all") + with repo.lock(): + if hasobsolete: + for marker in obsmarkers: + obsolete.createmarkers(repo, marker) + beforepush = marker[0][0] + afterpush = marker[0][1][0] + ui.note('marking %s as obsoleted by %s\n' % + (beforepush.hex(), afterpush.hex())) + else: + # strip the original changesets since the push was + # successful and changeset obsolescence is unavailable + util.strip(ui, repo, outgoing, "all") finally: try: # It's always safe to delete the temporary commits. @@ -373,11 +374,12 @@ def push(repo, dest, force, revs): parent = repo[None].p1() if parent.node() in temporary_commits: hg.update(repo, parent.p1().node()) - if hasobsolete: - relations = ((repo[n], ()) for n in temporary_commits) - obsolete.createmarkers(repo, relations) - else: - util.strip(ui, repo, temporary_commits, backup=None) + with repo.lock(): + if hasobsolete: + relations = ((repo[n], ()) for n in temporary_commits) + obsolete.createmarkers(repo, relations) + else: + util.strip(ui, repo, temporary_commits, backup=None) finally: util.swap_out_encoding(old_encoding) diff --git a/tests/comprehensive/test_obsstore_on.py b/tests/comprehensive/test_obsstore_on.py new file mode 100644 --- /dev/null +++ b/tests/comprehensive/test_obsstore_on.py @@ -0,0 +1,40 @@ +import os +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 + +import test_push_command + + +class ObsstoreOnMixIn(object): + # do not double the test size by being wrapped again + obsolete_mode_tests = False + stupid_mode_tests = False + + def setUp(self): + super(ObsstoreOnMixIn, self).setUp() + hgrcpath = os.environ.get('HGRCPATH') + assert hgrcpath + with open(hgrcpath, 'a') as f: + f.write('\n[experimental]\nevolution=createmarkers\n') + + def shortDescription(self): + text = super(ObsstoreOnMixIn, self).shortDescription() + if text: + text += ' (obsstore on)' + return text + + +def buildtestclass(cls): + name = 'ObsstoreOn%s' % cls.__name__ + newcls = type(name, (ObsstoreOnMixIn, cls,), {}) + globals()[name] = newcls + + +buildtestclass(test_push_command.PushTests)