##// END OF EJS Templates
keyword: be more efficient about ctx usage
Dirkjan Ochtman -
r7375:9f137013 default
parent child Browse files
Show More
@@ -139,19 +139,13 b' class kwtemplater(object):'
139 self.ct = cmdutil.changeset_templater(self.ui, self.repo,
139 self.ct = cmdutil.changeset_templater(self.ui, self.repo,
140 False, '', False)
140 False, '', False)
141
141
142 def getnode(self, path, fnode):
142 def substitute(self, data, path, ctx, subfunc):
143 '''Derives changenode from file path and filenode.'''
144 # used by kwfilelog.read and kwexpand
145 c = self.repo.filectx(path, fileid=fnode)
146 return c.node()
147
148 def substitute(self, data, path, node, subfunc):
149 '''Replaces keywords in data with expanded template.'''
143 '''Replaces keywords in data with expanded template.'''
150 def kwsub(mobj):
144 def kwsub(mobj):
151 kw = mobj.group(1)
145 kw = mobj.group(1)
152 self.ct.use_template(self.templates[kw])
146 self.ct.use_template(self.templates[kw])
153 self.ui.pushbuffer()
147 self.ui.pushbuffer()
154 self.ct.show(self.repo[node], root=self.repo.root, file=path)
148 self.ct.show(ctx, root=self.repo.root, file=path)
155 ekw = templatefilters.firstline(self.ui.popbuffer())
149 ekw = templatefilters.firstline(self.ui.popbuffer())
156 return '$%s: %s $' % (kw, ekw)
150 return '$%s: %s $' % (kw, ekw)
157 return subfunc(kwsub, data)
151 return subfunc(kwsub, data)
@@ -159,8 +153,8 b' class kwtemplater(object):'
159 def expand(self, path, node, data):
153 def expand(self, path, node, data):
160 '''Returns data with keywords expanded.'''
154 '''Returns data with keywords expanded.'''
161 if not self.restrict and self.matcher(path) and not util.binary(data):
155 if not self.restrict and self.matcher(path) and not util.binary(data):
162 changenode = self.getnode(path, node)
156 ctx = self.repo.filectx(path, fileid=node).changectx()
163 return self.substitute(data, path, changenode, self.re_kw.sub)
157 return self.substitute(data, path, ctx, self.re_kw.sub)
164 return data
158 return data
165
159
166 def iskwfile(self, path, flagfunc):
160 def iskwfile(self, path, flagfunc):
@@ -177,7 +171,7 b' class kwtemplater(object):'
177 files = [f for f in ctx.files() if f in mf]
171 files = [f for f in ctx.files() if f in mf]
178 notify = self.ui.debug
172 notify = self.ui.debug
179 else: # kwexpand/kwshrink
173 else: # kwexpand/kwshrink
180 ctx = self.repo['.']
174 ctx = self.repo[None]
181 mf = ctx.manifest()
175 mf = ctx.manifest()
182 notify = self.ui.note
176 notify = self.ui.note
183 candidates = [f for f in files if self.iskwfile(f, ctx.flags)]
177 candidates = [f for f in files if self.iskwfile(f, ctx.flags)]
@@ -190,8 +184,9 b' class kwtemplater(object):'
190 if util.binary(data):
184 if util.binary(data):
191 continue
185 continue
192 if expand:
186 if expand:
193 changenode = node or self.getnode(f, mf[f])
187 if node is None:
194 data, found = self.substitute(data, f, changenode,
188 ctx = self.repo.filectx(f, fileid=mf[f]).changectx()
189 data, found = self.substitute(data, f, ctx,
195 self.re_kw.subn)
190 self.re_kw.subn)
196 else:
191 else:
197 found = self.re_kw.search(data)
192 found = self.re_kw.search(data)
General Comments 0
You need to be logged in to leave comments. Login now