Patchwork [4,of,4,V2] fileset: replace predicate by filesetpredicate of registrar (API)

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 10, 2016, 8:21 p.m.
Message ID <5ba1632b208bd05af7e9.1457641271@feefifofum>
Download mbox | patch
Permalink /patch/13746/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - March 10, 2016, 8:21 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1457637294 -32400
#      Fri Mar 11 04:14:54 2016 +0900
# Node ID 5ba1632b208bd05af7e9cf93b5807f76e63bec13
# Parent  a212da83e652322b4969f098b8cd398dcd905ba9
fileset: replace predicate by filesetpredicate of registrar (API)

To make all built-in predicates be known to hggettext, loading
built-in predicates by loadpredicate() should be placed before fixing
i18nfunctions but after all of predicate decorating.
Pierre-Yves David - March 10, 2016, 10:45 p.m.
On 03/10/2016 08:21 PM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1457637294 -32400
> #      Fri Mar 11 04:14:54 2016 +0900
> # Node ID 5ba1632b208bd05af7e9cf93b5807f76e63bec13
> # Parent  a212da83e652322b4969f098b8cd398dcd905ba9
> fileset: replace predicate by filesetpredicate of registrar (API)
>
> To make all built-in predicates be known to hggettext, loading
> built-in predicates by loadpredicate() should be placed before fixing
> i18nfunctions but after all of predicate decorating.

Pushed to the clowncopter, thanks.

Patch

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -14,6 +14,7 @@  from . import (
     error,
     merge,
     parser,
+    registrar,
     util,
 )
 
@@ -144,34 +145,7 @@  symbols = {}
 # filesets using matchctx.existing()
 _existingcallers = set()
 
-def predicate(decl, callstatus=False, callexisting=False):
-    """Return a decorator for fileset predicate function
-
-    'decl' argument is the declaration (including argument list like
-    'adds(pattern)') or the name (for internal use only) of predicate.
-
-    Optional 'callstatus' argument indicates whether predicate implies
-    'matchctx.status()' at runtime or not (False, by default).
-
-    Optional 'callexisting' argument indicates whether predicate
-    implies 'matchctx.existing()' at runtime or not (False, by
-    default).
-    """
-    def decorator(func):
-        i = decl.find('(')
-        if i > 0:
-            name = decl[:i]
-        else:
-            name = decl
-        symbols[name] = func
-        if callstatus:
-            _statuscallers.add(name)
-        if callexisting:
-            _existingcallers.add(name)
-        if func.__doc__:
-            func.__doc__ = "``%s``\n    %s" % (decl, func.__doc__.strip())
-        return func
-    return decorator
+predicate = registrar.filesetpredicate()
 
 @predicate('modified()', callstatus=True)
 def modified(mctx, x):
@@ -570,5 +544,8 @@  def loadpredicate(ui, extname, registrar
         if func._callexisting:
             _existingcallers.add(name)
 
+# load built-in predicates explicitly to setup _statuscallers/_existingcallers
+loadpredicate(None, None, predicate)
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()