98 return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0])) |
98 return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0])) |
99 |
99 |
100 class kwtemplater(object): |
100 class kwtemplater(object): |
101 ''' |
101 ''' |
102 Sets up keyword templates, corresponding keyword regex, and |
102 Sets up keyword templates, corresponding keyword regex, and |
103 provides keyword expansion function. |
103 provides keyword substitution functions. |
104 ''' |
104 ''' |
105 def __init__(self, ui, repo): |
105 def __init__(self, ui, repo): |
106 self.ui = ui |
106 self.ui = ui |
107 self.repo = repo |
107 self.repo = repo |
108 templates = dict(ui.configitems('keywordmaps')) |
108 templates = dict(ui.configitems('keywordmaps')) |
130 self.ui.pushbuffer() |
130 self.ui.pushbuffer() |
131 self.t.show(changenode=node, root=self.repo.root, file=path) |
131 self.t.show(changenode=node, root=self.repo.root, file=path) |
132 keywordsub = templater.firstline(self.ui.popbuffer()) |
132 keywordsub = templater.firstline(self.ui.popbuffer()) |
133 return '$%s: %s $' % (kw, keywordsub) |
133 return '$%s: %s $' % (kw, keywordsub) |
134 |
134 |
135 def expand(self, path, node, data): |
135 def expand(self, path, node, filelog, data): |
136 '''Returns data with expanded keywords.''' |
136 '''Returns data with expanded keywords.''' |
137 if util.binary(data): |
137 if util.binary(data): |
138 return data |
138 return data |
139 return self.re_kw.sub(lambda m: self.kwsub(m, path, node), data) |
139 c = context.filectx(self.repo, path, fileid=node, filelog=filelog) |
|
140 cnode = c.node() |
|
141 return self.re_kw.sub(lambda m: self.kwsub(m, path, cnode), data) |
140 |
142 |
141 def shrink(self, text): |
143 def shrink(self, text): |
142 '''Returns text with all keyword substitutions removed.''' |
144 '''Returns text with all keyword substitutions removed.''' |
143 if util.binary(text): |
145 if util.binary(text): |
144 return text |
146 return text |
225 |
227 |
226 def read(self, node): |
228 def read(self, node): |
227 '''Substitutes keywords when reading filelog.''' |
229 '''Substitutes keywords when reading filelog.''' |
228 data = super(kwfilelog, self).read(node) |
230 data = super(kwfilelog, self).read(node) |
229 if self.kwt: |
231 if self.kwt: |
230 c = context.filectx(self._repo, self._path, |
232 data = self.kwt.expand(self._path, node, self, data) |
231 fileid=node, filelog=self) |
|
232 data = self.kwt.expand(self._path, c.node(), data) |
|
233 return data |
233 return data |
234 |
234 |
235 def add(self, text, meta, tr, link, p1=None, p2=None): |
235 def add(self, text, meta, tr, link, p1=None, p2=None): |
236 '''Removes keyword substitutions when adding to filelog.''' |
236 '''Removes keyword substitutions when adding to filelog.''' |
237 if self.kwt: |
237 if self.kwt: |