Mercurial > hg
comparison mercurial/templatekw.py @ 10260:fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Removing the explicit parameters from keywords signature is easier than copying
and reproducing the original argument list.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Mon, 18 Jan 2010 22:59:32 +0100 |
parents | f780b1098efc |
children | d6512b3e9ac0 |
comparison
equal
deleted
inserted
replaced
10259:8a9651cb2836 | 10260:fe699ca08a45 |
---|---|
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 from node import hex | 8 from node import hex |
9 import encoding, patch, util, error | 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 '''expand set of values. | 12 '''expand set of values. |
13 name is name of key in template map. | 13 name is name of key in template map. |
14 values is list of strings or dicts. | 14 values is list of strings or dicts. |
15 plural is plural of name, if not simply name + 's'. | 15 plural is plural of name, if not simply name + 's'. |
16 | 16 |
26 for each value, expand 'foo'. if 'last_foo' in template | 26 for each value, expand 'foo'. if 'last_foo' in template |
27 map, expand it instead of 'foo' for last key. | 27 map, expand it instead of 'foo' for last key. |
28 | 28 |
29 expand 'end_foos'. | 29 expand 'end_foos'. |
30 ''' | 30 ''' |
31 templ = args['templ'] | |
31 if plural: names = plural | 32 if plural: names = plural |
32 else: names = name + 's' | 33 else: names = name + 's' |
33 if not values: | 34 if not values: |
34 noname = 'no_' + names | 35 noname = 'no_' + names |
35 if noname in templ: | 36 if noname in templ: |
141 | 142 |
142 | 143 |
143 def showauthor(repo, ctx, templ, **args): | 144 def showauthor(repo, ctx, templ, **args): |
144 return ctx.user() | 145 return ctx.user() |
145 | 146 |
146 def showbranches(repo, ctx, templ, **args): | 147 def showbranches(**args): |
147 branch = ctx.branch() | 148 branch = args['ctx'].branch() |
148 if branch != 'default': | 149 if branch != 'default': |
149 branch = encoding.tolocal(branch) | 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 def showdate(repo, ctx, templ, **args): | 153 def showdate(repo, ctx, templ, **args): |
153 return ctx.date() | 154 return ctx.date() |
154 | 155 |
155 def showdescription(repo, ctx, templ, **args): | 156 def showdescription(repo, ctx, templ, **args): |
162 files += 1 | 163 files += 1 |
163 adds += i[1] | 164 adds += i[1] |
164 removes += i[2] | 165 removes += i[2] |
165 return '%s: +%s/-%s' % (files, adds, removes) | 166 return '%s: +%s/-%s' % (files, adds, removes) |
166 | 167 |
167 def showextras(repo, ctx, templ, **args): | 168 def showextras(**args): |
168 for key, value in sorted(ctx.extra().items()): | 169 templ = args['templ'] |
170 for key, value in sorted(args['ctx'].extra().items()): | |
169 args = args.copy() | 171 args = args.copy() |
170 args.update(dict(key=key, value=value)) | 172 args.update(dict(key=key, value=value)) |
171 yield templ('extra', **args) | 173 yield templ('extra', **args) |
172 | 174 |
173 def showfileadds(repo, ctx, templ, revcache, **args): | 175 def showfileadds(**args): |
174 return showlist(templ, 'file_add', getfiles(repo, ctx, revcache)[1], **args) | 176 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
175 | 177 return showlist('file_add', getfiles(repo, ctx, revcache)[1], **args) |
176 def showfilecopies(repo, ctx, templ, cache, revcache, **args): | 178 |
177 copies = revcache.get('copies') | 179 def showfilecopies(**args): |
180 cache, ctx= args['cache'], args['ctx'] | |
181 copies = args['revcache'].get('copies') | |
178 if copies is None: | 182 if copies is None: |
179 if 'getrenamed' not in cache: | 183 if 'getrenamed' not in cache: |
180 cache['getrenamed'] = getrenamedfn(repo) | 184 cache['getrenamed'] = getrenamedfn(args['repo']) |
181 copies = [] | 185 copies = [] |
182 getrenamed = cache['getrenamed'] | 186 getrenamed = cache['getrenamed'] |
183 for fn in ctx.files(): | 187 for fn in ctx.files(): |
184 rename = getrenamed(fn, ctx.rev()) | 188 rename = getrenamed(fn, ctx.rev()) |
185 if rename: | 189 if rename: |
186 copies.append((fn, rename[0])) | 190 copies.append((fn, rename[0])) |
187 | 191 |
188 c = [{'name': x[0], 'source': x[1]} for x in copies] | 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 # showfilecopiesswitch() displays file copies only if copy records are | 195 # showfilecopiesswitch() displays file copies only if copy records are |
192 # provided before calling the templater, usually with a --copies | 196 # provided before calling the templater, usually with a --copies |
193 # command line switch. | 197 # command line switch. |
194 def showfilecopiesswitch(repo, ctx, templ, cache, revcache, **args): | 198 def showfilecopiesswitch(**args): |
195 copies = revcache.get('copies') or [] | 199 copies = args['revcache'].get('copies') or [] |
196 c = [{'name': x[0], 'source': x[1]} for x in copies] | 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): | 203 def showfiledels(**args): |
200 return showlist(templ, 'file_del', getfiles(repo, ctx, revcache)[2], **args) | 204 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
201 | 205 return showlist('file_del', getfiles(repo, ctx, revcache)[2], **args) |
202 def showfilemods(repo, ctx, templ, revcache, **args): | 206 |
203 return showlist(templ, 'file_mod', getfiles(repo, ctx, revcache)[0], **args) | 207 def showfilemods(**args): |
204 | 208 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
205 def showfiles(repo, ctx, templ, **args): | 209 return showlist('file_mod', getfiles(repo, ctx, revcache)[0], **args) |
206 return showlist(templ, 'file', ctx.files(), **args) | 210 |
211 def showfiles(**args): | |
212 return showlist('file', args['ctx'].files(), **args) | |
207 | 213 |
208 def showlatesttag(repo, ctx, templ, cache, **args): | 214 def showlatesttag(repo, ctx, templ, cache, **args): |
209 return getlatesttags(repo, ctx, cache)[2] | 215 return getlatesttags(repo, ctx, cache)[2] |
210 | 216 |
211 def showlatesttagdistance(repo, ctx, templ, cache, **args): | 217 def showlatesttagdistance(repo, ctx, templ, cache, **args): |
212 return getlatesttags(repo, ctx, cache)[1] | 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 args = args.copy() | 222 args = args.copy() |
216 args.update(dict(rev=repo.manifest.rev(ctx.changeset()[0]), | 223 args.update(dict(rev=repo.manifest.rev(ctx.changeset()[0]), |
217 node=hex(ctx.changeset()[0]))) | 224 node=hex(ctx.changeset()[0]))) |
218 return templ('manifest', **args) | 225 return templ('manifest', **args) |
219 | 226 |
221 return ctx.hex() | 228 return ctx.hex() |
222 | 229 |
223 def showrev(repo, ctx, templ, **args): | 230 def showrev(repo, ctx, templ, **args): |
224 return ctx.rev() | 231 return ctx.rev() |
225 | 232 |
226 def showtags(repo, ctx, templ, **args): | 233 def showtags(**args): |
227 return showlist(templ, 'tag', ctx.tags(), **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 keywords = { | 244 keywords = { |
230 'author': showauthor, | 245 'author': showauthor, |
231 'branches': showbranches, | 246 'branches': showbranches, |
232 'date': showdate, | 247 'date': showdate, |
233 'desc': showdescription, | 248 'desc': showdescription, |