##// END OF EJS Templates
cmdutil: extract latest tags closures in templatekw
Patrick Mezard -
r10057:babc00a8 default
parent child Browse files
Show More
@@ -763,9 +763,7 b' class changeset_templater(changeset_prin'
763 763 'manifest': '{rev}:{node|formatnode}',
764 764 'filecopy': '{name} ({source})',
765 765 'extra': '{key}={value|stringescape}'})
766 # Cache mapping from rev to a tuple with tag date, tag
767 # distance and tag name
768 self._latesttagcache = {-1: (0, 0, 'null')}
766 self.cache = {}
769 767
770 768 def use_template(self, t):
771 769 '''set template string to use'''
@@ -783,30 +781,6 b' class changeset_templater(changeset_prin'
783 781 return []
784 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 784 def _show(self, ctx, copies, props):
811 785 '''show a single changeset or file revision'''
812 786
@@ -820,17 +794,10 b' class changeset_templater(changeset_prin'
820 794 def showcopies(repo, ctx, templ, **args):
821 795 c = [{'name': x[0], 'source': x[1]} for x in copies]
822 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 798 defprops = {
830 799 'file_copies': showcopies,
831 800 'parents': showparents,
832 'latesttag': showlatesttag,
833 'latesttagdistance': showlatesttagdistance,
834 801 }
835 802 props = props.copy()
836 803 props.update(templatekw.keywords)
@@ -839,6 +806,7 b' class changeset_templater(changeset_prin'
839 806 props['ctx'] = ctx
840 807 props['repo'] = self.repo
841 808 props['revcache'] = {}
809 props['cache'] = self.cache
842 810
843 811 # find correct templates for current mode
844 812
@@ -75,6 +75,39 b' def getfiles(repo, ctx, revcache):'
75 75 ctx.node())[:3]
76 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 111 def showauthor(repo, ctx, templ, **args):
79 112 return ctx.user()
80 113
@@ -117,6 +150,12 b' def showfilemods(repo, ctx, templ, revca'
117 150 def showfiles(repo, ctx, templ, **args):
118 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 159 def showmanifest(repo, ctx, templ, **args):
121 160 args = args.copy()
122 161 args.update(dict(rev=repo.manifest.rev(ctx.changeset()[0]),
@@ -143,6 +182,8 b' keywords = {'
143 182 'file_dels': showfiledels,
144 183 'file_mods': showfilemods,
145 184 'files': showfiles,
185 'latesttag': showlatesttag,
186 'latesttagdistance': showlatesttagdistance,
146 187 'manifest': showmanifest,
147 188 'node': shownode,
148 189 'rev': showrev,
@@ -11,7 +11,7 b' class mytemplater(object):'
11 11 def process(self, t, map):
12 12 tmpl = self.loader(t)
13 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 15 continue
16 16 if hasattr(v, '__call__'):
17 17 v = v(**map)
General Comments 0
You need to be logged in to leave comments. Login now