Commit hook handling entirely into if-condition
authorChristian Ebert <blacktrash@gmx.net>
Sun, 11 Nov 2007 11:29:50 +0100
changeset 296 869b16d09eec
parent 294 343c5dd8dcda
child 297 9e29992343a1
Commit hook handling entirely into if-condition
hgkw/keyword.py
--- a/hgkw/keyword.py	Sat Nov 10 14:08:12 2007 +0100
+++ b/hgkw/keyword.py	Sun Nov 11 11:29:50 2007 +0100
@@ -441,23 +441,17 @@
                 wlock = self.wlock()
                 lock = self.lock()
                 # store and postpone commit hooks
-                # store parents for commit hook environment
                 commithooks = []
-                xp1, xp2 = p1, p2
                 for name, cmd in ui.configitems('hooks'):
                     if name.split('.', 1)[0] == 'commit':
                         commithooks.append((name, cmd))
                         ui.setconfig('hooks', name, '')
                 if commithooks:
-                    if xp1 is None:
-                        xp1, xp2 = repo.dirstate.parents()
-                    elif not xp2:
-                        xp2 = nullid
-                    xp1 = hex(xp1)
-                    if xp2 == nullid:
-                        xp2 = ''
+                    # store parents for commit hook environment
+                    if p1 is None:
+                        _p1, _p2 = repo.dirstate.parents()
                     else:
-                        xp2 = hex(xp2)
+                        _p1, _p2 = p1, p2 or nullid
 
                 node = super(kwrepo,
                              self).commit(files=files, text=text, user=user,
@@ -473,10 +467,16 @@
                         # 6th, 7th arguments set expansion, commit to True
                         _overwrite(ui, self, candidates, node, mn, True, True)
 
-                # restore commit hooks and run them
-                for name, cmd in commithooks:
-                    ui.setconfig('hooks', name, cmd)
-                repo.hook('commit', node=node, parent1=xp1, parent2=xp2)
+                if commithooks:
+                    # restore commit hooks and run them
+                    for name, cmd in commithooks:
+                        ui.setconfig('hooks', name, cmd)
+                    xp1 = hex(_p1)
+                    if _p2 == nullid:
+                        xp2 = ''
+                    else:
+                        xp2 = hex(_p2)
+                    repo.hook('commit', node=node, parent1=xp1, parent2=xp2)
                 return node
             finally:
                 del wlock, lock