3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> |
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> |
4 # |
4 # |
5 # This software may be used and distributed according to the terms of the |
5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2, incorporated herein by reference. |
6 # GNU General Public License version 2, incorporated herein by reference. |
7 |
7 |
|
8 import encoding |
8 |
9 |
9 def showlist(templ, name, values, plural=None, **args): |
10 def showlist(templ, name, values, plural=None, **args): |
10 '''expand set of values. |
11 '''expand set of values. |
11 name is name of key in template map. |
12 name is name of key in template map. |
12 values is list of strings or dicts. |
13 values is list of strings or dicts. |
65 yield one(last, tag=lastname) |
66 yield one(last, tag=lastname) |
66 endname = 'end_' + names |
67 endname = 'end_' + names |
67 if endname in templ: |
68 if endname in templ: |
68 yield templ(endname, **args) |
69 yield templ(endname, **args) |
69 |
70 |
|
71 def showauthor(ctx, templ, **args): |
|
72 return ctx.user() |
|
73 |
|
74 def showbranches(ctx, templ, **args): |
|
75 branch = ctx.branch() |
|
76 if branch != 'default': |
|
77 branch = encoding.tolocal(branch) |
|
78 return showlist(templ, 'branch', [branch], plural='branches', **args) |
|
79 |
|
80 def showdate(ctx, templ, **args): |
|
81 return ctx.date() |
|
82 |
|
83 def showdescription(ctx, templ, **args): |
|
84 return ctx.description().strip() |
|
85 |
|
86 def showextras(ctx, templ, **args): |
|
87 for key, value in sorted(ctx.extra().items()): |
|
88 args = args.copy() |
|
89 args.update(dict(key=key, value=value)) |
|
90 yield templ('extra', **args) |
|
91 |
|
92 def showfiles(ctx, templ, **args): |
|
93 return showlist(templ, 'file', ctx.files(), **args) |
|
94 |
|
95 def shownode(ctx, templ, **args): |
|
96 return ctx.hex() |
|
97 |
|
98 def showrev(ctx, templ, **args): |
|
99 return ctx.rev() |
|
100 |
|
101 def showtags(ctx, templ, **args): |
|
102 return showlist(templ, 'tag', ctx.tags(), **args) |
|
103 |
|
104 keywords = { |
|
105 'author': showauthor, |
|
106 'branches': showbranches, |
|
107 'date': showdate, |
|
108 'desc': showdescription, |
|
109 'extras': showextras, |
|
110 'files': showfiles, |
|
111 'node': shownode, |
|
112 'rev': showrev, |
|
113 'tags': showtags, |
|
114 } |
|
115 |