mercurial/templatefuncs.py
changeset 37210 2a2ce93e12f4
parent 37163 0fb28899e81a
child 37224 67efce231633
--- a/mercurial/templatefuncs.py	Fri Mar 30 12:16:46 2018 -0700
+++ b/mercurial/templatefuncs.py	Mon Mar 19 11:16:21 2018 -0400
@@ -26,7 +26,10 @@
     templateutil,
     util,
 )
-from .utils import dateutil
+from .utils import (
+    dateutil,
+    stringutil,
+)
 
 evalrawexp = templateutil.evalrawexp
 evalfuncarg = templateutil.evalfuncarg
@@ -166,6 +169,24 @@
         return node
     return templatefilters.short(node)
 
+@templatefunc('mailmap(author)')
+def mailmap(context, mapping, args):
+    """Return the author, updated according to the value
+    set in the .mailmap file"""
+    if len(args) != 1:
+        raise error.ParseError(_("mailmap expects one argument"))
+
+    author = evalfuncarg(context, mapping, args[0])
+
+    cache = context.resource(mapping, 'cache')
+    repo = context.resource(mapping, 'repo')
+
+    if 'mailmap' not in cache:
+        data = repo.wvfs.tryread('.mailmap')
+        cache['mailmap'] = stringutil.parsemailmap(data)
+
+    return stringutil.mapname(cache['mailmap'], author) or author
+
 @templatefunc('pad(text, width[, fillchar=\' \'[, left=False]])',
               argspec='text width fillchar left')
 def pad(context, mapping, args):