hgkw/keyword.py
branch0.9.2compat
changeset 360 ed06223f88fc
parent 359 4ac7e51443fe
child 366 b1105cc0982f
equal deleted inserted replaced
359:4ac7e51443fe 360:ed06223f88fc
    77 
    77 
    78 Expansions spanning more than one line and incremental expansions,
    78 Expansions spanning more than one line and incremental expansions,
    79 like CVS' $Log$, are not supported. A keyword template map
    79 like CVS' $Log$, are not supported. A keyword template map
    80 "Log = {desc}" expands to the first line of the changeset description.
    80 "Log = {desc}" expands to the first line of the changeset description.
    81 
    81 
    82 Caveat: "hg import" fails if the patch context contains an active
    82 Caveat: With Mercurial versions prior to 4574925db5c0 "hg import" might
    83         keyword. In that case run "hg kwshrink", and then reimport.
    83         cause rejects if the patch context contains an active keyword.
       
    84         In that case run "hg kwshrink", and then reimport.
    84         Or, better, use bundle/unbundle to share changes.
    85         Or, better, use bundle/unbundle to share changes.
    85 '''
    86 '''
    86 
    87 
    87 from mercurial import commands, cmdutil, context, filelog, localrepo
    88 from mercurial import commands, cmdutil, context, filelog
    88 from mercurial import patch, revlog, templater, util
    89 from mercurial import localrepo, revlog, templater, util
    89 from mercurial.node import *
    90 from mercurial.node import *
    90 from mercurial.i18n import gettext as _
    91 from mercurial.i18n import gettext as _
    91 import os.path, re, shutil, tempfile, time
    92 import os.path, re, shutil, tempfile, time
       
    93 
       
    94 try:
       
    95     # avoid spurious rejects if patchfile is available
       
    96     from mercurial.patch import patchfile
       
    97     _patchfile_init = patchfile.__init__
       
    98 except ImportError:
       
    99     _patchfile_init = None
    92 
   100 
    93 # backwards compatibility hacks
   101 # backwards compatibility hacks
    94 
   102 
    95 def _normal(repo, files):
   103 def _normal(repo, files):
    96     '''Backwards compatible repo.dirstate.normal/update.'''
   104     '''Backwards compatible repo.dirstate.normal/update.'''
   547                     repo.hook('commit', node=node, parent1=_p1, parent2=_p2)
   555                     repo.hook('commit', node=node, parent1=_p1, parent2=_p2)
   548                 return node
   556                 return node
   549             finally:
   557             finally:
   550                 del _wlock, _lock
   558                 del _wlock, _lock
   551 
   559 
   552     kwrepo._kwt = kwtemplater(ui, repo, inc, exc)
   560     kwt = kwrepo._kwt = kwtemplater(ui, repo, inc, exc)
       
   561 
       
   562     if _patchfile_init:
       
   563 
       
   564         def kwpatchfile_init(self, ui, fname, missing=False):
       
   565             '''Monkeypatch/wrap patch.patchfile.__init__ to avoid
       
   566             rejects or conflicts due to expanded keywords in working dir.'''
       
   567             _patchfile_init(self, ui, fname, missing=missing)
       
   568             if kwt.matcher(self.fname):
       
   569                 # shrink keywords read from working dir
       
   570                 kwshrunk = kwt.shrink(''.join(self.lines))
       
   571                 self.lines = kwshrunk.splitlines(True)
       
   572 
       
   573         patchfile.__init__ = kwpatchfile_init
       
   574 
   553     repo.__class__ = kwrepo
   575     repo.__class__ = kwrepo
   554 
   576 
   555 
   577 
   556 cmdtable = {
   578 cmdtable = {
   557     'kwcat':
   579     'kwcat':