hgext/keyword.py
changeset 6504 1be53f931c9c
parent 6503 4572beeacff1
child 6505 7ae26bb2d5cc
equal deleted inserted replaced
6503:4572beeacff1 6504:1be53f931c9c
   126                                     inc=kwtools['inc'], exc=kwtools['exc'])[1]
   126                                     inc=kwtools['inc'], exc=kwtools['exc'])[1]
   127         self.restrict = kwtools['hgcmd'] in restricted.split()
   127         self.restrict = kwtools['hgcmd'] in restricted.split()
   128 
   128 
   129         kwmaps = self.ui.configitems('keywordmaps')
   129         kwmaps = self.ui.configitems('keywordmaps')
   130         if kwmaps: # override default templates
   130         if kwmaps: # override default templates
   131             kwmaps = [(k, templater.parsestring(v, quoted=False))
   131             kwmaps = [(k, templater.parsestring(v, False))
   132                       for (k, v) in kwmaps]
   132                       for (k, v) in kwmaps]
   133             self.templates = dict(kwmaps)
   133             self.templates = dict(kwmaps)
   134         escaped = map(re.escape, self.templates.keys())
   134         escaped = map(re.escape, self.templates.keys())
   135         kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped)
   135         kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped)
   136         self.re_kw = re.compile(kwpat)
   136         self.re_kw = re.compile(kwpat)
   239         return self.kwt.expand(self.path, node, data)
   239         return self.kwt.expand(self.path, node, data)
   240 
   240 
   241     def add(self, text, meta, tr, link, p1=None, p2=None):
   241     def add(self, text, meta, tr, link, p1=None, p2=None):
   242         '''Removes keyword substitutions when adding to filelog.'''
   242         '''Removes keyword substitutions when adding to filelog.'''
   243         text = self.kwt.shrink(self.path, text)
   243         text = self.kwt.shrink(self.path, text)
   244         return super(kwfilelog, self).add(text, meta, tr, link, p1=p1, p2=p2)
   244         return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)
   245 
   245 
   246     def cmp(self, node, text):
   246     def cmp(self, node, text):
   247         '''Removes keyword substitutions for comparison.'''
   247         '''Removes keyword substitutions for comparison.'''
   248         text = self.kwt.shrink(self.path, text)
   248         text = self.kwt.shrink(self.path, text)
   249         if self.renamed(node):
   249         if self.renamed(node):
   300     kwstatus = 'current'
   300     kwstatus = 'current'
   301     fn = 'demo.txt'
   301     fn = 'demo.txt'
   302     branchname = 'demobranch'
   302     branchname = 'demobranch'
   303     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
   303     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
   304     ui.note(_('creating temporary repo at %s\n') % tmpdir)
   304     ui.note(_('creating temporary repo at %s\n') % tmpdir)
   305     repo = localrepo.localrepository(ui, path=tmpdir, create=True)
   305     repo = localrepo.localrepository(ui, tmpdir, True)
   306     ui.setconfig('keyword', fn, '')
   306     ui.setconfig('keyword', fn, '')
   307     if args or opts.get('rcfile'):
   307     if args or opts.get('rcfile'):
   308         kwstatus = 'custom'
   308         kwstatus = 'custom'
   309     if opts.get('rcfile'):
   309     if opts.get('rcfile'):
   310         ui.readconfig(opts.get('rcfile'))
   310         ui.readconfig(opts.get('rcfile'))
   479                     if _p2 == nullid:
   479                     if _p2 == nullid:
   480                         _p2 = ''
   480                         _p2 = ''
   481                     else:
   481                     else:
   482                         _p2 = hex(_p2)
   482                         _p2 = hex(_p2)
   483 
   483 
   484                 node = super(kwrepo,
   484                 n = super(kwrepo, self).commit(files, text, user, date, match,
   485                              self).commit(files=files, text=text, user=user,
   485                                                force, force_editor, p1, p2,
   486                                           date=date, match=match, force=force,
   486                                                extra, empty_ok)
   487                                           force_editor=force_editor,
       
   488                                           p1=p1, p2=p2, extra=extra,
       
   489                                           empty_ok=empty_ok)
       
   490 
   487 
   491                 # restore commit hooks
   488                 # restore commit hooks
   492                 for name, cmd in commithooks.iteritems():
   489                 for name, cmd in commithooks.iteritems():
   493                     ui.setconfig('hooks', name, cmd)
   490                     ui.setconfig('hooks', name, cmd)
   494                 if node is not None:
   491                 if n is not None:
   495                     kwt.overwrite(node=node)
   492                     kwt.overwrite(node=n)
   496                     repo.hook('commit', node=node, parent1=_p1, parent2=_p2)
   493                     repo.hook('commit', node=n, parent1=_p1, parent2=_p2)
   497                 return node
   494                 return n
   498             finally:
   495             finally:
   499                 del wlock, lock
   496                 del wlock, lock
   500 
   497 
   501     # monkeypatches
   498     # monkeypatches
   502     def kwpatchfile_init(self, ui, fname, missing=False):
   499     def kwpatchfile_init(self, ui, fname, missing=False):
   503         '''Monkeypatch/wrap patch.patchfile.__init__ to avoid
   500         '''Monkeypatch/wrap patch.patchfile.__init__ to avoid
   504         rejects or conflicts due to expanded keywords in working dir.'''
   501         rejects or conflicts due to expanded keywords in working dir.'''
   505         patchfile_init(self, ui, fname, missing=missing)
   502         patchfile_init(self, ui, fname, missing)
   506         # shrink keywords read from working dir
   503         # shrink keywords read from working dir
   507         self.lines = kwt.shrinklines(self.fname, self.lines)
   504         self.lines = kwt.shrinklines(self.fname, self.lines)
   508 
   505 
   509     def kw_diff(repo, node1=None, node2=None, files=None, match=util.always,
   506     def kw_diff(repo, node1=None, node2=None, files=None, match=util.always,
   510                 fp=None, changes=None, opts=None):
   507                 fp=None, changes=None, opts=None):
   512         comparing against working dir.'''
   509         comparing against working dir.'''
   513         if node2 is not None:
   510         if node2 is not None:
   514             kwt.matcher = util.never
   511             kwt.matcher = util.never
   515         elif node1 is not None and node1 != repo.changectx().node():
   512         elif node1 is not None and node1 != repo.changectx().node():
   516             kwt.restrict = True
   513             kwt.restrict = True
   517         patch_diff(repo, node1=node1, node2=node2, files=files, match=match,
   514         patch_diff(repo, node1, node2, files, match, fp, changes, opts)
   518                    fp=fp, changes=changes, opts=opts)
       
   519 
   515 
   520     def kwweb_changeset(web, req, tmpl):
   516     def kwweb_changeset(web, req, tmpl):
   521         '''Wraps webcommands.changeset turning off keyword expansion.'''
   517         '''Wraps webcommands.changeset turning off keyword expansion.'''
   522         kwt.matcher = util.never
   518         kwt.matcher = util.never
   523         return webcommands_changeset(web, req, tmpl)
   519         return webcommands_changeset(web, req, tmpl)