comparison mercurial/cmdutil.py @ 10054:1a85861f59af

cmdutil: extract ctx dependent closures into templatekw
author Patrick Mezard <pmezard@gmail.com>
date Sun, 13 Dec 2009 18:06:23 +0100
parents 5c5c6295533d
children e400a511e63a
comparison
equal deleted inserted replaced
10053:5c5c6295533d 10054:1a85861f59af
810 def _show(self, ctx, copies, props): 810 def _show(self, ctx, copies, props):
811 '''show a single changeset or file revision''' 811 '''show a single changeset or file revision'''
812 812
813 showlist = templatekw.showlist 813 showlist = templatekw.showlist
814 814
815 def showbranches(templ, **args): 815 def showparents(ctx, templ, **args):
816 branch = ctx.branch()
817 if branch != 'default':
818 branch = encoding.tolocal(branch)
819 return showlist(templ, 'branch', [branch], plural='branches',
820 **args)
821
822 def showparents(templ, **args):
823 parents = [[('rev', p.rev()), ('node', p.hex())] 816 parents = [[('rev', p.rev()), ('node', p.hex())]
824 for p in self._meaningful_parentrevs(ctx)] 817 for p in self._meaningful_parentrevs(ctx)]
825 return showlist(templ, 'parent', parents, **args) 818 return showlist(templ, 'parent', parents, **args)
826 819
827 def showtags(templ, **args): 820 def showcopies(ctx, templ, **args):
828 return showlist(templ, 'tag', ctx.tags(), **args)
829
830 def showextras(templ, **args):
831 for key, value in sorted(ctx.extra().items()):
832 args = args.copy()
833 args.update(dict(key=key, value=value))
834 yield templ('extra', **args)
835
836 def showcopies(templ, **args):
837 c = [{'name': x[0], 'source': x[1]} for x in copies] 821 c = [{'name': x[0], 'source': x[1]} for x in copies]
838 return showlist(templ, 'file_copy', c, plural='file_copies', **args) 822 return showlist(templ, 'file_copy', c, plural='file_copies', **args)
839 823
840 files = [] 824 files = []
841 def getfiles(): 825 def getfiles():
842 if not files: 826 if not files:
843 files[:] = self.repo.status(ctx.parents()[0].node(), 827 files[:] = self.repo.status(ctx.parents()[0].node(),
844 ctx.node())[:3] 828 ctx.node())[:3]
845 return files 829 return files
846 def showfiles(templ, **args): 830 def showmods(ctx, templ, **args):
847 return showlist(templ, 'file', ctx.files(), **args)
848 def showmods(templ, **args):
849 return showlist(templ, 'file_mod', getfiles()[0], **args) 831 return showlist(templ, 'file_mod', getfiles()[0], **args)
850 def showadds(templ, **args): 832 def showadds(ctx, templ, **args):
851 return showlist(templ, 'file_add', getfiles()[1], **args) 833 return showlist(templ, 'file_add', getfiles()[1], **args)
852 def showdels(templ, **args): 834 def showdels(ctx, templ, **args):
853 return showlist(templ, 'file_del', getfiles()[2], **args) 835 return showlist(templ, 'file_del', getfiles()[2], **args)
854 def showmanifest(templ, **args): 836 def showmanifest(ctx, templ, **args):
855 args = args.copy() 837 args = args.copy()
856 args.update(dict(rev=self.repo.manifest.rev(ctx.changeset()[0]), 838 args.update(dict(rev=self.repo.manifest.rev(ctx.changeset()[0]),
857 node=hex(ctx.changeset()[0]))) 839 node=hex(ctx.changeset()[0])))
858 return templ('manifest', **args) 840 return templ('manifest', **args)
859 841
860 def showdiffstat(templ, **args): 842 def showdiffstat(ctx, templ, **args):
861 diff = patch.diff(self.repo, ctx.parents()[0].node(), ctx.node()) 843 diff = patch.diff(self.repo, ctx.parents()[0].node(), ctx.node())
862 files, adds, removes = 0, 0, 0 844 files, adds, removes = 0, 0, 0
863 for i in patch.diffstatdata(util.iterlines(diff)): 845 for i in patch.diffstatdata(util.iterlines(diff)):
864 files += 1 846 files += 1
865 adds += i[1] 847 adds += i[1]
866 removes += i[2] 848 removes += i[2]
867 return '%s: +%s/-%s' % (files, adds, removes) 849 return '%s: +%s/-%s' % (files, adds, removes)
868 850
869 def showlatesttag(templ, **args): 851 def showlatesttag(ctx, templ, **args):
870 return self._latesttaginfo(ctx.rev())[2] 852 return self._latesttaginfo(ctx.rev())[2]
871 def showlatesttagdistance(templ, **args): 853 def showlatesttagdistance(ctx, templ, **args):
872 return self._latesttaginfo(ctx.rev())[1] 854 return self._latesttaginfo(ctx.rev())[1]
873 855
874 defprops = { 856 defprops = {
875 'author': ctx.user(),
876 'branches': showbranches,
877 'date': ctx.date(),
878 'desc': ctx.description().strip(),
879 'file_adds': showadds, 857 'file_adds': showadds,
880 'file_dels': showdels, 858 'file_dels': showdels,
881 'file_mods': showmods, 859 'file_mods': showmods,
882 'files': showfiles,
883 'file_copies': showcopies, 860 'file_copies': showcopies,
884 'manifest': showmanifest, 861 'manifest': showmanifest,
885 'node': ctx.hex(),
886 'parents': showparents, 862 'parents': showparents,
887 'rev': ctx.rev(),
888 'tags': showtags,
889 'extras': showextras,
890 'diffstat': showdiffstat, 863 'diffstat': showdiffstat,
891 'latesttag': showlatesttag, 864 'latesttag': showlatesttag,
892 'latesttagdistance': showlatesttagdistance, 865 'latesttagdistance': showlatesttagdistance,
893 } 866 }
894 props = props.copy() 867 props = props.copy()
868 props.update(templatekw.keywords)
895 props.update(defprops) 869 props.update(defprops)
896 props['templ'] = self.t 870 props['templ'] = self.t
871 props['ctx'] = ctx
897 872
898 # find correct templates for current mode 873 # find correct templates for current mode
899 874
900 tmplmodes = [ 875 tmplmodes = [
901 (True, None), 876 (True, None),