Patchwork [5,of,7] revset: add 'takeorder' attribute to mark functions that need ordering flag

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 13, 2016, 4:13 p.m.
Message ID <fbceee41a25ddcbb81c3.1473783206@mimosa>
Download mbox | patch
Permalink /patch/16605/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 13, 2016, 4:13 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1470560330 -32400
#      Sun Aug 07 17:58:50 2016 +0900
# Node ID fbceee41a25ddcbb81c36489b0b6b183c5e9197f
# Parent  43fea7dc231eb4e162c6665f39d52346ce56843b
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.

Patch

diff --git a/mercurial/registrar.py b/mercurial/registrar.py
--- a/mercurial/registrar.py
+++ b/mercurial/registrar.py
@@ -108,6 +108,9 @@  class revsetpredicate(_funcregistrarbase
     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 @@  class revsetpredicate(_funcregistrarbase
     _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
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -422,7 +422,10 @@  def keyvaluepair(repo, subset, k, v):
 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