Patchwork [4,of,6] extensions: add fileset support to exthelper

login
register
mail settings
Submitter Matt Harbison
Date Dec. 1, 2018, 4:10 a.m.
Message ID <9472a31f5d6537265a4a.1543637458@Envy>
Download mbox | patch
Permalink /patch/36889/
State New
Headers show

Comments

Matt Harbison - Dec. 1, 2018, 4:10 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1543633839 18000
#      Fri Nov 30 22:10:39 2018 -0500
# Node ID 9472a31f5d6537265a4a2caa249797e7d8e83046
# Parent  90653b8d51ae02abf8481e1419a8a98f8cbc750e
extensions: add fileset support to exthelper

This will be tested by using it in lfs.

Patch

diff --git a/mercurial/exthelper.py b/mercurial/exthelper.py
--- a/mercurial/exthelper.py
+++ b/mercurial/exthelper.py
@@ -8,6 +8,7 @@  from . import (
     commands,
     configitems,
     extensions,
+    fileset,
     registrar,
     revset,
     templatekw,
@@ -28,6 +29,7 @@  class exthelper(object):
         self._extcallables = []
         self._repocallables = []
         self._revsetsymbols = []
+        self._filesetsymbols = []
         self._templatekws = []
         self._commandwrappers = []
         self._extcommandwrappers = []
@@ -58,6 +60,7 @@  class exthelper(object):
         self._extcallables.extend(other._extcallables)
         self._repocallables.extend(other._repocallables)
         self._revsetsymbols.extend(other._revsetsymbols)
+        self._filesetsymbols.extend(other._filesetsymbols)
         self._templatekws.extend(other._templatekws)
         self._commandwrappers.extend(other._commandwrappers)
         self._extcommandwrappers.extend(other._extcommandwrappers)
@@ -131,6 +134,12 @@  class exthelper(object):
         # TODO: Figure out the calling extension name
         revset.loadpredicate(ui, 'exthelper', revsetpredicate)
 
+        filesetpredicate = registrar.filesetpredicate()
+        for name, symbol in self._filesetsymbols:
+            filesetpredicate(name)(symbol)
+        # TODO: Figure out the calling extension name
+        fileset.loadpredicate(ui, 'exthelper', filesetpredicate)
+
         templatekeyword = registrar.templatekeyword()
         for name, kw, requires in self._templatekws:
             if requires is not None:
@@ -235,6 +244,23 @@  class exthelper(object):
             return symbol
         return dec
 
+    def fileset(self, symbolname):
+        """Decorated function is a fileset symbol
+
+        The name of the symbol must be given as the decorator argument.
+        The symbol is added during `extsetup`.
+
+        example::
+
+            @eh.fileset('lfs()')
+            def filesetbabar(mctx, x):
+                return mctx.predicate(...)
+        """
+        def dec(symbol):
+            self._filesetsymbols.append((symbolname, symbol))
+            return symbol
+        return dec
+
     def templatekw(self, keywordname, requires=None):
         """Decorated function is a template keyword