##// END OF EJS Templates
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard -
r10054:1a85861f default
parent child Browse files
Show More
@@ -812,28 +812,12 b' class changeset_templater(changeset_prin'
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
@@ -843,21 +827,19 b' class changeset_templater(changeset_prin'
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)):
@@ -866,34 +848,27 b' class changeset_templater(changeset_prin'
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
@@ -5,6 +5,7 b''
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
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 import encoding
8
9
9 def showlist(templ, name, values, plural=None, **args):
10 def showlist(templ, name, values, plural=None, **args):
10 '''expand set of values.
11 '''expand set of values.
@@ -67,3 +68,48 b' def showlist(templ, name, values, plural'
67 if endname in templ:
68 if endname in templ:
68 yield templ(endname, **args)
69 yield templ(endname, **args)
69
70
71 def showauthor(ctx, templ, **args):
72 return ctx.user()
73
74 def showbranches(ctx, templ, **args):
75 branch = ctx.branch()
76 if branch != 'default':
77 branch = encoding.tolocal(branch)
78 return showlist(templ, 'branch', [branch], plural='branches', **args)
79
80 def showdate(ctx, templ, **args):
81 return ctx.date()
82
83 def showdescription(ctx, templ, **args):
84 return ctx.description().strip()
85
86 def showextras(ctx, templ, **args):
87 for key, value in sorted(ctx.extra().items()):
88 args = args.copy()
89 args.update(dict(key=key, value=value))
90 yield templ('extra', **args)
91
92 def showfiles(ctx, templ, **args):
93 return showlist(templ, 'file', ctx.files(), **args)
94
95 def shownode(ctx, templ, **args):
96 return ctx.hex()
97
98 def showrev(ctx, templ, **args):
99 return ctx.rev()
100
101 def showtags(ctx, templ, **args):
102 return showlist(templ, 'tag', ctx.tags(), **args)
103
104 keywords = {
105 'author': showauthor,
106 'branches': showbranches,
107 'date': showdate,
108 'desc': showdescription,
109 'extras': showextras,
110 'files': showfiles,
111 'node': shownode,
112 'rev': showrev,
113 'tags': showtags,
114 }
115
@@ -11,6 +11,10 b' class mytemplater(object):'
11 def process(self, t, map):
11 def process(self, t, map):
12 tmpl = self.loader(t)
12 tmpl = self.loader(t)
13 for k, v in map.iteritems():
13 for k, v in map.iteritems():
14 if k in ('templ', 'ctx'):
15 continue
16 if hasattr(v, '__call__'):
17 v = v(**map)
14 v = templater.stringify(v)
18 v = templater.stringify(v)
15 tmpl = tmpl.replace('{{%s}}' % k, v)
19 tmpl = tmpl.replace('{{%s}}' % k, v)
16 yield tmpl
20 yield tmpl
General Comments 0
You need to be logged in to leave comments. Login now