topic: add a compatibility to access transaction's validator stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 21 Sep 2018 17:50:28 +0200
branchstable
changeset 4123 119fced5a891
parent 4121 7f18c7e1e744
child 4124 23658110ab26
topic: add a compatibility to access transaction's validator The attribute was made private in ebbba3ba3f66.
hgext3rd/topic/__init__.py
hgext3rd/topic/discovery.py
--- a/hgext3rd/topic/__init__.py	Fri Sep 21 11:58:42 2018 +0200
+++ b/hgext3rd/topic/__init__.py	Fri Sep 21 17:50:28 2018 +0200
@@ -454,25 +454,38 @@
 
             reporef = weakref.ref(self)
             if self.ui.configbool('experimental', 'enforce-single-head'):
-                origvalidator = tr.validator
+                if util.safehasattr(tr, 'validator'): # hg <= 4.7
+                    origvalidator = tr.validator
+                else:
+                    origvalidator = tr._validator
 
                 def validator(tr2):
                     repo = reporef()
                     flow.enforcesinglehead(repo, tr2)
                     origvalidator(tr2)
-                tr.validator = validator
+
+                if util.safehasattr(tr, 'validator'): # hg <= 4.7
+                    tr.validator = validator
+                else:
+                    tr._validator = validator
 
             topicmodeserver = self.ui.config('experimental',
                                              'topic-mode.server', 'ignore')
             ispush = (desc.startswith('push') or desc.startswith('serve'))
             if (topicmodeserver != 'ignore' and ispush):
-                origvalidator = tr.validator
+                if util.safehasattr(tr, 'validator'): # hg <= 4.7
+                    origvalidator = tr.validator
+                else:
+                    origvalidator = tr._validator
 
                 def validator(tr2):
                     repo = reporef()
                     flow.rejectuntopicedchangeset(repo, tr2)
                     return origvalidator(tr2)
-                tr.validator = validator
+                if util.safehasattr(tr, 'validator'): # hg <= 4.7
+                    tr.validator = validator
+                else:
+                    tr._validator = validator
 
             elif (self.ui.configbool('experimental', 'topic.publish-bare-branch')
                     and (desc.startswith('push')
--- a/hgext3rd/topic/discovery.py	Fri Sep 21 11:58:42 2018 +0200
+++ b/hgext3rd/topic/discovery.py	Fri Sep 21 17:50:28 2018 +0200
@@ -153,7 +153,10 @@
         return
     tr._prepushheads = _nbheads(op.repo)
     reporef = weakref.ref(op.repo)
-    oldvalidator = tr.validator
+    if util.safehasattr(tr, 'validator'): # hg <= 4.7
+        oldvalidator = tr.validator
+    else:
+        oldvalidator = tr._validator
 
     def validator(tr):
         repo = reporef()
@@ -171,7 +174,10 @@
                             % branch)
                     raise error.Abort(msg)
         return oldvalidator(tr)
-    tr.validator = validator
+    if util.safehasattr(tr, 'validator'): # hg <= 4.7
+        tr.validator = validator
+    else:
+        tr._validator = validator
 handlecheckheads.params = frozenset()
 
 def _pushb2phases(orig, pushop, bundler):