478 def commit(self, *args, **opts): |
478 def commit(self, *args, **opts): |
479 # use custom commitctx for user commands |
479 # use custom commitctx for user commands |
480 # other extensions can still wrap repo.commitctx directly |
480 # other extensions can still wrap repo.commitctx directly |
481 self.commitctx = self.kwcommitctx |
481 self.commitctx = self.kwcommitctx |
482 try: |
482 try: |
483 return super(kwrepo, self).commit(*args, **opts) |
483 self._kwcommithooks = {} |
|
484 n = super(kwrepo, self).commit(*args, **opts) |
|
485 if self._kwcommithooks: |
|
486 xp1, xp2 = self._kwxp1, self._kwxp2 |
|
487 for name, cmd in self._kwcommithooks.iteritems(): |
|
488 ui.setconfig('hooks', name, cmd) |
|
489 self.hook('commit', node=n, parent1=xp1, parent2=xp2) |
|
490 return n |
484 finally: |
491 finally: |
485 del self.commitctx |
492 del self.commitctx |
486 |
493 |
487 def kwcommitctx(self, ctx, error=False): |
494 def kwcommitctx(self, ctx, error=False): |
488 wlock = lock = None |
495 wlock = lock = None |
489 try: |
496 try: |
490 wlock = self.wlock() |
497 wlock = self.wlock() |
491 lock = self.lock() |
498 lock = self.lock() |
492 # store and postpone commit hooks |
499 # store and postpone commit hooks |
493 commithooks = {} |
|
494 for name, cmd in ui.configitems('hooks'): |
500 for name, cmd in ui.configitems('hooks'): |
495 if name.split('.', 1)[0] == 'commit': |
501 if name.split('.', 1)[0] == 'commit': |
496 commithooks[name] = cmd |
502 self._kwcommithooks[name] = cmd |
497 ui.setconfig('hooks', name, None) |
503 ui.setconfig('hooks', name, None) |
498 if commithooks: |
504 if self._kwcommithooks: |
499 # store parents for commit hooks |
505 # store parents for commit hooks |
500 p1, p2 = ctx.p1(), ctx.p2() |
506 p1, p2 = ctx.p1(), ctx.p2() |
501 xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
507 self._kwxp1, self._kwxp2 = p1.hex(), p2 and p2.hex() or '' |
502 |
508 |
503 n = super(kwrepo, self).commitctx(ctx, error) |
509 n = super(kwrepo, self).commitctx(ctx, error) |
504 |
510 |
505 kwt.overwrite(n, True, None) |
511 kwt.overwrite(n, True, None) |
506 if commithooks: |
|
507 for name, cmd in commithooks.iteritems(): |
|
508 ui.setconfig('hooks', name, cmd) |
|
509 self.hook('commit', node=n, parent1=xp1, parent2=xp2) |
|
510 return n |
512 return n |
511 finally: |
513 finally: |
512 release(lock, wlock) |
514 release(lock, wlock) |
513 |
515 |
514 # monkeypatches |
516 # monkeypatches |