Show More
@@ -0,0 +1,69 b'' | |||||
|
1 | # templatekw.py - common changeset template keywords | |||
|
2 | # | |||
|
3 | # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> | |||
|
4 | # | |||
|
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. | |||
|
7 | ||||
|
8 | ||||
|
9 | def showlist(templ, name, values, plural=None, **args): | |||
|
10 | '''expand set of values. | |||
|
11 | name is name of key in template map. | |||
|
12 | values is list of strings or dicts. | |||
|
13 | plural is plural of name, if not simply name + 's'. | |||
|
14 | ||||
|
15 | expansion works like this, given name 'foo'. | |||
|
16 | ||||
|
17 | if values is empty, expand 'no_foos'. | |||
|
18 | ||||
|
19 | if 'foo' not in template map, return values as a string, | |||
|
20 | joined by space. | |||
|
21 | ||||
|
22 | expand 'start_foos'. | |||
|
23 | ||||
|
24 | for each value, expand 'foo'. if 'last_foo' in template | |||
|
25 | map, expand it instead of 'foo' for last key. | |||
|
26 | ||||
|
27 | expand 'end_foos'. | |||
|
28 | ''' | |||
|
29 | if plural: names = plural | |||
|
30 | else: names = name + 's' | |||
|
31 | if not values: | |||
|
32 | noname = 'no_' + names | |||
|
33 | if noname in templ: | |||
|
34 | yield templ(noname, **args) | |||
|
35 | return | |||
|
36 | if name not in templ: | |||
|
37 | if isinstance(values[0], str): | |||
|
38 | yield ' '.join(values) | |||
|
39 | else: | |||
|
40 | for v in values: | |||
|
41 | yield dict(v, **args) | |||
|
42 | return | |||
|
43 | startname = 'start_' + names | |||
|
44 | if startname in templ: | |||
|
45 | yield templ(startname, **args) | |||
|
46 | vargs = args.copy() | |||
|
47 | def one(v, tag=name): | |||
|
48 | try: | |||
|
49 | vargs.update(v) | |||
|
50 | except (AttributeError, ValueError): | |||
|
51 | try: | |||
|
52 | for a, b in v: | |||
|
53 | vargs[a] = b | |||
|
54 | except ValueError: | |||
|
55 | vargs[name] = v | |||
|
56 | return templ(tag, **vargs) | |||
|
57 | lastname = 'last_' + name | |||
|
58 | if lastname in templ: | |||
|
59 | last = values.pop() | |||
|
60 | else: | |||
|
61 | last = None | |||
|
62 | for v in values: | |||
|
63 | yield one(v) | |||
|
64 | if last is not None: | |||
|
65 | yield one(last, tag=lastname) | |||
|
66 | endname = 'end_' + names | |||
|
67 | if endname in templ: | |||
|
68 | yield templ(endname, **args) | |||
|
69 |
@@ -8,7 +8,7 b'' | |||||
8 | from node import hex, nullid, nullrev, short |
|
8 | from node import hex, nullid, nullrev, short | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import os, sys, errno, re, glob |
|
10 | import os, sys, errno, re, glob | |
11 | import mdiff, bdiff, util, templater, patch, error, encoding |
|
11 | import mdiff, bdiff, util, templater, patch, error, encoding, templatekw | |
12 | import match as _match |
|
12 | import match as _match | |
13 |
|
13 | |||
14 | revrangesep = ':' |
|
14 | revrangesep = ':' | |
@@ -810,90 +810,32 b' class changeset_templater(changeset_prin' | |||||
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 | def showlist(name, values, plural=None, **args): |
|
813 | showlist = templatekw.showlist | |
814 | '''expand set of values. |
|
|||
815 | name is name of key in template map. |
|
|||
816 | values is list of strings or dicts. |
|
|||
817 | plural is plural of name, if not simply name + 's'. |
|
|||
818 |
|
||||
819 | expansion works like this, given name 'foo'. |
|
|||
820 |
|
||||
821 | if values is empty, expand 'no_foos'. |
|
|||
822 |
|
||||
823 | if 'foo' not in template map, return values as a string, |
|
|||
824 | joined by space. |
|
|||
825 |
|
||||
826 | expand 'start_foos'. |
|
|||
827 |
|
||||
828 | for each value, expand 'foo'. if 'last_foo' in template |
|
|||
829 | map, expand it instead of 'foo' for last key. |
|
|||
830 |
|
814 | |||
831 | expand 'end_foos'. |
|
815 | def showbranches(templ, **args): | |
832 | ''' |
|
|||
833 | if plural: names = plural |
|
|||
834 | else: names = name + 's' |
|
|||
835 | if not values: |
|
|||
836 | noname = 'no_' + names |
|
|||
837 | if noname in self.t: |
|
|||
838 | yield self.t(noname, **args) |
|
|||
839 | return |
|
|||
840 | if name not in self.t: |
|
|||
841 | if isinstance(values[0], str): |
|
|||
842 | yield ' '.join(values) |
|
|||
843 | else: |
|
|||
844 | for v in values: |
|
|||
845 | yield dict(v, **args) |
|
|||
846 | return |
|
|||
847 | startname = 'start_' + names |
|
|||
848 | if startname in self.t: |
|
|||
849 | yield self.t(startname, **args) |
|
|||
850 | vargs = args.copy() |
|
|||
851 | def one(v, tag=name): |
|
|||
852 | try: |
|
|||
853 | vargs.update(v) |
|
|||
854 | except (AttributeError, ValueError): |
|
|||
855 | try: |
|
|||
856 | for a, b in v: |
|
|||
857 | vargs[a] = b |
|
|||
858 | except ValueError: |
|
|||
859 | vargs[name] = v |
|
|||
860 | return self.t(tag, **vargs) |
|
|||
861 | lastname = 'last_' + name |
|
|||
862 | if lastname in self.t: |
|
|||
863 | last = values.pop() |
|
|||
864 | else: |
|
|||
865 | last = None |
|
|||
866 | for v in values: |
|
|||
867 | yield one(v) |
|
|||
868 | if last is not None: |
|
|||
869 | yield one(last, tag=lastname) |
|
|||
870 | endname = 'end_' + names |
|
|||
871 | if endname in self.t: |
|
|||
872 | yield self.t(endname, **args) |
|
|||
873 |
|
||||
874 | def showbranches(**args): |
|
|||
875 | branch = ctx.branch() |
|
816 | branch = ctx.branch() | |
876 | if branch != 'default': |
|
817 | if branch != 'default': | |
877 | branch = encoding.tolocal(branch) |
|
818 | branch = encoding.tolocal(branch) | |
878 |
return showlist('branch', [branch], plural='branches', |
|
819 | return showlist(templ, 'branch', [branch], plural='branches', | |
|
820 | **args) | |||
879 |
|
821 | |||
880 | def showparents(**args): |
|
822 | def showparents(templ, **args): | |
881 | parents = [[('rev', p.rev()), ('node', p.hex())] |
|
823 | parents = [[('rev', p.rev()), ('node', p.hex())] | |
882 | for p in self._meaningful_parentrevs(ctx)] |
|
824 | for p in self._meaningful_parentrevs(ctx)] | |
883 | return showlist('parent', parents, **args) |
|
825 | return showlist(templ, 'parent', parents, **args) | |
884 |
|
826 | |||
885 | def showtags(**args): |
|
827 | def showtags(templ, **args): | |
886 | return showlist('tag', ctx.tags(), **args) |
|
828 | return showlist(templ, 'tag', ctx.tags(), **args) | |
887 |
|
829 | |||
888 | def showextras(**args): |
|
830 | def showextras(templ, **args): | |
889 | for key, value in sorted(ctx.extra().items()): |
|
831 | for key, value in sorted(ctx.extra().items()): | |
890 | args = args.copy() |
|
832 | args = args.copy() | |
891 | args.update(dict(key=key, value=value)) |
|
833 | args.update(dict(key=key, value=value)) | |
892 |
yield |
|
834 | yield templ('extra', **args) | |
893 |
|
835 | |||
894 | def showcopies(**args): |
|
836 | def showcopies(templ, **args): | |
895 | c = [{'name': x[0], 'source': x[1]} for x in copies] |
|
837 | c = [{'name': x[0], 'source': x[1]} for x in copies] | |
896 | return showlist('file_copy', c, plural='file_copies', **args) |
|
838 | return showlist(templ, 'file_copy', c, plural='file_copies', **args) | |
897 |
|
839 | |||
898 | files = [] |
|
840 | files = [] | |
899 | def getfiles(): |
|
841 | def getfiles(): | |
@@ -901,21 +843,21 b' class changeset_templater(changeset_prin' | |||||
901 | files[:] = self.repo.status(ctx.parents()[0].node(), |
|
843 | files[:] = self.repo.status(ctx.parents()[0].node(), | |
902 | ctx.node())[:3] |
|
844 | ctx.node())[:3] | |
903 | return files |
|
845 | return files | |
904 | def showfiles(**args): |
|
846 | def showfiles(templ, **args): | |
905 | return showlist('file', ctx.files(), **args) |
|
847 | return showlist(templ, 'file', ctx.files(), **args) | |
906 | def showmods(**args): |
|
848 | def showmods(templ, **args): | |
907 | return showlist('file_mod', getfiles()[0], **args) |
|
849 | return showlist(templ, 'file_mod', getfiles()[0], **args) | |
908 | def showadds(**args): |
|
850 | def showadds(templ, **args): | |
909 | return showlist('file_add', getfiles()[1], **args) |
|
851 | return showlist(templ, 'file_add', getfiles()[1], **args) | |
910 | def showdels(**args): |
|
852 | def showdels(templ, **args): | |
911 | return showlist('file_del', getfiles()[2], **args) |
|
853 | return showlist(templ, 'file_del', getfiles()[2], **args) | |
912 | def showmanifest(**args): |
|
854 | def showmanifest(templ, **args): | |
913 | args = args.copy() |
|
855 | args = args.copy() | |
914 | args.update(dict(rev=self.repo.manifest.rev(ctx.changeset()[0]), |
|
856 | args.update(dict(rev=self.repo.manifest.rev(ctx.changeset()[0]), | |
915 | node=hex(ctx.changeset()[0]))) |
|
857 | node=hex(ctx.changeset()[0]))) | |
916 |
return |
|
858 | return templ('manifest', **args) | |
917 |
|
859 | |||
918 | def showdiffstat(**args): |
|
860 | def showdiffstat(templ, **args): | |
919 | diff = patch.diff(self.repo, ctx.parents()[0].node(), ctx.node()) |
|
861 | diff = patch.diff(self.repo, ctx.parents()[0].node(), ctx.node()) | |
920 | files, adds, removes = 0, 0, 0 |
|
862 | files, adds, removes = 0, 0, 0 | |
921 | for i in patch.diffstatdata(util.iterlines(diff)): |
|
863 | for i in patch.diffstatdata(util.iterlines(diff)): | |
@@ -924,9 +866,9 b' class changeset_templater(changeset_prin' | |||||
924 | removes += i[2] |
|
866 | removes += i[2] | |
925 | return '%s: +%s/-%s' % (files, adds, removes) |
|
867 | return '%s: +%s/-%s' % (files, adds, removes) | |
926 |
|
868 | |||
927 | def showlatesttag(**args): |
|
869 | def showlatesttag(templ, **args): | |
928 | return self._latesttaginfo(ctx.rev())[2] |
|
870 | return self._latesttaginfo(ctx.rev())[2] | |
929 | def showlatesttagdistance(**args): |
|
871 | def showlatesttagdistance(templ, **args): | |
930 | return self._latesttaginfo(ctx.rev())[1] |
|
872 | return self._latesttaginfo(ctx.rev())[1] | |
931 |
|
873 | |||
932 | defprops = { |
|
874 | defprops = { | |
@@ -951,6 +893,7 b' class changeset_templater(changeset_prin' | |||||
951 | } |
|
893 | } | |
952 | props = props.copy() |
|
894 | props = props.copy() | |
953 | props.update(defprops) |
|
895 | props.update(defprops) | |
|
896 | props['templ'] = self.t | |||
954 |
|
897 | |||
955 | # find correct templates for current mode |
|
898 | # find correct templates for current mode | |
956 |
|
899 |
General Comments 0
You need to be logged in to leave comments.
Login now