hgkw/keyword.py
changeset 293 a7d568671575
parent 292 783c1310e20f
child 296 869b16d09eec
equal deleted inserted replaced
292:783c1310e20f 293:a7d568671575
    80         Or, better, use bundle/unbundle to share changes.
    80         Or, better, use bundle/unbundle to share changes.
    81 '''
    81 '''
    82 
    82 
    83 from mercurial import commands, cmdutil, context, fancyopts
    83 from mercurial import commands, cmdutil, context, fancyopts
    84 from mercurial import filelog, localrepo, revlog, templater, util
    84 from mercurial import filelog, localrepo, revlog, templater, util
       
    85 from mercurial.node import *
    85 from mercurial.i18n import _
    86 from mercurial.i18n import _
    86 import re, shutil, sys, tempfile, time
    87 import re, shutil, sys, tempfile, time
    87 
    88 
    88 commands.optionalrepo += ' kwdemo'
    89 commands.optionalrepo += ' kwdemo'
    89 
    90 
   325     quiet = ui.quiet
   326     quiet = ui.quiet
   326     verbose = ui.verbose
   327     verbose = ui.verbose
   327     ui.quiet = not verbose
   328     ui.quiet = not verbose
   328     commands.branch(ui, repo, branchname)
   329     commands.branch(ui, repo, branchname)
   329     ui.quiet = quiet
   330     ui.quiet = quiet
       
   331     for name, cmd in ui.configitems('hooks'):
       
   332         if name.split('.', 1)[0].find('commit') > -1:
       
   333             repo.ui.setconfig('hooks', name, '')
       
   334     ui.note(_('unhooked all commit hooks\n'))
   330     ui.note('hg -R "%s" ci -m "%s"\n' % (tmpdir, msg))
   335     ui.note('hg -R "%s" ci -m "%s"\n' % (tmpdir, msg))
   331     repo.commit(text=msg)
   336     repo.commit(text=msg)
   332     pathinfo = ('', ' in %s' % path)[ui.verbose]
   337     pathinfo = ('', ' in %s' % path)[ui.verbose]
   333     demostatus('%s keywords expanded%s' % (kwstatus, pathinfo))
   338     demostatus('%s keywords expanded%s' % (kwstatus, pathinfo))
   334     ui.write(repo.wread(fn))
   339     ui.write(repo.wread(fn))
   433                    p1=None, p2=None, extra={}):
   438                    p1=None, p2=None, extra={}):
   434             wlock = lock = None
   439             wlock = lock = None
   435             try:
   440             try:
   436                 wlock = self.wlock()
   441                 wlock = self.wlock()
   437                 lock = self.lock()
   442                 lock = self.lock()
       
   443                 # store and postpone commit hooks
       
   444                 # store parents for commit hook environment
       
   445                 commithooks = []
       
   446                 xp1, xp2 = p1, p2
       
   447                 for name, cmd in ui.configitems('hooks'):
       
   448                     if name.split('.', 1)[0] == 'commit':
       
   449                         commithooks.append((name, cmd))
       
   450                         ui.setconfig('hooks', name, '')
       
   451                 if commithooks:
       
   452                     if xp1 is None:
       
   453                         xp1, xp2 = repo.dirstate.parents()
       
   454                     elif not xp2:
       
   455                         xp2 = nullid
       
   456                     xp1 = hex(xp1)
       
   457                     if xp2 == nullid:
       
   458                         xp2 = ''
       
   459                     else:
       
   460                         xp2 = hex(xp2)
       
   461 
   438                 node = super(kwrepo,
   462                 node = super(kwrepo,
   439                              self).commit(files=files, text=text, user=user,
   463                              self).commit(files=files, text=text, user=user,
   440                                           date=date, match=match, force=force,
   464                                           date=date, match=match, force=force,
   441                                           force_editor=force_editor,
   465                                           force_editor=force_editor,
   442                                           p1=p1, p2=p2, extra=extra)
   466                                           p1=p1, p2=p2, extra=extra)
   446                     candidates = [f for f in cl[3] if mn.has_key(f)
   470                     candidates = [f for f in cl[3] if mn.has_key(f)
   447                                   and _iskwfile(ui, mn, f)]
   471                                   and _iskwfile(ui, mn, f)]
   448                     if candidates:
   472                     if candidates:
   449                         # 6th, 7th arguments set expansion, commit to True
   473                         # 6th, 7th arguments set expansion, commit to True
   450                         _overwrite(ui, self, candidates, node, mn, True, True)
   474                         _overwrite(ui, self, candidates, node, mn, True, True)
       
   475 
       
   476                 # restore commit hooks and run them
       
   477                 for name, cmd in commithooks:
       
   478                     ui.setconfig('hooks', name, cmd)
       
   479                 repo.hook('commit', node=node, parent1=xp1, parent2=xp2)
   451                 return node
   480                 return node
   452             finally:
   481             finally:
   453                 del wlock, lock
   482                 del wlock, lock
   454 
   483 
   455     repo.__class__ = kwrepo
   484     repo.__class__ = kwrepo