[PATCH 3 of 3] localrepo: introduce new hook 'postupdate'

Adrian Buehlmann adrian at cadifra.com
Wed May 20 13:07:29 CDT 2009


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1242664704 -7200
# Node ID 647382e36fed707bd0c5f761aa6d6b5f2bf97ff1
# Parent  ecb607c5062dafd7d37457cace84b3ce1a0594e4
localrepo: introduce new hook 'postupdate'

is triggered after the dirstate has been written to disk,
which is later than the 'update' hook.

diff --git a/doc/hgrc.5.txt b/doc/hgrc.5.txt
--- a/doc/hgrc.5.txt
+++ b/doc/hgrc.5.txt
@@ -454,6 +454,13 @@ hooks::
     Run after successful invocations of the associated command. The
     contents of the command line are passed as $HG_ARGS and the result
     code in $HG_RESULT. Hook failure is ignored.
+  postupdate;;
+    Run whenever the status cache for the working tree (.hg/dirstate)
+    has been updated. This hook is run after the 'update' hook (see
+    further down), and may for example be used to update working tree
+    file status indicators in GUI tools (e.g. "changed" icons).
+    (Note that .hg/dirstate has not yet been updated when the 'update'
+    hook runs.)
   pre-<command>;;
     Run before executing the associated command. The contents of the
     command line are passed as $HG_ARGS. If the hook returns failure,
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -686,7 +686,8 @@ class localrepository(repo.repository):
             l.lock()
             return l
 
-        l = self._lock(self.join("wlock"), wait, self.dirstate.write,
+        def dswrite(): self.dirstate.write(); self.hook('postupdate')
+        l = self._lock(self.join("wlock"), wait, dswrite,
                        self.dirstate.invalidate, _('working directory of %s') %
                        self.origroot)
         self._wlockref = weakref.ref(l)
diff --git a/tests/test-hook b/tests/test-hook
--- a/tests/test-hook
+++ b/tests/test-hook
@@ -78,6 +78,7 @@ hg update 1
 
 # update hook
 echo 'update = python ../printenv.py update' >> .hg/hgrc
+echo 'postupdate = python ../printenv.py postupdate' >> .hg/hgrc
 hg update
 
 # prechangegroup hook can prevent incoming changes
diff --git a/tests/test-hook.out b/tests/test-hook.out
--- a/tests/test-hook.out
+++ b/tests/test-hook.out
@@ -74,6 +74,7 @@ preupdate hook: HG_PARENT1=b702efe96888
 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
 preupdate hook: HG_PARENT1=8ea2ef7ad3e8 
 update hook: HG_ERROR=0 HG_PARENT1=8ea2ef7ad3e8 
+postupdate hook: 
 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
 3:4c52fb2e4022
 prechangegroup.forbid hook: HG_SOURCE=pull HG_URL=file: 


More information about the Mercurial-devel mailing list