'start_commit' hook is unhookable?
Brian de Alwis
bsd at cs.ubc.ca
Sat Aug 2 18:51:27 BST 2008
So I hacked together a tiny plugin to use the 'start_commit' hook to
clear exec bits for a tree. This failed on bzr 1.5, but I wrote the
failure off at the time thinking that 'start_commit' must have been a
new hook for 1.6. But I've just installed 1.6b3 and the problem is
there. And poking around, I discovered that 'start_commit' was
actually added in 1.4.
I get the following error in the log:
> [17636] 2008-08-02 11:40:23.992 WARNING: Unable to load plugin
> 'clear_exec_bit'
> from '/Users/bsd/.bazaar/plugins'
> 0.494 Traceback (most recent call last):
> File "/usr/pkg/lib/python2.4/site-packages/bzrlib/plugin.py", line
> 210, in loa
> d_from_dir
> exec "import bzrlib.plugins.%s" % name in {}
> File "<string>", line 1, in ?
> File "/Users/bsd/.bazaar/plugins/clear_exec_bit.py", line 23, in ?
> Branch.hooks.install_named_hook(
> File "/usr/pkg/lib/python2.4/site-packages/bzrlib/hooks.py", line
> 75, in insta
> ll_named_hook
> raise errors.UnknownHook(self.__class__.__name__, hook_name)
> UnknownHook: The BranchHooks hook 'start_commit' is unknown in this
> version of b
> zrlib.
I'd hazard that the plugins are being loaded before the
MutableTreeHooks.__init__() (which defines the 'start_commit' hook) is
being called?
I've attached my simple plugin here.
------------------------------------------------------------
# For projects defining 'clear_exec_bit = on', this hook will first
# perform a `chmod a-x' for all files as a pre-commit hook.
import os
from bzrlib import urlutils
from bzrlib.branch import Branch
from bzrlib.config import LocationConfig
def start_commit_hook(tree):
config = LocationConfig(tree.basedir) # unsure if this is right
# maybe this should specify glob patterns instead...
enabled = (config.get_user_option('clear_exec_bit') in
(u'on', u'yes', u'ye', u'y'))
if not enabled:
return
base = tree.basedir # it's how cmd_root does it
# questionable whether single-quoting is the right thing
print "clearing exec bits in " + base
os.system("find '" + base + "' -type f -print0 | xargs -0 chmod a-
x")
Branch.hooks.install_named_hook(
'start_commit', start_commit_hook, 'clear executable bit')
------------------------------------------------------------
--
Brian de Alwis | Software Practices Lab | UBC | http://www.cs.ubc.ca/~bsd/
"Amusement to an observing mind is study." - Benjamin Disraeli
More information about the bazaar
mailing list