diff hgext/transplant.py @ 27586:42910f9fffeb

revset: use delayregistrar to register predicate in extension easily Previous patch introduced 'revset.predicate' decorator to register revset predicate function easily. But it shouldn't be used in extension directly, because it registers specified function immediately. Registration itself can't be restored, even if extension loading fails after that. Therefore, registration should be delayed until 'uisetup()' or so. This patch uses 'extpredicate' decorator derived from 'delayregistrar' to register predicate in extension easily. This patch also tests whether 'registrar.delayregistrar' avoids function registration if 'setup()' isn't invoked on it, because 'extpredicate' is the first user of it.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 29 Dec 2015 23:58:30 +0900
parents 43c00ca887d1
children 1c48f348f2d0
line wrap: on
line diff
--- a/hgext/transplant.py	Tue Dec 29 23:58:30 2015 +0900
+++ b/hgext/transplant.py	Tue Dec 29 23:58:30 2015 +0900
@@ -693,9 +693,11 @@
         if cleanupfn:
             cleanupfn()
 
+revsetpredicate = revset.extpredicate()
+
+@revsetpredicate('transplanted([set])')
 def revsettransplanted(repo, subset, x):
-    """``transplanted([set])``
-    Transplanted changesets in set, or all transplanted changesets.
+    """Transplanted changesets in set, or all transplanted changesets.
     """
     if x:
         s = revset.getset(repo, subset, x)
@@ -711,7 +713,7 @@
     return n and revlog.hex(n) or ''
 
 def extsetup(ui):
-    revset.symbols['transplanted'] = revsettransplanted
+    revsetpredicate.setup()
     templatekw.keywords['transplanted'] = kwtransplanted
     cmdutil.unfinishedstates.append(
         ['series', True, False, _('transplant in progress'),