changeset 6574:054a7c342463

topic: use distinct names for distinct origvalidator and _validate() Here, the same topicrepo.transaction method, we set up various transaction validators. On older hg versions (5.3 and older) this involves storing the original transaction validator (i.e. tr._validator function) and creating a wrapper function to use as the replacement. In cases when multiple topic-related validators were needed, the code used to store tr._validator multiple times, and create a wrapper function that used origvalidator multiple times as well. In such cases we can no longer use the same names for the functions/variables, as they are used inside multiple validator functions, but are going to be overridden by later assignments/definitions (due to the shared names), since it's done in the scope of the same topicrepo.transaction(). Names can be better, but it'll do for now, and at some point we'll simply drop compatibility for 5.3, which should happen relatively soon.
author Anton Shestakov <av6@dwimlabs.net>
date Sat, 14 Oct 2023 15:53:40 -0300
parents d511eba4cdb0
children 1ecb25d771df
files hgext3rd/topic/__init__.py
diffstat 1 files changed, 20 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Sun Oct 15 16:59:25 2023 -0300
+++ b/hgext3rd/topic/__init__.py	Sat Oct 14 15:53:40 2023 -0300
@@ -801,21 +801,21 @@
             if self.ui.configbool(b'experimental', b'enforce-single-head'):
                 if util.safehasattr(tr, '_validator'):
                     # hg <= 5.3 (36f08ae87ef6)
-                    origvalidator = tr._validator
+                    origvalidator_single_head = tr._validator
 
-                def _validate(tr2):
+                def _validate_single_head(tr2):
                     repo = reporef()
                     flow.enforcesinglehead(repo, tr2)
 
                 def validator(tr2):
-                    _validate(tr2)
-                    return origvalidator(tr2)
+                    _validate_single_head(tr2)
+                    return origvalidator_single_head(tr2)
 
                 if util.safehasattr(tr, '_validator'):
                     # hg <= 5.3 (36f08ae87ef6)
                     tr._validator = validator
                 else:
-                    tr.addvalidator(b'000-enforce-single-head', _validate)
+                    tr.addvalidator(b'000-enforce-single-head', _validate_single_head)
 
             topicmodeserver = self.ui.config(b'experimental',
                                              b'topic-mode.server', b'ignore')
@@ -825,21 +825,21 @@
             if (topicmodeserver != b'ignore' and ispush):
                 if util.safehasattr(tr, '_validator'):
                     # hg <= 5.3 (36f08ae87ef6)
-                    origvalidator = tr._validator
+                    origvalidator_untopiced = tr._validator
 
-                def _validate(tr2):
+                def _validate_untopiced(tr2):
                     repo = reporef()
                     flow.rejectuntopicedchangeset(repo, tr2)
 
                 def validator(tr2):
-                    _validate(tr2)
-                    return origvalidator(tr2)
+                    _validate_untopiced(tr2)
+                    return origvalidator_untopiced(tr2)
 
                 if util.safehasattr(tr, '_validator'):
                     # hg <= 5.3 (36f08ae87ef6)
                     tr._validator = validator
                 else:
-                    tr.addvalidator(b'000-reject-untopiced', _validate)
+                    tr.addvalidator(b'000-reject-untopiced', _validate_untopiced)
 
             elif publishbare and ispush:
                 origclose = tr.close
@@ -857,40 +857,40 @@
             if not allow_publish:
                 if util.safehasattr(tr, '_validator'):
                     # hg <= 5.3 (36f08ae87ef6)
-                    origvalidator = tr._validator
+                    origvalidator_publish = tr._validator
 
-                def _validate(tr2):
+                def _validate_publish(tr2):
                     repo = reporef()
                     flow.reject_publish(repo, tr2)
 
                 def validator(tr2):
-                    _validate(tr2)
-                    return origvalidator(tr2)
+                    _validate_publish(tr2)
+                    return origvalidator_publish(tr2)
 
                 if util.safehasattr(tr, '_validator'):
                     # hg <= 5.3 (36f08ae87ef6)
                     tr._validator = validator
                 else:
-                    tr.addvalidator(b'000-reject-publish', _validate)
+                    tr.addvalidator(b'000-reject-publish', _validate_publish)
 
             if util.safehasattr(tr, '_validator'):
                 # hg <= 5.3 (36f08ae87ef6)
-                origvalidator = tr._validator
+                origvalidator_affected_tns = tr._validator
 
-            def _validate(tr2):
+            def _validate_affected_tns(tr2):
                 repo = reporef()
                 find_affected_tns(repo, tr2)
 
             def validator(tr2):
-                result = origvalidator(tr2)
-                _validate(tr2)
+                result = origvalidator_affected_tns(tr2)
+                _validate_affected_tns(tr2)
                 return result
 
             if util.safehasattr(tr, '_validator'):
                 # hg <= 5.3 (36f08ae87ef6)
                 tr._validator = validator
             else:
-                tr.addvalidator(b'000-find-affected-tns', _validate)
+                tr.addvalidator(b'999-find-affected-tns', _validate_affected_tns)
 
             # real transaction start
             ct = self.currenttopic