topic: fix compatibility issues caused because of change in transaction API
In 36f08ae87ef687be53a59bd87376bcfbe4479205 in core mercurial, `_validator`
attribute to transaction class was removed and a dict was introduced. It added a
`addvalidator()` function to transaction class which can be used to register
multiple validator callbacks.
This updates the code to use `addvalidator()` when `_validator` attribute is not
present.
--- a/hgext3rd/topic/__init__.py Wed Mar 11 16:11:04 2020 +0700
+++ b/hgext3rd/topic/__init__.py Thu Mar 19 20:09:18 2020 +0530
@@ -483,18 +483,27 @@
if self.ui.configbool(b'experimental', b'enforce-single-head'):
if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
origvalidator = tr.validator
+ elif util.safehasattr(tr, '_validator'):
+ # hg <= 5.3 (36f08ae87ef6)
+ origvalidator = tr._validator
else:
- origvalidator = tr._validator
+ origvalidator = None
+
+ def _validate(tr2):
+ repo = reporef()
+ flow.enforcesinglehead(repo, tr2)
def validator(tr2):
- repo = reporef()
- flow.enforcesinglehead(repo, tr2)
+ _validate(tr2)
origvalidator(tr2)
if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
tr.validator = validator
+ elif util.safehasattr(tr, '_validator'):
+ # hg <= 5.3 (36f08ae87ef6)
+ tr._validator = validator
else:
- tr._validator = validator
+ tr.addvalidator(b'000-enforce-single-head', _validate)
topicmodeserver = self.ui.config(b'experimental',
b'topic-mode.server', b'ignore')
@@ -502,17 +511,27 @@
if (topicmodeserver != b'ignore' and ispush):
if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
origvalidator = tr.validator
- else:
+ elif util.safehasattr(tr, '_validator'):
+ # hg <= 5.3 (36f08ae87ef6)
origvalidator = tr._validator
+ else:
+ origvalidator = None
- def validator(tr2):
+ def _validate(tr2):
repo = reporef()
flow.rejectuntopicedchangeset(repo, tr2)
+
+ def validator(tr2):
+ _validate(tr2)
return origvalidator(tr2)
+
if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
tr.validator = validator
+ elif util.safehasattr(tr, '_validator'):
+ # hg <= 5.3 (36f08ae87ef6)
+ tr._validator = validator
else:
- tr._validator = validator
+ tr.addvalidator(b'000-reject-untopiced', _validate)
elif (self.ui.configbool(b'experimental', b'topic.publish-bare-branch')
and (desc.startswith(b'push')
@@ -533,17 +552,27 @@
if not allow_publish:
if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
origvalidator = tr.validator
- else:
+ elif util.safehasattr(tr, '_validator'):
+ # hg <= 5.3 (36f08ae87ef6)
origvalidator = tr._validator
+ else:
+ origvalidator = None
- def validator(tr2):
+ def _validate(tr2):
repo = reporef()
flow.reject_publish(repo, tr2)
+
+ def validator(tr2):
+ _validate(tr2)
return origvalidator(tr2)
+
if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
tr.validator = validator
+ elif util.safehasattr(tr, '_validator'):
+ # hg <= 5.3 (36f08ae87ef6)
+ tr._validator = validator
else:
- tr._validator = validator
+ tr.addvalidator(b'000-reject-publish', _validate)
# real transaction start
ct = self.currenttopic
--- a/hgext3rd/topic/discovery.py Wed Mar 11 16:11:04 2020 +0700
+++ b/hgext3rd/topic/discovery.py Thu Mar 19 20:09:18 2020 +0530
@@ -159,10 +159,11 @@
reporef = weakref.ref(op.repo)
if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
oldvalidator = tr.validator
- else:
+ elif util.safehasattr(tr, '_validator'):
+ # hg <= 5.3 (36f08ae87ef6)
oldvalidator = tr._validator
- def validator(tr):
+ def _validate(tr):
repo = reporef()
if repo is not None:
repo.invalidatecaches()
@@ -177,11 +178,19 @@
msg = _(b'push create more than 1 head on new branch "%s"'
% branch)
raise error.Abort(msg)
+
+ def validator(tr):
+ _validate(tr)
return oldvalidator(tr)
+
if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
tr.validator = validator
+ elif util.safehasattr(tr, '_validator'):
+ # hg <= 5.3 (36f08ae87ef6)
+ tr._validator = validator
else:
- tr._validator = validator
+ tr.addvalidator(b'000-new-head-check', _validate)
+
handlecheckheads.params = frozenset()
def _pushb2phases(orig, pushop, bundler):