##// END OF EJS Templates
templater: add separate() template function...
Martin von Zweigbergk -
r29085:df838803 default
parent child Browse files
Show More
@@ -81,6 +81,10 b' Some sample command line templates:'
81
81
82 $ hg log -r 0 --template "files: {join(files, ', ')}\n"
82 $ hg log -r 0 --template "files: {join(files, ', ')}\n"
83
83
84 - Separate non-empty arguments by a " "::
85
86 $ hg log -r 0 --template "{separate(' ', node, bookmarks, tags}\n"
87
84 - Modify each line of a commit description::
88 - Modify each line of a commit description::
85
89
86 $ hg log --template "{splitlines(desc) % '**** {line}\n'}"
90 $ hg log --template "{splitlines(desc) % '**** {line}\n'}"
@@ -724,6 +724,25 b' def rstdoc(context, mapping, args):'
724
724
725 return minirst.format(text, style=style, keep=['verbose'])
725 return minirst.format(text, style=style, keep=['verbose'])
726
726
727 @templatefunc('separate(sep, args)')
728 def separate(context, mapping, args):
729 """Add a separator between non-empty arguments."""
730 if not args:
731 # i18n: "separate" is a keyword
732 raise error.ParseError(_("separate expects at least one argument"))
733
734 sep = evalstring(context, mapping, args[0])
735 first = True
736 for arg in args[1:]:
737 argstr = evalstring(context, mapping, arg)
738 if not argstr:
739 continue
740 if first:
741 first = False
742 else:
743 yield sep
744 yield argstr
745
727 @templatefunc('shortest(node, minlength=4)')
746 @templatefunc('shortest(node, minlength=4)')
728 def shortest(context, mapping, args):
747 def shortest(context, mapping, args):
729 """Obtain the shortest representation of
748 """Obtain the shortest representation of
@@ -3320,6 +3320,15 b' Test width argument passed to pad functi'
3320 hg: parse error: pad() expects an integer width
3320 hg: parse error: pad() expects an integer width
3321 [255]
3321 [255]
3322
3322
3323 Test separate function
3324
3325 $ hg log -r 0 -T '{separate("-", "", "a", "b", "", "", "c", "")}\n'
3326 a-b-c
3327 $ hg log -r 0 -T '{separate(" ", "{rev}:{node|short}", author|user, branch)}\n'
3328 0:f7769ec2ab97 test default
3329 $ hg log -r 0 --color=always -T '{separate(" ", "a", label(red, "b"), "c", label(red, ""), "d")}\n'
3330 a \x1b[0;31mb\x1b[0m c d (esc)
3331
3323 Test ifcontains function
3332 Test ifcontains function
3324
3333
3325 $ hg log --template '{rev} {ifcontains(rev, "2 two 0", "is in the string", "is not")}\n'
3334 $ hg log --template '{rev} {ifcontains(rev, "2 two 0", "is in the string", "is not")}\n'
General Comments 0
You need to be logged in to leave comments. Login now