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( |
|
|
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( |
|
|
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( |
|
|
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( |
|
|
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( |
|
|
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( |
|
|
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( |
|
|
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( |
|
|
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( |
|
|
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( |
|
|
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( |
|
|
201 | return showlist('file_copy', c, plural='file_copies', **args) | |
|
198 | 202 | |
|
199 |
def showfiledels( |
|
|
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( |
|
|
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( |
|
|
206 |
return showlist( |
|
|
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( |
|
|
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( |
|
|
227 |
return showlist( |
|
|
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' |
General Comments 0
You need to be logged in to leave comments.
Login now