209 |
209 |
210 def __init__(self, ui, repo, inc, exc): |
210 def __init__(self, ui, repo, inc, exc): |
211 self.ui = ui |
211 self.ui = ui |
212 self.repo = repo |
212 self.repo = repo |
213 self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1] |
213 self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1] |
214 self.node = None |
214 self.commitnode = None |
215 self.path = '' |
215 self.path = '' |
216 |
216 |
217 kwmaps = self.ui.configitems('keywordmaps') |
217 kwmaps = self.ui.configitems('keywordmaps') |
218 if kwmaps: # override default templates |
218 if kwmaps: # override default templates |
219 kwmaps = [(k, templater.parsestring(v, quoted=False)) |
219 kwmaps = [(k, templater.parsestring(v, quoted=False)) |
235 except TypeError: |
235 except TypeError: |
236 return cmdutil.changeset_templater(self.ui, self.repo, |
236 return cmdutil.changeset_templater(self.ui, self.repo, |
237 False, None, '', False) |
237 False, None, '', False) |
238 |
238 |
239 def substitute(self, node, data, subfunc): |
239 def substitute(self, node, data, subfunc): |
240 '''Obtains node if missing, and calls given substitution function.''' |
240 '''Obtains file's changenode if commit node not given, |
241 if not self.node: |
241 and calls given substitution function.''' |
|
242 if self.commitnode: |
|
243 fnode = self.commitnode |
|
244 else: |
242 c = context.filectx(self.repo, self.path, fileid=node) |
245 c = context.filectx(self.repo, self.path, fileid=node) |
243 self.node = c.node() |
246 fnode = c.node() |
244 |
247 |
245 def kwsub(mobj): |
248 def kwsub(mobj): |
246 '''Substitutes keyword using corresponding template.''' |
249 '''Substitutes keyword using corresponding template.''' |
247 kw = mobj.group(1) |
250 kw = mobj.group(1) |
248 self.ct.use_template(self.templates[kw]) |
251 self.ct.use_template(self.templates[kw]) |
249 self.ui.pushbuffer() |
252 self.ui.pushbuffer() |
250 self.ct.show(changenode=self.node, |
253 self.ct.show(changenode=fnode, root=self.repo.root, file=self.path) |
251 root=self.repo.root, file=self.path) |
|
252 return '$%s: %s $' % (kw, templater.firstline(self.ui.popbuffer())) |
254 return '$%s: %s $' % (kw, templater.firstline(self.ui.popbuffer())) |
253 |
255 |
254 return subfunc(kwsub, data) |
256 return subfunc(kwsub, data) |
255 |
257 |
256 def expand(self, node, data): |
258 def expand(self, node, data): |
324 |
326 |
325 def _overwrite(ui, repo, node=None, expand=True, files=None): |
327 def _overwrite(ui, repo, node=None, expand=True, files=None): |
326 '''Overwrites selected files expanding/shrinking keywords.''' |
328 '''Overwrites selected files expanding/shrinking keywords.''' |
327 ctx = repo.changectx(node) |
329 ctx = repo.changectx(node) |
328 mf = ctx.manifest() |
330 mf = ctx.manifest() |
329 if files is None: |
331 if node is not None: # commit |
330 notify = ui.debug # commit |
332 _kwtemplater.commitnode = node |
331 files = [f for f in ctx.files() if mf.has_key(f)] |
333 files = [f for f in ctx.files() if mf.has_key(f)] |
332 else: |
334 notify = ui.debug |
333 notify = ui.note # kwexpand/kwshrink |
335 else: # kwexpand/kwshrink |
|
336 notify = ui.note |
334 candidates = [f for f in files if _iskwfile(f, mf.linkf)] |
337 candidates = [f for f in files if _iskwfile(f, mf.linkf)] |
335 if candidates: |
338 if candidates: |
336 overwritten = [] |
339 overwritten = [] |
337 candidates.sort() |
340 candidates.sort() |
338 action = expand and 'expanding' or 'shrinking' |
341 action = expand and 'expanding' or 'shrinking' |
339 _kwtemplater.node = node or ctx.node() |
|
340 for f in candidates: |
342 for f in candidates: |
341 fp = repo.file(f, kwmatch=True) |
343 fp = repo.file(f, kwmatch=True) |
342 data, kwfound = fp.kwctread(mf[f], expand) |
344 data, kwfound = fp.kwctread(mf[f], expand) |
343 if kwfound: |
345 if kwfound: |
344 notify(_('overwriting %s %s keywords\n') % (f, action)) |
346 notify(_('overwriting %s %s keywords\n') % (f, action)) |
500 def kwbailout(): |
502 def kwbailout(): |
501 '''Obtains command via simplified cmdline parsing, |
503 '''Obtains command via simplified cmdline parsing, |
502 returns True if keyword expansion not needed.''' |
504 returns True if keyword expansion not needed.''' |
503 nokwcommands = ('add', 'addremove', 'bundle', 'clone', 'copy', |
505 nokwcommands = ('add', 'addremove', 'bundle', 'clone', 'copy', |
504 'export', 'grep', 'identify', 'incoming', 'init', |
506 'export', 'grep', 'identify', 'incoming', 'init', |
505 'outgoing', 'push', 'remove', 'rename', 'rollback', |
507 'log', 'outgoing', 'push', 'remove', 'rename', |
|
508 'rollback', 'tip', |
506 'convert') |
509 'convert') |
507 args = fancyopts(sys.argv[1:], commands.globalopts, {}) |
510 args = fancyopts(sys.argv[1:], commands.globalopts, {}) |
508 if args: |
511 if args: |
509 aliases, i = findcmd(ui, args[0], commands.table) |
512 aliases, i = findcmd(ui, args[0], commands.table) |
510 return aliases[0] in nokwcommands |
513 return aliases[0] in nokwcommands |