##// END OF EJS Templates
templatekw: fix extras, manifest and showlist args (issue1989)...
Patrick Mezard -
r10260:fe699ca0 default
parent child Browse files
Show More
@@ -806,10 +806,11 b' class changeset_templater(changeset_prin'
806 806 # causes unexpected behaviours at templating level and makes
807 807 # it harder to extract it in a standalone function. Its
808 808 # behaviour cannot be changed so leave it here for now.
809 def showparents(repo, ctx, templ, **args):
809 def showparents(**args):
810 ctx = args['ctx']
810 811 parents = [[('rev', p.rev()), ('node', p.hex())]
811 812 for p in self._meaningful_parentrevs(ctx)]
812 return showlist(templ, 'parent', parents, **args)
813 return showlist('parent', parents, **args)
813 814
814 815 props = props.copy()
815 816 props.update(templatekw.keywords)
@@ -8,7 +8,7 b''
8 8 from node import hex
9 9 import encoding, patch, util, error
10 10
11 def showlist(templ, name, values, plural=None, **args):
11 def showlist(name, values, plural=None, **args):
12 12 '''expand set of values.
13 13 name is name of key in template map.
14 14 values is list of strings or dicts.
@@ -28,6 +28,7 b' def showlist(templ, name, values, plural'
28 28
29 29 expand 'end_foos'.
30 30 '''
31 templ = args['templ']
31 32 if plural: names = plural
32 33 else: names = name + 's'
33 34 if not values:
@@ -143,11 +144,11 b' def getrenamedfn(repo, endrev=None):'
143 144 def showauthor(repo, ctx, templ, **args):
144 145 return ctx.user()
145 146
146 def showbranches(repo, ctx, templ, **args):
147 branch = ctx.branch()
147 def showbranches(**args):
148 branch = args['ctx'].branch()
148 149 if branch != 'default':
149 150 branch = encoding.tolocal(branch)
150 return showlist(templ, 'branch', [branch], plural='branches', **args)
151 return showlist('branch', [branch], plural='branches', **args)
151 152
152 153 def showdate(repo, ctx, templ, **args):
153 154 return ctx.date()
@@ -164,20 +165,23 b' def showdiffstat(repo, ctx, templ, **arg'
164 165 removes += i[2]
165 166 return '%s: +%s/-%s' % (files, adds, removes)
166 167
167 def showextras(repo, ctx, templ, **args):
168 for key, value in sorted(ctx.extra().items()):
168 def showextras(**args):
169 templ = args['templ']
170 for key, value in sorted(args['ctx'].extra().items()):
169 171 args = args.copy()
170 172 args.update(dict(key=key, value=value))
171 173 yield templ('extra', **args)
172 174
173 def showfileadds(repo, ctx, templ, revcache, **args):
174 return showlist(templ, 'file_add', getfiles(repo, ctx, revcache)[1], **args)
175 def showfileadds(**args):
176 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
177 return showlist('file_add', getfiles(repo, ctx, revcache)[1], **args)
175 178
176 def showfilecopies(repo, ctx, templ, cache, revcache, **args):
177 copies = revcache.get('copies')
179 def showfilecopies(**args):
180 cache, ctx= args['cache'], args['ctx']
181 copies = args['revcache'].get('copies')
178 182 if copies is None:
179 183 if 'getrenamed' not in cache:
180 cache['getrenamed'] = getrenamedfn(repo)
184 cache['getrenamed'] = getrenamedfn(args['repo'])
181 185 copies = []
182 186 getrenamed = cache['getrenamed']
183 187 for fn in ctx.files():
@@ -186,24 +190,26 b' def showfilecopies(repo, ctx, templ, cac'
186 190 copies.append((fn, rename[0]))
187 191
188 192 c = [{'name': x[0], 'source': x[1]} for x in copies]
189 return showlist(templ, 'file_copy', c, plural='file_copies', **args)
193 return showlist('file_copy', c, plural='file_copies', **args)
190 194
191 195 # showfilecopiesswitch() displays file copies only if copy records are
192 196 # provided before calling the templater, usually with a --copies
193 197 # command line switch.
194 def showfilecopiesswitch(repo, ctx, templ, cache, revcache, **args):
195 copies = revcache.get('copies') or []
198 def showfilecopiesswitch(**args):
199 copies = args['revcache'].get('copies') or []
196 200 c = [{'name': x[0], 'source': x[1]} for x in copies]
197 return showlist(templ, 'file_copy', c, plural='file_copies', **args)
201 return showlist('file_copy', c, plural='file_copies', **args)
198 202
199 def showfiledels(repo, ctx, templ, revcache, **args):
200 return showlist(templ, 'file_del', getfiles(repo, ctx, revcache)[2], **args)
203 def showfiledels(**args):
204 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
205 return showlist('file_del', getfiles(repo, ctx, revcache)[2], **args)
201 206
202 def showfilemods(repo, ctx, templ, revcache, **args):
203 return showlist(templ, 'file_mod', getfiles(repo, ctx, revcache)[0], **args)
207 def showfilemods(**args):
208 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
209 return showlist('file_mod', getfiles(repo, ctx, revcache)[0], **args)
204 210
205 def showfiles(repo, ctx, templ, **args):
206 return showlist(templ, 'file', ctx.files(), **args)
211 def showfiles(**args):
212 return showlist('file', args['ctx'].files(), **args)
207 213
208 214 def showlatesttag(repo, ctx, templ, cache, **args):
209 215 return getlatesttags(repo, ctx, cache)[2]
@@ -211,7 +217,8 b' def showlatesttag(repo, ctx, templ, cach'
211 217 def showlatesttagdistance(repo, ctx, templ, cache, **args):
212 218 return getlatesttags(repo, ctx, cache)[1]
213 219
214 def showmanifest(repo, ctx, templ, **args):
220 def showmanifest(**args):
221 repo, ctx, templ = args['repo'], args['ctx'], args['templ']
215 222 args = args.copy()
216 223 args.update(dict(rev=repo.manifest.rev(ctx.changeset()[0]),
217 224 node=hex(ctx.changeset()[0])))
@@ -223,9 +230,17 b' def shownode(repo, ctx, templ, **args):'
223 230 def showrev(repo, ctx, templ, **args):
224 231 return ctx.rev()
225 232
226 def showtags(repo, ctx, templ, **args):
227 return showlist(templ, 'tag', ctx.tags(), **args)
233 def showtags(**args):
234 return showlist('tag', args['ctx'].tags(), **args)
228 235
236 # keywords are callables like:
237 # fn(repo, ctx, templ, cache, revcache, **args)
238 # with:
239 # repo - current repository instance
240 # ctx - the changectx being displayed
241 # templ - the templater instance
242 # cache - a cache dictionary for the whole templater run
243 # revcache - a cache dictionary for the current revision
229 244 keywords = {
230 245 'author': showauthor,
231 246 'branches': showbranches,
@@ -195,4 +195,13 b' style = ~/styles/teststyle'
195 195 EOF
196 196 hg -R latesttag tip
197 197
198 echo '# test recursive showlist template (issue1989)'
199 cat > style1989 <<EOF
200 changeset = '{file_mods}{manifest}{extras}'
201 file_mod = 'M|{author|person}\n'
202 manifest = '{rev},{author}\n'
203 extra = '{key}: {author}\n'
204 EOF
205 hg -R latesttag log -r tip --style=style1989
206
198 207 echo '# done'
@@ -1066,4 +1066,8 b' 1: t1+0'
1066 1066 0: null+1
1067 1067 # style path expansion (issue1948)
1068 1068 test 10:dee8f28249af
1069 # test recursive showlist template (issue1989)
1070 M|test
1071 10,test
1072 branch: test
1069 1073 # done
General Comments 0
You need to be logged in to leave comments. Login now