Issue38

Title only one hook of any kind possible
Priority feature Status resolved
Superseder Nosy List bos, tonfa, vadim
Assigned To vadim Topics

Created on 2005-10-26.03:50:43 by vadim, last changed 2005-11-04.23:20:27 by vadim.

Files
File name Uploaded Type Edit Remove
export.diff tonfa, 2005-10-30.09:35:41 text/x-patch
Messages
msg139 (view) Author: bos Date: 2005-11-04.23:16:45
this works well for me, thank you.
msg103 (view) Author: tonfa Date: 2005-10-30.09:35:41
The attached patch documents it. Please correct any mistake (i am not a native
english speaker).

Thanks
msg99 (view) Author: mpm Date: 2005-10-29.21:04:26
This also needs an hgrc.5 update and a mention on the wiki.
msg97 (view) Author: mpm Date: 2005-10-29.20:42:10
Someone forgot to run 'make tests'. Fixed in tip.
msg94 (view) Author: tonfa Date: 2005-10-29.09:08:07
# HG changeset patch
# User Benoit Boissinot <benoit.boissinot@ens-lyon.org>
# Node ID 8ae6e720f3c11bb0032cef2acba519e8a0677550
# Parent  1a3c6689ef2b46442f87debae53584bdbb1bf6b1
allow multiples hook

suggested by Vadim Gelfer
This patch allows to have multiple hooks of the same kind:
for example
commit.email = /my/email/hook
commit.autobuild = /my/build/hook

diff -r 1a3c6689ef2b -r 8ae6e720f3c1 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Fri Oct 28 17:18:50 2005 -0700
+++ b/mercurial/localrepo.py	Sat Oct 29 11:02:41 2005 +0200
@@ -47,9 +47,8 @@
         except IOError: pass

     def hook(self, name, **args):
-        s = self.ui.config("hooks", name)
-        if s:
-            self.ui.note(_("running hook %s: %s\n") % (name, s))
+        def runhook(name, cmd)
+            self.ui.note(_("running hook %s: %s\n") % (name, cmd))
             old = {}
             for k, v in args.items():
                 k = k.upper()
@@ -59,7 +58,7 @@
             # Hooks run in the repository root
             olddir = os.getcwd()
             os.chdir(self.root)
-            r = os.system(s)
+            r = os.system(cmd)
             os.chdir(olddir)

             for k, v in old.items():
@@ -72,7 +71,14 @@
                 self.ui.warn(_("abort: %s hook failed with status %d!\n") %
                              (name, r))
                 return False
-        return True
+            return True
+
+        r = True
+        for hname, cmd in ui.configitems("hooks"):
+            s = hname.split(".")
+            if s[0] == name and cmd:
+                r = runhook(hname, cmd) and r
+        return r

     def tags(self):
         '''return a mapping of tag to node'''
msg67 (view) Author: vadim Date: 2005-10-26.14:43:32
for question 1, i think the way to do is to have a prefix for naming hooks. example:

commit.email = /my/email/hook
commit.autobuild = /my/build/hook

so all hooks that is named commit or commit.something are run as a commit hook.
you can override a hook in /etc/mercurial or somewhere by a change of its value
in a different hgrc file, or turn off by setting it to an empty string.

for question 2, a site-wide hook is something that is run by all users and hosts
that share a hgrc file. i do not want to put the hooks under revision control, i
just do not want to maintaining 50 copies of the same file on 25 machines.
msg63 (view) Author: mpm Date: 2005-10-26.05:29:46
This raises some interesting questions:

- how would you explicitly override a site-wide hook?
- what does it mean to have a site-wide hook on a distributed system?
msg56 (view) Author: vadim Date: 2005-10-26.03:50:43
mercurial supports hooks, but i can only make one hook of any kind. this means i
cannot have a site-wide commit hook and a per-user commit hook, because the
per-user hook always is used.
History
Date User Action Args
2005-11-04 23:20:27vadimsetnosy: + bos
2005-11-04 23:16:45bossetstatus: testing -> resolved
nosy: vadim, tonfa
messages: + msg139
2005-10-31 18:45:01mpmsetstatus: chatting -> testing
assignedto: vadim
nosy: vadim, tonfa
2005-10-30 09:35:41tonfasetfiles: + export.diff
nosy: vadim, tonfa
messages: + msg103
2005-10-29 21:04:26mpmsetnosy: vadim, tonfa
messages: + msg99
2005-10-29 20:42:11mpmsetnosy: vadim, tonfa
messages: + msg97
2005-10-29 09:09:40tonfasetpriority: bug -> feature
nosy: + tonfa
2005-10-29 09:08:07tonfasetmessages: + msg94
2005-10-26 14:43:32vadimsetmessages: + msg67
2005-10-26 05:29:46mpmsetstatus: unread -> chatting
messages: + msg63
2005-10-26 03:50:43vadimcreate