diff --git a/mercurial/templater.py b/mercurial/templater.py
index ebc03e64548a5768cfac67a1674b09a23c577491_bWVyY3VyaWFsL3RlbXBsYXRlci5weQ==..bd1f043d1ea3b6f7b54b9d7d317ab2b4d104dc2e_bWVyY3VyaWFsL3RlbXBsYXRlci5weQ== 100644
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -713,6 +713,18 @@
         tzoffset = util.makedate()[1]
     return (date[0], tzoffset)
 
+@templatefunc('relpath(path)')
+def relpath(context, mapping, args):
+    """Convert a repository-absolute path into a filesystem path relative to
+    the current working directory."""
+    if len(args) != 1:
+        # i18n: "relpath" is a keyword
+        raise error.ParseError(_("relpath expects one argument"))
+
+    repo = mapping['ctx'].repo()
+    path = evalstring(context, mapping, args[0])
+    return repo.pathto(path)
+
 @templatefunc('revset(query[, formatargs...])')
 def revset(context, mapping, args):
     """Execute a revision set query. See
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
index ebc03e64548a5768cfac67a1674b09a23c577491_dGVzdHMvdGVzdC1jb21tYW5kLXRlbXBsYXRlLnQ=..bd1f043d1ea3b6f7b54b9d7d317ab2b4d104dc2e_dGVzdHMvdGVzdC1jb21tYW5kLXRlbXBsYXRlLnQ= 100644
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -3521,6 +3521,15 @@
   0
   
 
+Test relpath function
+
+  $ hg log -r0 -T '{files % "{file|relpath}\n"}'
+  a
+  $ cd ..
+  $ hg log -R r -r0 -T '{files % "{file|relpath}\n"}'
+  r/a (glob)
+  $ cd r
+
 Test active bookmark templating
 
   $ hg book foo