changeset 29933:91a95ad985d8

revset: add 'takeorder' attribute to mark functions that need ordering flag Since most functions shouldn't need 'order' flag, it is passed only when explicitly required. This avoids large API breakage.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 07 Aug 2016 17:58:50 +0900
parents 09a84e747c88
children 2c6a05b938d8
files mercurial/registrar.py mercurial/revset.py
diffstat 2 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/registrar.py	Sun Aug 07 17:46:12 2016 +0900
+++ b/mercurial/registrar.py	Sun Aug 07 17:58:50 2016 +0900
@@ -108,6 +108,9 @@
     Optional argument 'safe' indicates whether a predicate is safe for
     DoS attack (False by default).
 
+    Optional argument 'takeorder' indicates whether a predicate function
+    takes ordering policy as the last argument.
+
     'revsetpredicate' instance in example above can be used to
     decorate multiple functions.
 
@@ -120,8 +123,9 @@
     _getname = _funcregistrarbase._parsefuncdecl
     _docformat = "``%s``\n    %s"
 
-    def _extrasetup(self, name, func, safe=False):
+    def _extrasetup(self, name, func, safe=False, takeorder=False):
         func._safe = safe
+        func._takeorder = takeorder
 
 class filesetpredicate(_funcregistrarbase):
     """Decorator to register fileset predicate
--- a/mercurial/revset.py	Sun Aug 07 17:46:12 2016 +0900
+++ b/mercurial/revset.py	Sun Aug 07 17:58:50 2016 +0900
@@ -422,7 +422,10 @@
 def func(repo, subset, a, b, order):
     f = getsymbol(a)
     if f in symbols:
-        return symbols[f](repo, subset, b)
+        fn = symbols[f]
+        if getattr(fn, '_takeorder', False):
+            return fn(repo, subset, b, order)
+        return fn(repo, subset, b)
 
     keep = lambda fn: getattr(fn, '__doc__', None) is not None