# # # add_dir "tests/netsync_mtn_uri_scheme" # # add_file "tests/netsync_mtn_uri_scheme/__driver__.lua" # content [b31411d665b6aa92f6ae04396930f449f8412e56] # # patch "cmd_netsync.cc" # from [f1f2ecbdc31ebece21d44885bfc47ee43b60622e] # to [605c31efa097702173539bf481b2caa437fbad12] # # patch "lua_hooks.cc" # from [8b2119a72410c7c5f7f997473c61010f4cb1473a] # to [d8d705a6bb25bf199b715cc8e73489bf114b1c36] # # patch "lua_hooks.hh" # from [e9569a63763815809452a9705e7ed2c2b3a63e66] # to [9908c60aeec1949c6f8d16698ce2132d0120aeb7] # # patch "std_hooks.lua" # from [9fd3160c435eff59acc8622875047304e3472b9c] # to [7c97a71fda5accd86188472092e52f812dc848d1] # # patch "tests/test_hooks.lua" # from [843c3d1b361597a1b2302b4ca22e3cc72cbf238b] # to [268c94edd77cf0af6d976b87870787f11d4d7716] # ============================================================ --- tests/netsync_mtn_uri_scheme/__driver__.lua b31411d665b6aa92f6ae04396930f449f8412e56 +++ tests/netsync_mtn_uri_scheme/__driver__.lua b31411d665b6aa92f6ae04396930f449f8412e56 @@ -0,0 +1,30 @@ + +include("common/netsync.lua") +mtn_setup() +netsync.setup() + +addfile("file1", "foo") +commit("branch") + +addfile("file2", "bar") +commit("branch-test") + +addfile("file3", "baz") +commit("branch-test-exclude") + + +srv = netsync.start() + +check(mtn2("pull", "mtn://" .. srv.address .. "?branch-te*&!branch-test-*"), 0, false, false) +check(mtn2("ls", "branches"), 0, true) +check(not qgrep("^branch$", "stdout")) +check( qgrep("^branch-test$", "stdout")) +check(not qgrep("^branch-test-exclude$", "stdout")) + +check(mtn2("pull", "mtn://" .. srv.address), 0, false, false) +check(mtn2("ls", "branches"), 0, true) +check(qgrep("^branch$", "stdout")) +check(qgrep("^branch-test$", "stdout")) +check(qgrep("^branch-test-exclude$", "stdout")) + +srv:stop() ============================================================ --- cmd_netsync.cc f1f2ecbdc31ebece21d44885bfc47ee43b60622e +++ cmd_netsync.cc 605c31efa097702173539bf481b2caa437fbad12 @@ -90,7 +90,8 @@ extract_patterns(options & opts, databas static void extract_patterns(options & opts, database & db, args_vector const & args, - globish & include_pattern, globish & exclude_pattern) + globish & include_pattern, globish & exclude_pattern, + bool host_is_uri) { if (args.size() >= 2 || opts.exclude_given) { @@ -112,7 +113,7 @@ extract_patterns(options & opts, databas db.set_var(default_exclude_pattern_key, var_value(exclude_pattern())); } } - else + else if (!host_is_uri) { N(db.var_exists(default_include_pattern_key), F("no branch pattern given and no default pattern set")); @@ -146,19 +147,10 @@ build_client_connection_info(options & o info.client.exclude_pattern = exclude; info.client.unparsed = addr; parse_uri(info.client.unparsed(), info.client.u); - if (lua.hook_get_netsync_connect_command(info.client.u, - info.client.include_pattern, - info.client.exclude_pattern, - global_sanity.debug_p(), - info.client.argv)) - { - info.client.use_argv = true; - opts.use_transport_auth = lua.hook_use_transport_auth(info.client.u); - } - else - { - info.client.use_argv = false; - } + info.client.use_argv = false; + lua.hook_get_netsync_connect_command(info, + global_sanity.debug_p()); + opts.use_transport_auth = lua.hook_use_transport_auth(info.client.u); if (opts.use_transport_auth) { find_key(opts, lua, db, keys, info, need_key); @@ -178,7 +170,8 @@ extract_client_connection_info(options & globish inc; globish exc; extract_address(opts, db, args, addr); - extract_patterns(opts, db, args, inc, exc); + parse_uri(addr(), info.client.u); + extract_patterns(opts, db, args, inc, exc, !info.client.u.host.empty()); build_client_connection_info(opts, lua, db, keys, addr, inc, exc, info, need_key); } ============================================================ --- lua_hooks.cc 8b2119a72410c7c5f7f997473c61010f4cb1473a +++ lua_hooks.cc d8d705a6bb25bf199b715cc8e73489bf114b1c36 @@ -23,6 +23,7 @@ #include "app_state.hh" #include "file_io.hh" #include "lua_hooks.hh" +#include "netcmd.hh" #include "sanity.hh" #include "vocab.hh" #include "transforms.hh" @@ -608,31 +609,28 @@ bool } bool -lua_hooks::hook_get_netsync_connect_command(uri const & u, - globish const & include_pattern, - globish const & exclude_pattern, - bool debug, - std::vector & argv) +lua_hooks::hook_get_netsync_connect_command(netsync_connection_info & info, + bool debug) { bool cmd = false, exec_ok = false; Lua ll(st); ll.func("get_netsync_connect_command"); - push_uri(u, ll); + push_uri(info.client.u, ll); ll.push_table(); - if (!include_pattern().empty()) + if (!info.client.include_pattern().empty()) { ll.push_str("include"); - ll.push_str(include_pattern()); + ll.push_str(info.client.include_pattern()); ll.set_table(); } - if (!exclude_pattern().empty()) + if (!info.client.exclude_pattern().empty()) { ll.push_str("exclude"); - ll.push_str(exclude_pattern()); + ll.push_str(info.client.exclude_pattern()); ll.set_table(); } @@ -646,15 +644,63 @@ lua_hooks::hook_get_netsync_connect_comm ll.call(2,1); ll.begin(); + + netsync_connection_info info2(info); - argv.clear(); + info2.client.argv.clear(); + info2.client.use_argv = false; + bool not_use_argv = false; while(ll.next()) { std::string s; ll.extract_str(s).pop(); - argv.push_back(s); + if (!lua_isnumber(st, -1)) + { + std::string k; + ll.extract_str(k); // do not pop + // can be URI parts, or include/exclude + if (k == "scheme") + info2.client.u.scheme = s; + else if (k == "user") + info2.client.u.user = s; + else if (k == "host") + info2.client.u.host = s; + else if (k == "port") + info2.client.u.port = s; + else if (k == "path") + info2.client.u.path = s; + else if (k == "query") + info2.client.u.query = s; + else if (k == "fragment") + info2.client.u.fragment = s; + else if (k == "include") + info2.client.include_pattern = s; + else if (k == "exclude") + info2.client.exclude_pattern = s; + else + W(F("get_netsync_connect_command hook returned unknown item '%s'") + % k); + + not_use_argv = true; + } + else + { + info2.client.argv.push_back(s); + info2.client.use_argv = true; + } } - return ll.ok() && !argv.empty(); + E(!(info2.client.use_argv && not_use_argv), + F("get_netsync_command returned inconsistent data")); + + if (ll.ok()) + { + info = info2; + return true; + } + else + { + return false; + } } ============================================================ --- lua_hooks.hh e9569a63763815809452a9705e7ed2c2b3a63e66 +++ lua_hooks.hh 9908c60aeec1949c6f8d16698ce2132d0120aeb7 @@ -26,6 +26,8 @@ struct options; struct globish; struct options; +struct netsync_connection_info; + extern app_state* get_app_state(lua_State *L); class lua_hooks @@ -71,11 +73,8 @@ public: globish const & include, globish const & exclude, rsa_keypair_id & k); - bool hook_get_netsync_connect_command(uri const & u, - globish const & include_pattern, - globish const & exclude_pattern, - bool debug, - std::vector & argv); + bool hook_get_netsync_connect_command(netsync_connection_info & info, + bool debug); bool hook_use_transport_auth(uri const & u); bool hook_get_netsync_read_permitted(std::string const & branch, ============================================================ --- std_hooks.lua 9fd3160c435eff59acc8622875047304e3472b9c +++ std_hooks.lua 7c97a71fda5accd86188472092e52f812dc848d1 @@ -1056,6 +1056,41 @@ function get_netsync_connect_command(uri local argv = nil + local include = {} + local exclude = {} + if uri["query"] then + for ex, pat in string.gmatch(uri["query"], "(!?)([^!&]+)") do + if pat and string.len(pat) > 0 then + if ex == "!" then + table.insert(exclude, pat) + else + table.insert(include, pat) + end + end + end + end + + if uri["scheme"] == "mtn" then + local ret = {} + + local inc = table.concat(include, ",") + local exc = table.concat(exclude, ",") + + if inc == "" then + ret.include = "*" + else + ret.include = "{" .. inc .. "}" + end + + if exc == "" then + ret.exclude = "" + else + ret.exclude = "{" .. exc .. "}" + end + + return ret + end + if uri["scheme"] == "ssh" and uri["host"] and uri["path"] then ============================================================ --- tests/test_hooks.lua 843c3d1b361597a1b2302b4ca22e3cc72cbf238b +++ tests/test_hooks.lua 268c94edd77cf0af6d976b87870787f11d4d7716 @@ -87,7 +87,7 @@ do function get_netsync_connect_command(uri, args) local argv = std_get_netsync_connect_command(uri, args) - if argv then + if argv and argv[1] then table.insert(argv, "--confdir="..get_confdir()) table.insert(argv, "--rcfile="..get_confdir().."/test_hooks.lua") end