diff tests/test-command-template.t @ 20519:cda9d2b6beab

template: add revset() template function Adds a template function that executes a revset and returns the list of revisions as the result. It has the signature 'revset(query [, args...])'. The args are optional and are applied to the query string using the standard python string.format(args) pattern. This allows things like: '{revset("parents({0})", rev)}' to produce the parents of each individual commit in the log output. If no args are specified, the revset result is cached for the duration of the templater; so it's better to not use args if performance is a concern. By itself, revset() can be used to print commit parents, print the common ancestor of a commit with the main branch, etc. It can be used with the ifcontains() function to do things like '{ifcontains(rev, revset('.'), label(...), ...)}' to color the working copy parent, to color certain branches, to color draft commits, etc.
author Durham Goode <durham@fb.com>
date Tue, 11 Feb 2014 21:04:12 -0800
parents 1e43f15a647f
children 5c65ee4193e1
line wrap: on
line diff
--- a/tests/test-command-template.t	Tue Feb 11 21:10:00 2014 -0800
+++ b/tests/test-command-template.t	Tue Feb 11 21:04:12 2014 -0800
@@ -1657,3 +1657,22 @@
   $ hg log --template '{rev} {ifcontains("a", file_adds, "added a", "did not add a")}\n'
   1 did not add a
   0 added a
+
+Test revset function
+
+  $ hg log --template '{rev} {ifcontains(rev, revset("."), "current rev", "not current rev")}\n'
+  1 current rev
+  0 not current rev
+
+  $ hg log --template '{rev} Parents: {revset("parents(%s)", rev)}\n'
+  1 Parents: 0
+  0 Parents: 
+
+  $ hg log --template 'Rev: {rev}\n{revset("::%s", rev) % "Ancestor: {revision}\n"}\n'
+  Rev: 1
+  Ancestor: 0
+  Ancestor: 1
+  
+  Rev: 0
+  Ancestor: 0
+