diff hgext3rd/topic/__init__.py @ 4123:119fced5a891 stable

topic: add a compatibility to access transaction's validator The attribute was made private in ebbba3ba3f66.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 21 Sep 2018 17:50:28 +0200
parents 870c31f85c90
children 23658110ab26
line wrap: on
line diff
--- 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')