[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-commits-diffs] net.venge.monotone: 5d8b9d46a8717039091ef619e2
From: |
code |
Subject: |
[Monotone-commits-diffs] net.venge.monotone: 5d8b9d46a8717039091ef619e2c1c00d25837063 |
Date: |
Wed, 9 Mar 2011 13:00:19 +0100 (CET) |
revision: 5d8b9d46a8717039091ef619e2c1c00d25837063
date: 2011-03-09T12:00:01
author: Richard Levitte <address@hidden>
branch: net.venge.monotone
changelog:
* contrib/monotone-cluster-push.lua: Moved ...
* extra/mtn-hooks/monotone-cluster-push.lua: ... here. Bugs fixed (among
others, a loop was missing, making it useless).
* test/extra/cvs-ignore/__driver__.lua: New test driver for
monotone-cluster-push.lua.
manifest:
format_version "1"
new_manifest [b7e365ed7771d403916b3e3bc315ba0647885a84]
old_revision [01d48aa4dce0b565ff49caa10a49f38ee79176b7]
rename "contrib/monotone-cluster-push.lua"
to "extra/mtn-hooks/monotone-cluster-push.lua"
add_dir "test/extra/cluster-push"
add_file "test/extra/cluster-push/__driver__.lua"
content [718f98e2a3702d2f351c86abf37d52773599f72d]
patch "extra/mtn-hooks/monotone-cluster-push.lua"
from [3a4f3bd0394d70d5c07c9314ad42026b212a4983]
to [698cb958e60f8a847f4a43f371e6fc222a5200ef]
============================================================
--- contrib/monotone-cluster-push.lua 3a4f3bd0394d70d5c07c9314ad42026b212a4983
+++ extra/mtn-hooks/monotone-cluster-push.lua 698cb958e60f8a847f4a43f371e6fc222a5200ef
@@ -1,4 +1,4 @@
--- Copyright (c) 2007 by Richard Levitte <address@hidden>
+-- Copyright (c) 2007, 2011 by Richard Levitte <address@hidden>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
@@ -34,46 +34,43 @@
--
-- include("/PATH/TO/monotone-cluster-push.lua")
--
--- You may want to change the following variables:
+-- You may want to set up the following variables:
--
-- MCP_rcfile
-- The absolute path to the configuration file used
--- by this script. It contains basio stanza with the
--- following keys:
+-- by this script.
+-- Default: {confdir}/cluster-push.rc
--
--- pattern Branch pattern, as in
--- read-permissions. MUST
--- come first in each stanza.
--- server Server address or address:port
--- to which this pattern should
--- be pushed. There may be many
--- of these.
+-- The configuration file must contain basic-io stanzas with the
+-- following keys:
--
--- The default is cluster-push.rc located in the server's
--- configuration directory.
+-- pattern Branch pattern, as in read-permissions. It MUST
+-- come first in each stanza.
+-- server Server address or address:port to which this
+-- pattern should be pushed. There may be many of
+-- these in each stanza.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
--- Variables
--------------------------------------------------------------------------------
-MCP_default_rcfile = get_confdir() .. "/cluster-push.rc"
-
-
-if not MCP_rcfile then MCP_rcfile = MCP_default_rcfile end
-
--------------------------------------------------------------------------------
-- Local hack of the note_netsync_* functions
-------------------------------------------------------------------------------
do
+ -- initialise rcfile with a default, or use MCP_rcfile if it's set
+ local rcfile = get_confdir() .. "/cluster-push.rc"
+ if MCP_rcfile then rcfile = MCP_rcfile end
+
local debug = false
- local quiet_startup = true
+ if MCP_debug then debug = true end
+ local verbose_startup = false
+ if MCP_verbose_startup then verbose_startup = true end
+
local branches = {}
- -- returns false if the rcfile wasn't parseable, otherwise true.
- -- if it was parseable, run the callback with each item as argument
+ -- returns false if the rcfile wasn't parseable, otherwise a table of
+ -- patterns with the servers they each should be pushed to.
local process_rcfile =
- function (_hook_name, _rcfile, _callback)
+ function (_hook_name, _rcfile)
if debug then
io.stderr:write(_hook_name, ": reading ", _rcfile,
"\n")
@@ -135,15 +132,18 @@ do
startup =
function(...)
local pattern_branches =
- process_rcfile("note_mtn_startup", MCP_rcfile, nil)
+ process_rcfile("monotone-cluster-push: startup", rcfile)
if pattern_branches then
for pattern, servers in pairs(pattern_branches) do
for _,server in pairs(servers) do
- if not quiet_startup then
- io.stderr:write("note_mtn_startup: pushing pattern \"",
- pattern, "\" to server ", server, "\n")
+ if not verbose_startup then
+ io.stderr:write("monotone-cluster-push: startup: ",
+ "pushing pattern \"", pattern,
+ "\" to server ", server, "\n")
end
- server_request_sync("push", server, pattern, "")
+ server_request_sync("push",
+ "mtn://"..server.."?"..pattern,
+ "", "")
end
end
end
@@ -153,7 +153,8 @@ do
start =
function (nonce, ...)
if debug then
- io.stderr:write("note_netsync_start: initialise branches\n")
+ io.stderr:write("monotone-cluster-push: start: ",
+ "initialise branches\n")
end
branches[nonce] = {}
return "continue",nil
@@ -167,8 +168,8 @@ do
end
if name == "branch" then
if debug then
- io.stderr:write("note_netsync_cert_received: branch ",
- value, " identified\n")
+ io.stderr:write("monotone-cluster-push: cert_received: ",
+ "branch ", value, " identified\n")
end
branches[nonce][value] = true
end
@@ -180,14 +181,14 @@ do
for _, item in pairs(certs)
do
if debug then
- io.stderr:write("note_netsync_revision_received: cert ",
- item.name, " with value ",
+ io.stderr:write("monotone-cluster-push: revision_received: ",
+ "cert ", item.name, " with value ",
item.value, " received\n")
end
if item.name == "branch" then
if debug then
- io.stderr:write("note_netsync_revision_received: branch ",
- item.value, " identified\n")
+ io.stderr:write("monotone-cluster-push: revision_received: ",
+ "branch ", item.value, " identified\n")
end
branches[nonce][item.value] = true
end
@@ -203,26 +204,35 @@ do
keys_in, keys_out,
...)
if debug then
- io.stderr:write("note_netsync_end: ",
+ io.stderr:write("monotone-cluster-push: end: ",
string.format("%d certs, %d revs, %d keys",
certs_in, revs_in, keys_in),
"\n")
end
if certs_in > 0 or revs_in > 0 or keys_in > 0 then
local pattern_branches =
- process_rcfile("note_netsync_end", MCP_rcfile, nil)
+ process_rcfile("monotone-cluster-push: end", rcfile, nil)
if pattern_branches then
for pattern, servers in pairs(pattern_branches) do
- if globish_match(pattern, branch) then
+ for branch, _ in pairs(branches[nonce]) do
if debug then
- io.stderr:write("note_netsync_end: it matches branch ",
- branch, "\n")
+ io.stderr:write("monotone-cluster-push: end: ",
+ "trying pattern ", pattern,
+ " with branch ", branch, "\n")
end
- for _,server in pairs(servers) do
- io.stderr:write("note_netsync_end: ",
- "pushing pattern \"", pattern,
- "\" to server ", server, "\n")
- server_request_sync("push", server.."?"..pattern, "")
+ if globish.match(pattern, branch) then
+ if debug then
+ io.stderr:write("monotone-cluster-push: end: ",
+ "it matches\n")
+ end
+ for _,server in pairs(servers) do
+ io.stderr:write("monotone-cluster-push: end: ",
+ "pushing pattern \"", pattern,
+ "\" to server ", server, "\n")
+ server_request_sync("push",
+ "mtn://"..server.."?"..pattern,
+ "", "")
+ end
end
end
end
============================================================
--- /dev/null
+++ test/extra/cluster-push/__driver__.lua 718f98e2a3702d2f351c86abf37d52773599f72d
@@ -0,0 +1,59 @@
+includecommon("netsync.lua")
+
+mtn_setup()
+netsync.setup()
+append("netsync.lua", "\
+\
+includedirpattern(get_confdir() .. \"/hooks.d\",\"*.conf\")\
+includedirpattern(get_confdir() .. \"/hooks.d\",\"*.lua\")\
+")
+mkdir("hooks.d")
+
+-- the server that shall receive the push from the other server
+srv1 = netsync.start(2)
+sleep(5)
+
+-- the server that shall push to the other server. We add this
+-- hook now, so the former server doesn't catch it
+check(copy(srcdir.."/../extra/mtn-hooks/monotone-cluster-push.lua",
+ "hooks.d/monotone-cluster-push.lua"))
+writefile("hooks.d/monotone-cluster-push.conf",
+ "MCP_debug = true\nMCP_verbose_startup=true\n")
+writefile("cluster-push.rc",
+ "\
+pattern \"*\"\
+server \""..srv1.address.."\"\n")
+srv2 = netsync.start(3)
+sleep(5)
+
+-- Move the hook, so we don't confuse the clients
+rename("hooks.d/monotone-cluster-push.conf",
+ "hooks.d/monotone-cluster-push.conf.disabled")
+rename("hooks.d/monotone-cluster-push.lua",
+ "hooks.d/monotone-cluster-push.lua.disabled")
+
+-- Now, send something to the second server
+addfile("foo", "bar")
+commit()
+srv2:push("testbranch",1)
+pushed_rev=base_revision()
+sleep(5)
+
+-- Destroy the client setup and rebuild it, so we can pull frmo scratch
+remove("test.db")
+remove("_MTN")
+mtn_setup()
+
+-- Now, fetch from the first server
+srv1:pull("testbranch",1)
+check(mtn("checkout", "--branch=testbranch", "checkout"), 0, false, false)
+savedir = chdir("checkout")
+pulled_rev=base_revision()
+chdir(savedir)
+
+-- Check that the revisions are the same
+check(pushed_rev == pulled_rev)
+
+-- Cleanup
+srv1:stop()
+srv2:stop()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Monotone-commits-diffs] net.venge.monotone: 5d8b9d46a8717039091ef619e2c1c00d25837063,
code <=