hgkw/keyword.py
changeset 600 b40e7861defd
parent 597 795a95d7dc61
child 602 b21fe4c86037
equal deleted inserted replaced
597:795a95d7dc61 600:b40e7861defd
   187                 else:
   187                 else:
   188                     found = self.re_kw.search(data)
   188                     found = self.re_kw.search(data)
   189                 if found:
   189                 if found:
   190                     notify(msg % f)
   190                     notify(msg % f)
   191                     self.repo.wwrite(f, data, mf.flags(f))
   191                     self.repo.wwrite(f, data, mf.flags(f))
   192                     self.repo.dirstate.normal(f)
   192                     if node is None:
       
   193                         self.repo.dirstate.normal(f)
   193             self.restrict = False
   194             self.restrict = False
   194 
   195 
   195     def shrinktext(self, text):
   196     def shrinktext(self, text):
   196         '''Unconditionally removes all keyword substitutions from text.'''
   197         '''Unconditionally removes all keyword substitutions from text.'''
   197         return self.re_kw.sub(r'$\1$', text)
   198         return self.re_kw.sub(r'$\1$', text)
   458             data = super(kwrepo, self).wread(filename)
   459             data = super(kwrepo, self).wread(filename)
   459             return kwt.wread(filename, data)
   460             return kwt.wread(filename, data)
   460 
   461 
   461         def commit(self, text='', user=None, date=None, match=None,
   462         def commit(self, text='', user=None, date=None, match=None,
   462                    force=False, editor=None, extra={}):
   463                    force=False, editor=None, extra={}):
       
   464             # use custom commitctx for user commands
       
   465             # other extensions can still wrap repo.commitctx directly
       
   466             repo.commitctx = self.kwcommitctx
       
   467             return super(kwrepo, self).commit(text, user, date, match, force,
       
   468                          editor, extra)
       
   469 
       
   470         def kwcommitctx(self, ctx, error=False):
   463             wlock = lock = None
   471             wlock = lock = None
   464             _p1 = _p2 = None
       
   465             try:
   472             try:
   466                 wlock = self.wlock()
   473                 wlock = self.wlock()
   467                 lock = self.lock()
   474                 lock = self.lock()
   468                 # store and postpone commit hooks
   475                 # store and postpone commit hooks
   469                 commithooks = {}
   476                 commithooks = {}
   470                 for name, cmd in ui.configitems('hooks'):
   477                 for name, cmd in ui.configitems('hooks'):
   471                     if name.split('.', 1)[0] == 'commit':
   478                     if name.split('.', 1)[0] == 'commit':
   472                         commithooks[name] = cmd
   479                         commithooks[name] = cmd
   473                         ui.setconfig('hooks', name, None)
   480                         ui.setconfig('hooks', name, None)
   474                 if commithooks:
   481                 if commithooks:
   475                     # store parents for commit hook environment
   482                     # store parents for commit hooks
   476                     _p1, _p2 = repo.dirstate.parents()
   483                     p1, p2 = ctx.p1(), ctx.p2()
   477                     _p1 = hex(_p1)
   484                     xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
   478                     if _p2 == nullid:
   485 
   479                         _p2 = ''
   486                 n = super(kwrepo, self).commitctx(ctx, error)
   480                     else:
   487 
   481                         _p2 = hex(_p2)
   488                 kwt.overwrite(n, True, None)
   482 
   489                 if commithooks:
   483                 n = super(kwrepo, self).commit(text, user, date, match, force,
   490                     for name, cmd in commithooks.iteritems():
   484                                                editor, extra)
   491                         ui.setconfig('hooks', name, cmd)
   485 
   492                     repo.hook('commit', node=n, parent1=xp1, parent2=xp2)
   486                 # restore commit hooks
       
   487                 for name, cmd in commithooks.iteritems():
       
   488                     ui.setconfig('hooks', name, cmd)
       
   489                 if n is not None:
       
   490                     kwt.overwrite(n, True, None)
       
   491                     repo.hook('commit', node=n, parent1=_p1, parent2=_p2)
       
   492                 return n
   493                 return n
   493             finally:
   494             finally:
   494                 release(lock, wlock)
   495                 release(lock, wlock)
   495 
   496 
   496     # monkeypatches
   497     # monkeypatches