[PATCH 4 of 5] extdata: add basic template support

Matt Mackall mpm at selenic.com
Thu Sep 22 14:21:38 EDT 2016


# HG changeset patch
# User Matt Mackall <mpm at selenic.com>
# Date 1474294560 18000
#      Mon Sep 19 09:16:00 2016 -0500
# Node ID 6db1b2e7d19ed317404c1275db46780d40ececb8
# Parent  133b35066bef5d9c31d13c4f0b2e4a50d1ceae87
extdata: add basic template support

This lets us expose the per-entry "freeform data".

Again, the registrar framework isn't a good fit.

diff -r 133b35066bef -r 6db1b2e7d19e mercurial/templater.py
--- a/mercurial/templater.py	Mon Sep 19 09:13:11 2016 -0500
+++ b/mercurial/templater.py	Mon Sep 19 09:16:00 2016 -0500
@@ -19,6 +19,7 @@
     parser,
     registrar,
     revset as revsetmod,
+    scmutil,
     templatefilters,
     templatekw,
     util,
@@ -352,6 +353,13 @@
         try:
             v = context.process(key, safemapping)
         except TemplateNotFound:
+            # check for extdata last
+            if 'ctx' in mapping:
+                ctx = mapping['ctx']
+                repo = ctx.repo()
+                if key in scmutil.extdatasources(repo):
+                    extdata = scmutil.extdatasource(repo, key)
+                    return extdata.get(ctx.rev(), '')
             v = default
     if callable(v):
         return v(**mapping)
diff -r 133b35066bef -r 6db1b2e7d19e tests/test-command-template.t
--- a/tests/test-command-template.t	Mon Sep 19 09:13:11 2016 -0500
+++ b/tests/test-command-template.t	Mon Sep 19 09:16:00 2016 -0500
@@ -3851,6 +3851,23 @@
   abort: bad definition of template alias "bad": at 2: not a prefix: end
   [255]
 
+Template support for extdata:
+
+  $ echo "[extdata]" >> .hg/hgrc
+  $ echo "notes = notes.txt" >> .hg/hgrc
+  $ echo "b608 this change is great!" > notes.txt
+  $ echo "10e4 this is buggy :(" >> notes.txt
+  $ echo "1e4e first post" >> notes.txt
+  $ echo "bogusnode gives no error" >> notes.txt
+  $ hg log -T "{node|short} {author} {if(notes, '# {notes}')}\n"
+  d41e714fe50d person 
+  13207e5a10d9 person 
+  bbe44766e73d person 
+  10e46f2dcbf4 person # this is buggy :(
+  97054abb4ab8 other at place 
+  b608e9d1a3f0 A. N. Other <other at place> # this change is great!
+  1e4e1b8f71e0 User Name <user at hostname> # first post
+
   $ cd ..
 
 Set up repository for non-ascii encoding tests:


More information about the Mercurial-devel mailing list