From 8a55952204ba29f0cab49b38cea79661d9d10cb8 Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Thu, 28 Oct 2010 19:45:45 +0200 Subject: [PATCH] * use the built-in push_hook_functions to register the netsync hooks, this way additional hooks which need these notifications as well do not override earlier hooks * optionally include an additional hooks.lua file at the very end in which custom hooks can be defined --- .../Plugin/SyncMonotone/monotonerc-auth.tpl | 53 ++++++++++-------- .../Plugin/SyncMonotone/monotonerc-noauth.tpl | 55 +++++++++++-------- 2 files changed, 62 insertions(+), 46 deletions(-) diff --git a/src/IDF/Plugin/SyncMonotone/monotonerc-auth.tpl b/src/IDF/Plugin/SyncMonotone/monotonerc-auth.tpl index daf3307..7e5ff8c 100644 --- a/src/IDF/Plugin/SyncMonotone/monotonerc-auth.tpl +++ b/src/IDF/Plugin/SyncMonotone/monotonerc-auth.tpl @@ -34,30 +34,37 @@ end -- let IDF know of new arriving revisions to fill its timeline -- _idf_revs = {} -function note_netsync_start(session_id) - _idf_revs[session_id] = {} -end +push_hook_functions({ + ["start"] = function (session_id) + _idf_revs[session_id] = {} + return "continue",nil + end, + ["revision_received"] = function (new_id, revision, certs, session_id) + table.insert(_idf_revs[session_id], new_id) + return "continue",nil + end, + ["end"] = function (session_id, ...) + if table.getn(_idf_revs[session_id]) == 0 then + return "continue",nil + end -function note_netsync_revision_received(new_id, revision, certs, session_id) - table.insert(_idf_revs[session_id], new_id) -end + local pin,pout,pid = spawn_pipe("%%MTNPOSTPUSH%%", "%%PROJECT%%"); + if pid == -1 then + print("could not execute %%MTNPOSTPUSH%%") + return + end -function note_netsync_end (session_id, ...) - if table.getn(_idf_revs[session_id]) == 0 then - return + for _,r in ipairs(_idf_revs[session_id]) do + pin:write(r .. "\n") + end + pin:close() + + wait(pid) + return "continue",nil end +}) - local pin,pout,pid = spawn_pipe("%%MTNPOSTPUSH%%", "%%PROJECT%%"); - if pid == -1 then - print("could execute %%MTNPOSTPUSH%%") - return - end - - for _,r in ipairs(_idf_revs[session_id]) do - pin:write(r .. "\n") - end - pin:close() - - wait(pid) -end - +-- +-- Load additional local hooks, in case they exist +-- +include(get_confdir() .. "/hooks.lua") diff --git a/src/IDF/Plugin/SyncMonotone/monotonerc-noauth.tpl b/src/IDF/Plugin/SyncMonotone/monotonerc-noauth.tpl index c0c0050..e59aa04 100644 --- a/src/IDF/Plugin/SyncMonotone/monotonerc-noauth.tpl +++ b/src/IDF/Plugin/SyncMonotone/monotonerc-noauth.tpl @@ -31,7 +31,8 @@ function get_remote_automate_permitted(key_identity, command, options) "leaves", "ancestry_difference", "toposort", "erase_ancestors", "descendents", "ancestors", "heads", "get_file_of", "get_file", "interface_version", "get_attributes", "content_diff", - "file_merge", "show_conflicts", "certs", "keys" + "file_merge", "show_conflicts", "certs", "keys", "get_file_size", + "get_extended_manifest_of" } for _,v in ipairs(read_only_commands) do @@ -47,29 +48,37 @@ end -- let IDF know of new arriving revisions to fill its timeline -- _idf_revs = {} -function note_netsync_start(session_id) - _idf_revs[session_id] = {} -end +push_hook_functions({ + ["start"] = function (session_id) + _idf_revs[session_id] = {} + return "continue",nil + end, + ["revision_received"] = function (new_id, revision, certs, session_id) + table.insert(_idf_revs[session_id], new_id) + return "continue",nil + end, + ["end"] = function (session_id, ...) + if table.getn(_idf_revs[session_id]) == 0 then + return "continue",nil + end -function note_netsync_revision_received(new_id, revision, certs, session_id) - table.insert(_idf_revs[session_id], new_id) -end + local pin,pout,pid = spawn_pipe("%%MTNPOSTPUSH%%", "%%PROJECT%%"); + if pid == -1 then + print("could not execute %%MTNPOSTPUSH%%") + return + end -function note_netsync_end (session_id, ...) - if table.getn(_idf_revs[session_id]) == 0 then - return + for _,r in ipairs(_idf_revs[session_id]) do + pin:write(r .. "\n") + end + pin:close() + + wait(pid) + return "continue",nil end +}) - local pin,pout,pid = spawn_pipe("%%MTNPOSTPUSH%%", "%%PROJECT%%"); - if pid == -1 then - print("could execute %%MTNPOSTPUSH%%") - return - end - - for _,r in ipairs(_idf_revs[session_id]) do - pin:write(r .. "\n") - end - pin:close() - - wait(pid) -end +-- +-- Load additional local hooks, in case they exist +-- +include(get_confdir() .. "/hooks.lua")