From patchwork Tue Sep 13 16:13:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [5, of, 7] revset: add 'takeorder' attribute to mark functions that need ordering flag From: Yuya Nishihara X-Patchwork-Id: 16605 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Wed, 14 Sep 2016 01:13:26 +0900 # HG changeset patch # User Yuya Nishihara # 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. 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