hgkw/keyword.py
branchstable
changeset 691 44d25db950b4
parent 688 13bb123ad894
child 695 31b9e6615cec
equal deleted inserted replaced
686:17528ccdaa15 691:44d25db950b4
    77 '''
    77 '''
    78 
    78 
    79 from mercurial import commands, cmdutil, dispatch, filelog, revlog, extensions
    79 from mercurial import commands, cmdutil, dispatch, filelog, revlog, extensions
    80 from mercurial import patch, localrepo, templater, templatefilters, util, match
    80 from mercurial import patch, localrepo, templater, templatefilters, util, match
    81 from mercurial.hgweb import webcommands
    81 from mercurial.hgweb import webcommands
    82 from mercurial.lock import release
       
    83 from mercurial.node import nullid
    82 from mercurial.node import nullid
    84 from mercurial.i18n import _
    83 from mercurial.i18n import _
    85 import re, shutil, tempfile
    84 import re, shutil, tempfile
    86 
    85 
    87 commands.optionalrepo += ' kwdemo'
    86 commands.optionalrepo += ' kwdemo'
   262 def _kwfwrite(ui, repo, expand, *pats, **opts):
   261 def _kwfwrite(ui, repo, expand, *pats, **opts):
   263     '''Selects files and passes them to kwtemplater.overwrite.'''
   262     '''Selects files and passes them to kwtemplater.overwrite.'''
   264     if repo.dirstate.parents()[1] != nullid:
   263     if repo.dirstate.parents()[1] != nullid:
   265         raise util.Abort(_('outstanding uncommitted merge'))
   264         raise util.Abort(_('outstanding uncommitted merge'))
   266     kwt = kwtools['templater']
   265     kwt = kwtools['templater']
   267     status = _status(ui, repo, kwt, *pats, **opts)
   266     wlock = repo.wlock()
   268     modified, added, removed, deleted = status[:4]
       
   269     if modified or added or removed or deleted:
       
   270         raise util.Abort(_('outstanding uncommitted changes'))
       
   271     wlock = lock = None
       
   272     try:
   267     try:
   273         wlock = repo.wlock()
   268         status = _status(ui, repo, kwt, *pats, **opts)
   274         lock = repo.lock()
   269         modified, added, removed, deleted, unknown, ignored, clean = status
   275         kwt.overwrite(None, expand, status[6])
   270         if modified or added or removed or deleted:
       
   271             raise util.Abort(_('outstanding uncommitted changes'))
       
   272         kwt.overwrite(None, expand, clean)
   276     finally:
   273     finally:
   277         release(lock, wlock)
   274         wlock.release()
   278 
   275 
   279 def demo(ui, repo, *args, **opts):
   276 def demo(ui, repo, *args, **opts):
   280     '''print [keywordmaps] configuration and an expansion example
   277     '''print [keywordmaps] configuration and an expansion example
   281 
   278 
   282     Show current, custom, or default keyword template maps and their
   279     Show current, custom, or default keyword template maps and their
   483                 return super(kwrepo, self).commit(*args, **opts)
   480                 return super(kwrepo, self).commit(*args, **opts)
   484             finally:
   481             finally:
   485                 del self.commitctx
   482                 del self.commitctx
   486 
   483 
   487         def kwcommitctx(self, ctx, error=False):
   484         def kwcommitctx(self, ctx, error=False):
   488             wlock = lock = None
   485             n = super(kwrepo, self).commitctx(ctx, error)
   489             try:
   486             kwt.overwrite(n, True, None)
   490                 wlock = self.wlock()
   487             return n
   491                 lock = self.lock()
       
   492                 n = super(kwrepo, self).commitctx(ctx, error)
       
   493                 kwt.overwrite(n, True, None)
       
   494                 return n
       
   495             finally:
       
   496                 release(lock, wlock)
       
   497 
   488 
   498     # monkeypatches
   489     # monkeypatches
   499     def kwpatchfile_init(orig, self, ui, fname, opener,
   490     def kwpatchfile_init(orig, self, ui, fname, opener,
   500                          missing=False, eol=None):
   491                          missing=False, eol=None):
   501         '''Monkeypatch/wrap patch.patchfile.__init__ to avoid
   492         '''Monkeypatch/wrap patch.patchfile.__init__ to avoid