Show More
@@ -763,9 +763,7 b' class changeset_templater(changeset_prin' | |||||
763 | 'manifest': '{rev}:{node|formatnode}', |
|
763 | 'manifest': '{rev}:{node|formatnode}', | |
764 | 'filecopy': '{name} ({source})', |
|
764 | 'filecopy': '{name} ({source})', | |
765 | 'extra': '{key}={value|stringescape}'}) |
|
765 | 'extra': '{key}={value|stringescape}'}) | |
766 | # Cache mapping from rev to a tuple with tag date, tag |
|
766 | self.cache = {} | |
767 | # distance and tag name |
|
|||
768 | self._latesttagcache = {-1: (0, 0, 'null')} |
|
|||
769 |
|
767 | |||
770 | def use_template(self, t): |
|
768 | def use_template(self, t): | |
771 | '''set template string to use''' |
|
769 | '''set template string to use''' | |
@@ -783,30 +781,6 b' class changeset_templater(changeset_prin' | |||||
783 | return [] |
|
781 | return [] | |
784 | return parents |
|
782 | return parents | |
785 |
|
783 | |||
786 | def _latesttaginfo(self, rev): |
|
|||
787 | '''return date, distance and name for the latest tag of rev''' |
|
|||
788 | todo = [rev] |
|
|||
789 | while todo: |
|
|||
790 | rev = todo.pop() |
|
|||
791 | if rev in self._latesttagcache: |
|
|||
792 | continue |
|
|||
793 | ctx = self.repo[rev] |
|
|||
794 | tags = [t for t in ctx.tags() if self.repo.tagtype(t) == 'global'] |
|
|||
795 | if tags: |
|
|||
796 | self._latesttagcache[rev] = ctx.date()[0], 0, ':'.join(sorted(tags)) |
|
|||
797 | continue |
|
|||
798 | try: |
|
|||
799 | # The tuples are laid out so the right one can be found by comparison. |
|
|||
800 | pdate, pdist, ptag = max( |
|
|||
801 | self._latesttagcache[p.rev()] for p in ctx.parents()) |
|
|||
802 | except KeyError: |
|
|||
803 | # Cache miss - recurse |
|
|||
804 | todo.append(rev) |
|
|||
805 | todo.extend(p.rev() for p in ctx.parents()) |
|
|||
806 | continue |
|
|||
807 | self._latesttagcache[rev] = pdate, pdist + 1, ptag |
|
|||
808 | return self._latesttagcache[rev] |
|
|||
809 |
|
||||
810 | def _show(self, ctx, copies, props): |
|
784 | def _show(self, ctx, copies, props): | |
811 | '''show a single changeset or file revision''' |
|
785 | '''show a single changeset or file revision''' | |
812 |
|
786 | |||
@@ -820,17 +794,10 b' class changeset_templater(changeset_prin' | |||||
820 | def showcopies(repo, ctx, templ, **args): |
|
794 | def showcopies(repo, ctx, templ, **args): | |
821 | c = [{'name': x[0], 'source': x[1]} for x in copies] |
|
795 | c = [{'name': x[0], 'source': x[1]} for x in copies] | |
822 | return showlist(templ, 'file_copy', c, plural='file_copies', **args) |
|
796 | return showlist(templ, 'file_copy', c, plural='file_copies', **args) | |
823 |
|
||||
824 | def showlatesttag(repo, ctx, templ, **args): |
|
|||
825 | return self._latesttaginfo(ctx.rev())[2] |
|
|||
826 | def showlatesttagdistance(repo, ctx, templ, **args): |
|
|||
827 | return self._latesttaginfo(ctx.rev())[1] |
|
|||
828 |
|
797 | |||
829 | defprops = { |
|
798 | defprops = { | |
830 | 'file_copies': showcopies, |
|
799 | 'file_copies': showcopies, | |
831 | 'parents': showparents, |
|
800 | 'parents': showparents, | |
832 | 'latesttag': showlatesttag, |
|
|||
833 | 'latesttagdistance': showlatesttagdistance, |
|
|||
834 | } |
|
801 | } | |
835 | props = props.copy() |
|
802 | props = props.copy() | |
836 | props.update(templatekw.keywords) |
|
803 | props.update(templatekw.keywords) | |
@@ -839,6 +806,7 b' class changeset_templater(changeset_prin' | |||||
839 | props['ctx'] = ctx |
|
806 | props['ctx'] = ctx | |
840 | props['repo'] = self.repo |
|
807 | props['repo'] = self.repo | |
841 | props['revcache'] = {} |
|
808 | props['revcache'] = {} | |
|
809 | props['cache'] = self.cache | |||
842 |
|
810 | |||
843 | # find correct templates for current mode |
|
811 | # find correct templates for current mode | |
844 |
|
812 |
@@ -75,6 +75,39 b' def getfiles(repo, ctx, revcache):' | |||||
75 | ctx.node())[:3] |
|
75 | ctx.node())[:3] | |
76 | return revcache['files'] |
|
76 | return revcache['files'] | |
77 |
|
77 | |||
|
78 | def getlatesttags(repo, ctx, cache): | |||
|
79 | '''return date, distance and name for the latest tag of rev''' | |||
|
80 | ||||
|
81 | if 'latesttags' not in cache: | |||
|
82 | # Cache mapping from rev to a tuple with tag date, tag | |||
|
83 | # distance and tag name | |||
|
84 | cache['latesttags'] = {-1: (0, 0, 'null')} | |||
|
85 | latesttags = cache['latesttags'] | |||
|
86 | ||||
|
87 | rev = ctx.rev() | |||
|
88 | todo = [rev] | |||
|
89 | while todo: | |||
|
90 | rev = todo.pop() | |||
|
91 | if rev in latesttags: | |||
|
92 | continue | |||
|
93 | ctx = repo[rev] | |||
|
94 | tags = [t for t in ctx.tags() if repo.tagtype(t) == 'global'] | |||
|
95 | if tags: | |||
|
96 | latesttags[rev] = ctx.date()[0], 0, ':'.join(sorted(tags)) | |||
|
97 | continue | |||
|
98 | try: | |||
|
99 | # The tuples are laid out so the right one can be found by | |||
|
100 | # comparison. | |||
|
101 | pdate, pdist, ptag = max( | |||
|
102 | latesttags[p.rev()] for p in ctx.parents()) | |||
|
103 | except KeyError: | |||
|
104 | # Cache miss - recurse | |||
|
105 | todo.append(rev) | |||
|
106 | todo.extend(p.rev() for p in ctx.parents()) | |||
|
107 | continue | |||
|
108 | latesttags[rev] = pdate, pdist + 1, ptag | |||
|
109 | return latesttags[rev] | |||
|
110 | ||||
78 | def showauthor(repo, ctx, templ, **args): |
|
111 | def showauthor(repo, ctx, templ, **args): | |
79 | return ctx.user() |
|
112 | return ctx.user() | |
80 |
|
113 | |||
@@ -117,6 +150,12 b' def showfilemods(repo, ctx, templ, revca' | |||||
117 | def showfiles(repo, ctx, templ, **args): |
|
150 | def showfiles(repo, ctx, templ, **args): | |
118 | return showlist(templ, 'file', ctx.files(), **args) |
|
151 | return showlist(templ, 'file', ctx.files(), **args) | |
119 |
|
152 | |||
|
153 | def showlatesttag(repo, ctx, templ, cache, **args): | |||
|
154 | return getlatesttags(repo, ctx, cache)[2] | |||
|
155 | ||||
|
156 | def showlatesttagdistance(repo, ctx, templ, cache, **args): | |||
|
157 | return getlatesttags(repo, ctx, cache)[1] | |||
|
158 | ||||
120 | def showmanifest(repo, ctx, templ, **args): |
|
159 | def showmanifest(repo, ctx, templ, **args): | |
121 | args = args.copy() |
|
160 | args = args.copy() | |
122 | args.update(dict(rev=repo.manifest.rev(ctx.changeset()[0]), |
|
161 | args.update(dict(rev=repo.manifest.rev(ctx.changeset()[0]), | |
@@ -143,6 +182,8 b' keywords = {' | |||||
143 | 'file_dels': showfiledels, |
|
182 | 'file_dels': showfiledels, | |
144 | 'file_mods': showfilemods, |
|
183 | 'file_mods': showfilemods, | |
145 | 'files': showfiles, |
|
184 | 'files': showfiles, | |
|
185 | 'latesttag': showlatesttag, | |||
|
186 | 'latesttagdistance': showlatesttagdistance, | |||
146 | 'manifest': showmanifest, |
|
187 | 'manifest': showmanifest, | |
147 | 'node': shownode, |
|
188 | 'node': shownode, | |
148 | 'rev': showrev, |
|
189 | 'rev': showrev, |
@@ -11,7 +11,7 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', 'repo', 'revcache'): |
|
14 | if k in ('templ', 'ctx', 'repo', 'revcache', 'cache'): | |
15 | continue |
|
15 | continue | |
16 | if hasattr(v, '__call__'): |
|
16 | if hasattr(v, '__call__'): | |
17 | v = v(**map) |
|
17 | v = v(**map) |
General Comments 0
You need to be logged in to leave comments.
Login now