##// END OF EJS Templates
templates: generate keyword help dynamically
Patrick Mezard -
r13585:2e80d495 default
parent child Browse files
Show More
@@ -2142,6 +2142,7 b' def help_(ui, name=None, with_version=Fa'
2142 'extensions\n'))
2142 'extensions\n'))
2143
2143
2144 help.addtopichook('revsets', revset.makedoc)
2144 help.addtopichook('revsets', revset.makedoc)
2145 help.addtopichook('templates', templatekw.makedoc)
2145
2146
2146 if name and name != 'shortlist':
2147 if name and name != 'shortlist':
2147 i = None
2148 i = None
@@ -23,52 +23,7 b' Strings in curly braces are called keywo'
23 keywords depends on the exact context of the templater. These
23 keywords depends on the exact context of the templater. These
24 keywords are usually available for templating a log-like command:
24 keywords are usually available for templating a log-like command:
25
25
26 :author: String. The unmodified author of the changeset.
26 .. keywordsmarker
27
28 :branch: String. The name of the branch on which the changeset was
29 committed.
30
31 :branches: List of strings. The name of the branch on which the
32 changeset was committed. Will be empty if the branch name was
33 default.
34
35 :children: List of strings. The children of the changeset.
36
37 :date: Date information. The date when the changeset was committed.
38
39 :desc: String. The text of the changeset description.
40
41 :diffstat: String. Statistics of changes with the following format:
42 "modified files: +added/-removed lines"
43
44 :files: List of strings. All files modified, added, or removed by this
45 changeset.
46
47 :file_adds: List of strings. Files added by this changeset.
48
49 :file_copies: List of strings. Files copied in this changeset with
50 their sources.
51
52 :file_copies_switch: List of strings. Like "file_copies" but displayed
53 only if the --copied switch is set.
54
55 :file_mods: List of strings. Files modified by this changeset.
56
57 :file_dels: List of strings. Files removed by this changeset.
58
59 :node: String. The changeset identification hash, as a 40 hexadecimal
60 digit string.
61
62 :parents: List of strings. The parents of the changeset.
63
64 :rev: Integer. The repository-local changeset revision number.
65
66 :tags: List of strings. Any tags associated with the changeset.
67
68 :latesttag: String. Most recent global tag in the ancestors of this
69 changeset.
70
71 :latesttagdistance: Integer. Longest path to the latest tag.
72
27
73 The "date" keyword does not produce human-readable output. If you
28 The "date" keyword does not produce human-readable output. If you
74 want to use a date in your output, you can use a filter to process
29 want to use a date in your output, you can use a filter to process
@@ -7,6 +7,7 b''
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 from i18n import gettext
10
11
11 def showlist(name, values, plural=None, **args):
12 def showlist(name, values, plural=None, **args):
12 '''expand set of values.
13 '''expand set of values.
@@ -143,12 +144,20 b' def getrenamedfn(repo, endrev=None):'
143
144
144
145
145 def showauthor(repo, ctx, templ, **args):
146 def showauthor(repo, ctx, templ, **args):
147 """:author: String. The unmodified author of the changeset."""
146 return ctx.user()
148 return ctx.user()
147
149
148 def showbranch(**args):
150 def showbranch(**args):
151 """:branch: String. The name of the branch on which the changeset was
152 committed.
153 """
149 return args['ctx'].branch()
154 return args['ctx'].branch()
150
155
151 def showbranches(**args):
156 def showbranches(**args):
157 """:branches: List of strings. The name of the branch on which the
158 changeset was committed. Will be empty if the branch name was
159 default.
160 """
152 branch = args['ctx'].branch()
161 branch = args['ctx'].branch()
153 if branch != 'default':
162 if branch != 'default':
154 return showlist('branch', [branch], plural='branches', **args)
163 return showlist('branch', [branch], plural='branches', **args)
@@ -158,17 +167,23 b' def showbookmarks(**args):'
158 return showlist('bookmark', bookmarks, **args)
167 return showlist('bookmark', bookmarks, **args)
159
168
160 def showchildren(**args):
169 def showchildren(**args):
170 """:children: List of strings. The children of the changeset."""
161 ctx = args['ctx']
171 ctx = args['ctx']
162 childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
172 childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
163 return showlist('children', childrevs, **args)
173 return showlist('children', childrevs, **args)
164
174
165 def showdate(repo, ctx, templ, **args):
175 def showdate(repo, ctx, templ, **args):
176 """:date: Date information. The date when the changeset was committed."""
166 return ctx.date()
177 return ctx.date()
167
178
168 def showdescription(repo, ctx, templ, **args):
179 def showdescription(repo, ctx, templ, **args):
180 """:desc: String. The text of the changeset description."""
169 return ctx.description().strip()
181 return ctx.description().strip()
170
182
171 def showdiffstat(repo, ctx, templ, **args):
183 def showdiffstat(repo, ctx, templ, **args):
184 """:diffstat: String. Statistics of changes with the following format:
185 "modified files: +added/-removed lines"
186 """
172 files, adds, removes = 0, 0, 0
187 files, adds, removes = 0, 0, 0
173 for i in patch.diffstatdata(util.iterlines(ctx.diff())):
188 for i in patch.diffstatdata(util.iterlines(ctx.diff())):
174 files += 1
189 files += 1
@@ -184,10 +199,14 b' def showextras(**args):'
184 yield templ('extra', **args)
199 yield templ('extra', **args)
185
200
186 def showfileadds(**args):
201 def showfileadds(**args):
202 """:file_adds: List of strings. Files added by this changeset."""
187 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
203 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
188 return showlist('file_add', getfiles(repo, ctx, revcache)[1], **args)
204 return showlist('file_add', getfiles(repo, ctx, revcache)[1], **args)
189
205
190 def showfilecopies(**args):
206 def showfilecopies(**args):
207 """:file_copies: List of strings. Files copied in this changeset with
208 their sources.
209 """
191 cache, ctx = args['cache'], args['ctx']
210 cache, ctx = args['cache'], args['ctx']
192 copies = args['revcache'].get('copies')
211 copies = args['revcache'].get('copies')
193 if copies is None:
212 if copies is None:
@@ -207,25 +226,37 b' def showfilecopies(**args):'
207 # provided before calling the templater, usually with a --copies
226 # provided before calling the templater, usually with a --copies
208 # command line switch.
227 # command line switch.
209 def showfilecopiesswitch(**args):
228 def showfilecopiesswitch(**args):
229 """:file_copies_switch: List of strings. Like "file_copies" but displayed
230 only if the --copied switch is set.
231 """
210 copies = args['revcache'].get('copies') or []
232 copies = args['revcache'].get('copies') or []
211 c = [{'name': x[0], 'source': x[1]} for x in copies]
233 c = [{'name': x[0], 'source': x[1]} for x in copies]
212 return showlist('file_copy', c, plural='file_copies', **args)
234 return showlist('file_copy', c, plural='file_copies', **args)
213
235
214 def showfiledels(**args):
236 def showfiledels(**args):
237 """:file_dels: List of strings. Files removed by this changeset."""
215 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
238 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
216 return showlist('file_del', getfiles(repo, ctx, revcache)[2], **args)
239 return showlist('file_del', getfiles(repo, ctx, revcache)[2], **args)
217
240
218 def showfilemods(**args):
241 def showfilemods(**args):
242 """:file_mods: List of strings. Files modified by this changeset."""
219 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
243 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
220 return showlist('file_mod', getfiles(repo, ctx, revcache)[0], **args)
244 return showlist('file_mod', getfiles(repo, ctx, revcache)[0], **args)
221
245
222 def showfiles(**args):
246 def showfiles(**args):
247 """:files: List of strings. All files modified, added, or removed by this
248 changeset.
249 """
223 return showlist('file', args['ctx'].files(), **args)
250 return showlist('file', args['ctx'].files(), **args)
224
251
225 def showlatesttag(repo, ctx, templ, cache, **args):
252 def showlatesttag(repo, ctx, templ, cache, **args):
253 """:latesttag: String. Most recent global tag in the ancestors of this
254 changeset.
255 """
226 return getlatesttags(repo, ctx, cache)[2]
256 return getlatesttags(repo, ctx, cache)[2]
227
257
228 def showlatesttagdistance(repo, ctx, templ, cache, **args):
258 def showlatesttagdistance(repo, ctx, templ, cache, **args):
259 """:latesttagdistance: Integer. Longest path to the latest tag."""
229 return getlatesttags(repo, ctx, cache)[1]
260 return getlatesttags(repo, ctx, cache)[1]
230
261
231 def showmanifest(**args):
262 def showmanifest(**args):
@@ -236,12 +267,17 b' def showmanifest(**args):'
236 return templ('manifest', **args)
267 return templ('manifest', **args)
237
268
238 def shownode(repo, ctx, templ, **args):
269 def shownode(repo, ctx, templ, **args):
270 """:node: String. The changeset identification hash, as a 40 hexadecimal
271 digit string.
272 """
239 return ctx.hex()
273 return ctx.hex()
240
274
241 def showrev(repo, ctx, templ, **args):
275 def showrev(repo, ctx, templ, **args):
276 """:rev: Integer. The repository-local changeset revision number."""
242 return ctx.rev()
277 return ctx.rev()
243
278
244 def showtags(**args):
279 def showtags(**args):
280 """:tags: List of strings. Any tags associated with the changeset."""
245 return showlist('tag', args['ctx'].tags(), **args)
281 return showlist('tag', args['ctx'].tags(), **args)
246
282
247 # keywords are callables like:
283 # keywords are callables like:
@@ -276,3 +312,20 b' keywords = {'
276 'tags': showtags,
312 'tags': showtags,
277 }
313 }
278
314
315 def makedoc(topic, doc):
316 """Generate and include keyword help in templating topic."""
317 kw = []
318 for name in sorted(keywords):
319 text = (keywords[name].__doc__ or '').rstrip()
320 if not text:
321 continue
322 text = gettext(text)
323 lines = text.splitlines()
324 lines[1:] = [(' ' + l.strip()) for l in lines[1:]]
325 kw.append('\n'.join(lines))
326 kw = '\n\n'.join(kw)
327 doc = doc.replace('.. keywordsmarker', kw)
328 return doc
329
330 # tell hggettext to extract docstrings from these functions:
331 i18nfunctions = keywords.values()
General Comments 0
You need to be logged in to leave comments. Login now