add pretxncommit hook.
authorVadim Gelfer <vadim.gelfer@gmail.com>
Tue, 14 Feb 2006 17:13:18 -0800
changeset 1721 801756d0ca84
parent 1720 55017891051b
child 1722 681c5c211b92
add pretxncommit hook. hook allows check of changeset after create, but before transaction is committed. hook failure rolls transaction back. makes place for local policies like commit message must contain bug id or reviewer signoff. change also adds parent changeset ids to commit hook environment, because is cheap and useful.
doc/hgrc.5.txt
mercurial/localrepo.py
--- a/doc/hgrc.5.txt	Tue Feb 14 15:47:25 2006 -0800
+++ b/doc/hgrc.5.txt	Tue Feb 14 17:13:18 2006 -0800
@@ -151,19 +151,27 @@
   commit;;
     Run after a changeset has been created in the local repository.
     Passed the ID of the newly created changeset in environment
-    variable $NODE.
+    variable $NODE.  Parent changeset IDs in $P1 and $P2.
   incoming;;
     Run after a changeset has been pulled, pushed, or unbundled into
     the local repository.  Passed the ID of the newly arrived
     changeset in environment variable $NODE.
   precommit;;
-    Run before starting a commit.  Exit status 0 allows the commit to
-    proceed.  Non-zero status will cause the commit to fail.
+    Run before starting a local commit.  Exit status 0 allows the
+    commit to proceed.  Non-zero status will cause the commit to
+    fail.  Parent changeset IDs in $P1 and $P2.
   pretag;;
     Run before creating a tag.  Exit status 0 allows the tag to be
     created.  Non-zero status will cause the tag to fail.  ID of
     changeset to tag in $NODE.  Name of tag in $TAG.  Tag is local if
     $LOCAL=1, in repo if $LOCAL=0.
+  pretxncommit;;
+    Run after a changeset has been created but the transaction not yet
+    committed.  Changeset is visible to hook program.  This lets you
+    validate commit message and changes.  Exit status 0 allows the
+    commit to proceed.  Non-zero status will cause the transaction to
+    be rolled back.  ID of changeset in $NODE.  Parent changeset IDs
+    in $P1 and $P2.
   tag;;
     Run after a tag is created.  ID of tagged changeset in $NODE.
     Name of tag in $TAG.  Tag is local if $LOCAL=1, in repo if
--- a/mercurial/localrepo.py	Tue Feb 14 15:47:25 2006 -0800
+++ b/mercurial/localrepo.py	Tue Feb 14 17:13:18 2006 -0800
@@ -376,7 +376,11 @@
             self.ui.status(_("nothing changed\n"))
             return None
 
-        self.hook("precommit", throw=True)
+        xp1 = hex(p1)
+        if p2 == nullid: xp2 = ''
+        else: xp2 = hex(p2)
+
+        self.hook("precommit", throw=True, p1=xp1, p2=xp2)
 
         if not wlock:
             wlock = self.wlock()
@@ -462,13 +466,14 @@
 
         user = user or self.ui.username()
         n = self.changelog.add(mn, changed + remove, text, tr, p1, p2, user, date)
+        self.hook('pretxncommit', throw=True, node=hex(n), p1=xp1, p2=xp2)
         tr.close()
 
         self.dirstate.setparents(n)
         self.dirstate.update(new, "n")
         self.dirstate.forget(remove)
 
-        self.hook("commit", node=hex(n))
+        self.hook("commit", node=hex(n), p1=xp1, p2=xp2)
         return n
 
     def walk(self, node=None, files=[], match=util.always):