mercurial/templater.py
changeset 34459 a1b89c8ad32d
parent 34353 46f45b7efa30
child 34534 b3073e175c17
--- a/mercurial/templater.py	Sun Oct 01 10:50:00 2017 +0100
+++ b/mercurial/templater.py	Sun Oct 01 11:13:09 2017 +0100
@@ -24,6 +24,7 @@
     registrar,
     revset as revsetmod,
     revsetlang,
+    scmutil,
     templatefilters,
     templatekw,
     util,
@@ -593,6 +594,22 @@
 
     return ''.join(chunks)
 
+@templatefunc('extdata(source)', argspec='source')
+def extdata(context, mapping, args):
+    """Show a text read from the specified extdata source. (EXPERIMENTAL)"""
+    if 'source' not in args:
+        # i18n: "extdata" is a keyword
+        raise error.ParseError(_('extdata expects one argument'))
+
+    source = evalstring(context, mapping, args['source'])
+    cache = mapping['cache'].setdefault('extdata', {})
+    ctx = mapping['ctx']
+    if source in cache:
+        data = cache[source]
+    else:
+        data = cache[source] = scmutil.extdatasource(ctx.repo(), source)
+    return data.get(ctx.rev(), '')
+
 @templatefunc('files(pattern)')
 def files(context, mapping, args):
     """All files of the current changeset matching the pattern. See