comparison mercurial/cmdutil.py @ 7878:8c09952cd39a

templater: use contexts consistently throughout changeset_templater
author Alexander Solovyov <piranha@piranha.org.ua>
date Mon, 23 Mar 2009 13:15:57 +0100
parents bd8f44638847
children 5c4026a289a4
comparison
equal deleted inserted replaced
7877:eba7f12b0c51 7878:8c09952cd39a
708 708
709 def use_template(self, t): 709 def use_template(self, t):
710 '''set template string to use''' 710 '''set template string to use'''
711 self.t.cache['changeset'] = t 711 self.t.cache['changeset'] = t
712 712
713 def _meaningful_parentrevs(self, ctx):
714 """Return list of meaningful (or all if debug) parentrevs for rev.
715 """
716 parents = ctx.parents()
717 if len(parents) > 1:
718 return parents
719 if self.ui.debugflag:
720 return [parents[0], self.repo['null']]
721 if parents[0].rev() >= ctx.rev() - 1:
722 return []
723 return parents
724
713 def _show(self, ctx, copies, props): 725 def _show(self, ctx, copies, props):
714 '''show a single changeset or file revision''' 726 '''show a single changeset or file revision'''
715 changenode = ctx.node()
716 rev = ctx.rev()
717
718 log = self.repo.changelog
719 changes = log.read(changenode)
720 727
721 def showlist(name, values, plural=None, **args): 728 def showlist(name, values, plural=None, **args):
722 '''expand set of values. 729 '''expand set of values.
723 name is name of key in template map. 730 name is name of key in template map.
724 values is list of strings or dicts. 731 values is list of strings or dicts.
778 endname = 'end_' + names 785 endname = 'end_' + names
779 if endname in self.t: 786 if endname in self.t:
780 yield self.t(endname, **args) 787 yield self.t(endname, **args)
781 788
782 def showbranches(**args): 789 def showbranches(**args):
783 branch = changes[5].get("branch") 790 branch = ctx.branch()
784 if branch != 'default': 791 if branch != 'default':
785 branch = util.tolocal(branch) 792 branch = util.tolocal(branch)
786 return showlist('branch', [branch], plural='branches', **args) 793 return showlist('branch', [branch], plural='branches', **args)
787 794
788 def showparents(**args): 795 def showparents(**args):
789 parents = [[('rev', p), ('node', hex(log.node(p)))] 796 parents = [[('rev', p.rev()), ('node', p.hex())]
790 for p in self._meaningful_parentrevs(log, rev)] 797 for p in self._meaningful_parentrevs(ctx)]
791 return showlist('parent', parents, **args) 798 return showlist('parent', parents, **args)
792 799
793 def showtags(**args): 800 def showtags(**args):
794 return showlist('tag', self.repo.nodetags(changenode), **args) 801 return showlist('tag', ctx.tags(), **args)
795 802
796 def showextras(**args): 803 def showextras(**args):
797 for key, value in util.sort(changes[5].items()): 804 for key, value in util.sort(ctx.extra().items()):
798 args = args.copy() 805 args = args.copy()
799 args.update(dict(key=key, value=value)) 806 args.update(dict(key=key, value=value))
800 yield self.t('extra', **args) 807 yield self.t('extra', **args)
801 808
802 def showcopies(**args): 809 def showcopies(**args):
804 return showlist('file_copy', c, plural='file_copies', **args) 811 return showlist('file_copy', c, plural='file_copies', **args)
805 812
806 files = [] 813 files = []
807 def getfiles(): 814 def getfiles():
808 if not files: 815 if not files:
809 files[:] = self.repo.status( 816 files[:] = self.repo.status(ctx.parents()[0].node(),
810 log.parents(changenode)[0], changenode)[:3] 817 ctx.node())[:3]
811 return files 818 return files
812 def showfiles(**args): 819 def showfiles(**args):
813 return showlist('file', changes[3], **args) 820 return showlist('file', ctx.files(), **args)
814 def showmods(**args): 821 def showmods(**args):
815 return showlist('file_mod', getfiles()[0], **args) 822 return showlist('file_mod', getfiles()[0], **args)
816 def showadds(**args): 823 def showadds(**args):
817 return showlist('file_add', getfiles()[1], **args) 824 return showlist('file_add', getfiles()[1], **args)
818 def showdels(**args): 825 def showdels(**args):
819 return showlist('file_del', getfiles()[2], **args) 826 return showlist('file_del', getfiles()[2], **args)
820 def showmanifest(**args): 827 def showmanifest(**args):
821 args = args.copy() 828 args = args.copy()
822 args.update(dict(rev=self.repo.manifest.rev(changes[0]), 829 args.update(dict(rev=self.repo.manifest.rev(ctx.changeset()[0]),
823 node=hex(changes[0]))) 830 node=hex(ctx.changeset()[0])))
824 return self.t('manifest', **args) 831 return self.t('manifest', **args)
825 832
826 defprops = { 833 defprops = {
827 'author': changes[1], 834 'author': ctx.user(),
828 'branches': showbranches, 835 'branches': showbranches,
829 'date': changes[2], 836 'date': ctx.date(),
830 'desc': changes[4].strip(), 837 'desc': ctx.description().strip(),
831 'file_adds': showadds, 838 'file_adds': showadds,
832 'file_dels': showdels, 839 'file_dels': showdels,
833 'file_mods': showmods, 840 'file_mods': showmods,
834 'files': showfiles, 841 'files': showfiles,
835 'file_copies': showcopies, 842 'file_copies': showcopies,
836 'manifest': showmanifest, 843 'manifest': showmanifest,
837 'node': hex(changenode), 844 'node': ctx.hex(),
838 'parents': showparents, 845 'parents': showparents,
839 'rev': rev, 846 'rev': ctx.rev(),
840 'tags': showtags, 847 'tags': showtags,
841 'extras': showextras, 848 'extras': showextras,
842 } 849 }
843 props = props.copy() 850 props = props.copy()
844 props.update(defprops) 851 props.update(defprops)
855 else: 862 else:
856 key = '' 863 key = ''
857 if key: 864 if key:
858 h = templater.stringify(self.t(key, **props)) 865 h = templater.stringify(self.t(key, **props))
859 if self.buffered: 866 if self.buffered:
860 self.header[rev] = h 867 self.header[ctx.rev()] = h
861 else: 868 else:
862 self.ui.write(h) 869 self.ui.write(h)
863 if self.ui.debugflag and 'changeset_debug' in self.t: 870 if self.ui.debugflag and 'changeset_debug' in self.t:
864 key = 'changeset_debug' 871 key = 'changeset_debug'
865 elif self.ui.quiet and 'changeset_quiet' in self.t: 872 elif self.ui.quiet and 'changeset_quiet' in self.t:
867 elif self.ui.verbose and 'changeset_verbose' in self.t: 874 elif self.ui.verbose and 'changeset_verbose' in self.t:
868 key = 'changeset_verbose' 875 key = 'changeset_verbose'
869 else: 876 else:
870 key = 'changeset' 877 key = 'changeset'
871 self.ui.write(templater.stringify(self.t(key, **props))) 878 self.ui.write(templater.stringify(self.t(key, **props)))
872 self.showpatch(changenode) 879 self.showpatch(ctx.node())
873 except KeyError, inst: 880 except KeyError, inst:
874 raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, 881 raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile,
875 inst.args[0])) 882 inst.args[0]))
876 except SyntaxError, inst: 883 except SyntaxError, inst:
877 raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) 884 raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0]))