# HG changeset patch # User Christian Ebert # Date 1246462479 -7200 # Node ID b40e7861defdc9d1f1fead4e300f5dab7464f005 # Parent 795a95d7dc6193d72cfdf049beb108f17a1ecba1 Make repo.commit use a custom commitctx wrapper This avoids forcing the dirstate of overwritten files to normal during a commit. Thanks to Dan Villiom Podlaski Christiansen for the idea of a "double wrapper", so other extensions can still wrap repo.commitctx safely. diff -r 795a95d7dc61 -r b40e7861defd hgkw/keyword.py --- a/hgkw/keyword.py Mon Jun 29 18:37:08 2009 +0200 +++ b/hgkw/keyword.py Wed Jul 01 17:34:39 2009 +0200 @@ -189,7 +189,8 @@ if found: notify(msg % f) self.repo.wwrite(f, data, mf.flags(f)) - self.repo.dirstate.normal(f) + if node is None: + self.repo.dirstate.normal(f) self.restrict = False def shrinktext(self, text): @@ -460,8 +461,14 @@ def commit(self, text='', user=None, date=None, match=None, force=False, editor=None, extra={}): + # use custom commitctx for user commands + # other extensions can still wrap repo.commitctx directly + repo.commitctx = self.kwcommitctx + return super(kwrepo, self).commit(text, user, date, match, force, + editor, extra) + + def kwcommitctx(self, ctx, error=False): wlock = lock = None - _p1 = _p2 = None try: wlock = self.wlock() lock = self.lock() @@ -472,23 +479,17 @@ commithooks[name] = cmd ui.setconfig('hooks', name, None) if commithooks: - # store parents for commit hook environment - _p1, _p2 = repo.dirstate.parents() - _p1 = hex(_p1) - if _p2 == nullid: - _p2 = '' - else: - _p2 = hex(_p2) + # store parents for commit hooks + p1, p2 = ctx.p1(), ctx.p2() + xp1, xp2 = p1.hex(), p2 and p2.hex() or '' + + n = super(kwrepo, self).commitctx(ctx, error) - n = super(kwrepo, self).commit(text, user, date, match, force, - editor, extra) - - # restore commit hooks - for name, cmd in commithooks.iteritems(): - ui.setconfig('hooks', name, cmd) - if n is not None: - kwt.overwrite(n, True, None) - repo.hook('commit', node=n, parent1=_p1, parent2=_p2) + kwt.overwrite(n, True, None) + if commithooks: + for name, cmd in commithooks.iteritems(): + ui.setconfig('hooks', name, cmd) + repo.hook('commit', node=n, parent1=xp1, parent2=xp2) return n finally: release(lock, wlock)