[PATCH] keyword: wrap repo.commitctx instead of commit

Christian Ebert blacktrash at gmx.net
Mon Jun 29 23:21:06 UTC 2009


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1246317449 -7200
# Node ID 2a9b3d89cdda24eb72648a6e3b76c2cc4235c216
# Parent  3d11f8337bf9956c1fceb7dd937e22053cf33386
keyword: wrap repo.commitctx instead of commit

This avoids forcing the dirstate of overwritten files
to normal during a commit.

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -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):
@@ -458,10 +459,8 @@
             data = super(kwrepo, self).wread(filename)
             return kwt.wread(filename, data)
 
-        def commit(self, text='', user=None, date=None, match=None,
-                   force=False, editor=None, extra={}):
+        def commitctx(self, ctx, error=False):
             wlock = lock = None
-            _p1 = _p2 = None
             try:
                 wlock = self.wlock()
                 lock = self.lock()
@@ -472,23 +471,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).commit(text, user, date, match, force,
-                                               editor, extra)
+                n = super(kwrepo, self).commitctx(ctx, error)
 
-                # 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)



More information about the Mercurial-devel mailing list