Mercurial > hg
comparison mercurial/templater.py @ 3642:b2c47652e8e3
templater: changeset templater reorganization and optimizations
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 13 Nov 2006 13:26:57 -0600 |
parents | 54d27caf6a78 |
children | b4ad640a3bcf |
comparison
equal
deleted
inserted
replaced
3641:54d27caf6a78 | 3642:b2c47652e8e3 |
---|---|
155 | 155 |
156 def stringify(thing): | 156 def stringify(thing): |
157 '''turn nested template iterator into string.''' | 157 '''turn nested template iterator into string.''' |
158 if hasattr(thing, '__iter__'): | 158 if hasattr(thing, '__iter__'): |
159 return "".join([stringify(t) for t in thing]) | 159 return "".join([stringify(t) for t in thing]) |
160 if thing is None: return "" | |
160 return str(thing) | 161 return str(thing) |
161 | 162 |
162 para_re = None | 163 para_re = None |
163 space_re = None | 164 space_re = None |
164 | 165 |
380 branch = changes[5].get("branch") | 381 branch = changes[5].get("branch") |
381 if branch: | 382 if branch: |
382 yield showlist('branch', [branch], plural='branches', **args) | 383 yield showlist('branch', [branch], plural='branches', **args) |
383 # add old style branches if requested | 384 # add old style branches if requested |
384 if brinfo and changenode in brinfo: | 385 if brinfo and changenode in brinfo: |
385 for x in showlist('branch', brinfo[changenode], | 386 yield showlist('branch', brinfo[changenode], |
386 plural='branches', **args): | 387 plural='branches', **args) |
387 yield x | |
388 | |
389 if self.ui.debugflag: | |
390 def showmanifest(**args): | |
391 args = args.copy() | |
392 args.update(dict(rev=self.repo.manifest.rev(changes[0]), | |
393 node=hex(changes[0]))) | |
394 yield self.t('manifest', **args) | |
395 else: | |
396 showmanifest = '' | |
397 | 388 |
398 def showparents(**args): | 389 def showparents(**args): |
399 parents = [[('rev', log.rev(p)), ('node', hex(p))] | 390 parents = [[('rev', log.rev(p)), ('node', hex(p))] |
400 for p in log.parents(changenode) | 391 for p in log.parents(changenode) |
401 if self.ui.debugflag or p != nullid] | 392 if self.ui.debugflag or p != nullid] |
402 if (not self.ui.debugflag and len(parents) == 1 and | 393 if (not self.ui.debugflag and len(parents) == 1 and |
403 parents[0][0][1] == rev - 1): | 394 parents[0][0][1] == rev - 1): |
404 return | 395 return |
405 for x in showlist('parent', parents, **args): | 396 return showlist('parent', parents, **args) |
406 yield x | |
407 | 397 |
408 def showtags(**args): | 398 def showtags(**args): |
409 for x in showlist('tag', self.repo.nodetags(changenode), **args): | 399 return showlist('tag', self.repo.nodetags(changenode), **args) |
410 yield x | |
411 | 400 |
412 def showextras(**args): | 401 def showextras(**args): |
413 extras = changes[5].items() | 402 extras = changes[5].items() |
414 extras.sort() | 403 extras.sort() |
415 for key, value in extras: | 404 for key, value in extras: |
416 args = args.copy() | 405 args = args.copy() |
417 args.update(dict(key=key, value=value)) | 406 args.update(dict(key=key, value=value)) |
418 yield self.t('extra', **args) | 407 yield self.t('extra', **args) |
419 | 408 |
409 def showcopies(**args): | |
410 c = [{'name': x[0], 'source': x[1]} for x in copies] | |
411 return showlist('file_copy', c, plural='file_copies', **args) | |
412 | |
420 if self.ui.debugflag: | 413 if self.ui.debugflag: |
421 files = self.repo.status(log.parents(changenode)[0], changenode)[:3] | 414 files = self.repo.status(log.parents(changenode)[0], changenode)[:3] |
422 def showfiles(**args): | 415 def showfiles(**args): |
423 for x in showlist('file', files[0], **args): yield x | 416 return showlist('file', files[0], **args) |
424 def showadds(**args): | 417 def showadds(**args): |
425 for x in showlist('file_add', files[1], **args): yield x | 418 return showlist('file_add', files[1], **args) |
426 def showdels(**args): | 419 def showdels(**args): |
427 for x in showlist('file_del', files[2], **args): yield x | 420 return showlist('file_del', files[2], **args) |
421 def showmanifest(**args): | |
422 args = args.copy() | |
423 args.update(dict(rev=self.repo.manifest.rev(changes[0]), | |
424 node=hex(changes[0]))) | |
425 return self.t('manifest', **args) | |
428 else: | 426 else: |
429 def showfiles(**args): | 427 def showfiles(**args): |
430 for x in showlist('file', changes[3], **args): yield x | 428 yield showlist('file', changes[3], **args) |
431 showadds = '' | 429 showadds = '' |
432 showdels = '' | 430 showdels = '' |
433 | 431 showmanifest = '' |
434 copies = [{'name': x[0], 'source': x[1]} | |
435 for x in copies] | |
436 def showcopies(**args): | |
437 for x in showlist('file_copy', copies, plural='file_copies', | |
438 **args): | |
439 yield x | |
440 | 432 |
441 defprops = { | 433 defprops = { |
442 'author': changes[1], | 434 'author': changes[1], |
443 'branches': showbranches, | 435 'branches': showbranches, |
444 'date': changes[2], | 436 'date': changes[2], |