revset: add 'takeorder' attribute to mark functions that need ordering flag
authorYuya Nishihara <yuya@tcha.org>
Sun, 07 Aug 2016 17:58:50 +0900
changeset 29933 91a95ad985d8
parent 29932 09a84e747c88
child 29934 2c6a05b938d8
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.
mercurial/registrar.py
mercurial/revset.py
--- 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