Running post-commit hooks on the server?

Andrew Bennetts andrew at canonical.com
Mon Oct 8 12:23:01 BST 2007


Daniel Pittman wrote:
[...]
> So, it looks like the answer to the first part -- rebuilding and sending
> email -- is to use the "smart" server.  If so, where is the use of hooks
> in the "smart server" documented so I know how to have it do these
> things?

Unfortunately, it's not possible at the moment.

The smart server protocol isn't quite good enough yet to provide something you
can hook.  I think ideally you'd be able to write a plugin that used
“Branch.hooks.install_hook('set_rh', ...)” to install a hook to be run when a
branch's revision history changes (this should happen regardless of whether the
client is pushing from an independent branch, or performing a commit in a
checkout of the remote branch).  That hook on the Branch object exists, but the
client never calls any method that will trigger it, because setting the revision
history is done by the “dumb” fallback to just uploading a new version of the
.bzr/branch/last-revision file (or equivalent, e.g.
.bzr/branch/revision-history for older formats).  So because that is still
implemented via file operations, the Branch object never gets a chance to run
its hooks.

Thinking about it, it's probably fairly easy fix this.  In fact, there's already
a very similar “Branch.set_last_revision” remote method, I think perhaps we just
need a corresponding “Branch.set_last_revision_info” that sets both revision_id
and revno, and to use it in RemoteBranch.set_last_revision_info, so that we stop
using file-level operations for this.

I'll see if I can add that smart method in the next day or so, because AFAIK
that's the only thing stopping hooks from working on the server.  If someone
else wants to have a go, I'm happy to point them in the write direction; adding
new smart methods is pretty easy.

-Andrew.




More information about the bazaar mailing list