# # # add_file "contrib/monotone-run-script-post-netsync.lua" # content [0140c14f8c10632103017d252bea7f4becb975c1] # # patch "ChangeLog" # from [f7e8f58a4a00bfc3152931501bf763393ae3b8e1] # to [0609d91ae5fbacaf196bf230db60c298ee263215] # # patch "contrib/README" # from [58cb523ad71039ff8f4affd7da9e365cfbd82c11] # to [88e13f5d9cba985742a732c76620538067a92b14] # ============================================================ --- contrib/monotone-run-script-post-netsync.lua 0140c14f8c10632103017d252bea7f4becb975c1 +++ contrib/monotone-run-script-post-netsync.lua 0140c14f8c10632103017d252bea7f4becb975c1 @@ -0,0 +1,87 @@ +-- The following hooks are run as soon as revisions or certs to existing revisions +-- are arriving via netsync. Then they note if a particular, pre-defined branch +-- (_branch) is touched and if so, a script (_updater) is run at the end of the +-- netsync session. +-- +-- A sample script which updates a particular workspace automatically could look +-- like this. This is particularily useful if you manage a website with monotone +-- and want that your just committed changes popup on the web server: +-- +-- #!/bin/bash +-- branch="my.target.branch" +-- workspace="/path/to/workspace" +-- cd $workspace +-- # only update if there is no divergency +-- heads=`mtn heads -b $branch 2>/dev/null | wc -l` +-- if [ "$heads" != "1" ]; then exit; fi +-- mtn up -r "h:$branch" >/dev/null 2>&1 +-- +-- Copy the following lua hooks into your monotonerc file or load them with +-- --rcfile for the monotone process which serves your database. +-- +-- License: GPL +-- +-- Version history: +-- ---------------- +-- +-- 0.1 (2007-01-29) Thommas Keller +-- - initial version +-- + +_branch = "my.target.branch" +_updater = "/path/to/update.sh" +_sessions = {} + +-- fixme: only session_id is set, so we can't check the server's role or sync type here! +-- this seems to be some weird bug with monotone (tested with 0.31) +function note_netsync_start (session_id, my_role, sync_type, remote_host, remote_keyname, includes, excludes) + print("netsync_start: starting netsync communication") + _sessions[session_id] = 0 +end + +function note_netsync_revision_received (new_id, revision, certs, session_id) + if _sessions[session_id] == nil then + print("revision_received: no session present") + return + end + + for i,cert in ipairs(certs) do + if cert["name"] == "branch" and cert["value"] == _branch then + print("revision_received: found another interesting revision") + _sessions[session_id] = _sessions[session_id] + 1 + end + end +end + +-- check if an interesting cert has arrived due to propagate +function note_netsync_cert_received (rev_id, key, name, value, session_id) + if _sessions[session_id] == nil then + print("cert_received: no session present") + return + end + + if name == branch and value == _branch then + print("cert_received: found another interesting cert") + _sessions[session_id] = _sessions[session_id] + 1 + end +end + +function note_netsync_end (session_id, status, bytes_in, bytes_out, certs_in, certs_out, revs_in, revs_out, keys_in, keys_out) + if _sessions[session_id] == nil then + print("netsync_end: no session present") + return + end + + -- fixme: we should check status for being != 200, but as above, it seems as this is not set + + -- if no interesting revisions arrived, skip the update + if _sessions[session_id] == 0 then + print("netsync_end: no interesting revisions/certs received") + return + end + + _sessions[session_id] = nil + + print("netsync_end: running update script") + spawn(_updater) +end ============================================================ --- ChangeLog f7e8f58a4a00bfc3152931501bf763393ae3b8e1 +++ ChangeLog 0609d91ae5fbacaf196bf230db60c298ee263215 @@ -1,3 +1,8 @@ +2007-01-29 Thomas Keller + + * added some lua hooks to run a script after revs or certs have + arrived via netsync for a particular branch + 2007-01-29 Matthew Gregan * INSTALL: Drop the libboost-serialization-dev requirement since ============================================================ --- contrib/README 58cb523ad71039ff8f4affd7da9e365cfbd82c11 +++ contrib/README 88e13f5d9cba985742a732c76620538067a92b14 @@ -49,3 +49,6 @@ licenses. specification file. Both files has comments in the beginning, explaining how the specification files should be written. + + -- monotone-run-script-post-netsync.lua: run a script after revs or certs + for a particular branch have arrived via netsync