Patchwork [1,of,8] templater: add ctx convenience function

login
register
mail settings
Submitter timeless@mozdev.org
Date Sept. 11, 2015, 3:36 a.m.
Message ID <404f89e718a2866eaed6.1441942599@waste.org>
Download mbox | patch
Permalink /patch/10478/
State Rejected
Headers show

Comments

timeless@mozdev.org - Sept. 11, 2015, 3:36 a.m.
# HG changeset patch
# User timeless@mozdev.org
# Date 1441936103 14400
#      Thu Sep 10 21:48:23 2015 -0400
# Node ID 404f89e718a2866eaed6eef778b9eafe00f1f9ae
# Parent  ea489d94e1dc1fc3dc1dcbef1c86c18c49605ed1
templater: add ctx convenience function

takes: func, context, mapping, args
returns: ctx, repo

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -544,6 +544,16 @@ 
         tzoffset = util.makedate()[1]
     return (date[0], tzoffset)
 
+def ctxrepo(func, context, mapping, args):
+    if not len(args) == 1:
+        raise error.ParseError(_("%s expects one argument") % func)
+    raw = stringify(args[0][0](context, mapping, args[0][1]))
+    rev = raw
+    ctx = mapping['ctx']
+    repo = ctx.repo()
+    ctx = repo[rev]
+    return ctx, repo
+
 def revset(context, mapping, args):
     """:revset(query[, formatargs...]): Execute a revision set query. See
     :hg:`help revset`."""