# # # patch "cmd_db.cc" # from [bb81c161035c666f5c625805bac19599c317e0d4] # to [d12f7b5a45aa0f00dcecf4939abce214efe1fff7] # # patch "cmd_netsync.cc" # from [2f2e37097e69603ab5de2f7687eb950a561638a9] # to [91c034049f4a24ee047e9e23a0af7a87f956c5af] # # patch "cmd_policy.cc" # from [f01bd509de385a3022c6d892d53ea4c01b856f03] # to [96bdd43f72b7f20ff4c5a6d3e9db73e9cf08cf6f] # # patch "policies/base_policy.cc" # from [9128088b7d91014132ff664c9b30436c0301e565] # to [bd24c2dd8a7cf76f531e77b3f473350c41d77d32] # # patch "policies/base_policy.hh" # from [5de53362e991cda313d70744f0de7fbd45d996d3] # to [3ec29b21d8f445d3f7ba653110881ec0d3e0f723] # # patch "policies/branch.cc" # from [38c0927a432186288494aff435c3676a7bd5398d] # to [4a716cffac6b04358b671879d1fc18de781cc3f5] # # patch "policies/branch.hh" # from [9ceb051153d9d73a97d4e265a8000edaa17cd72d] # to [fd1bcfa0ac885f4694ab1c92a090277d6548f736] # # patch "policies/delegation.cc" # from [ff7da4c3dac17be4d2ccc2196f3ead81f1dbc1f4] # to [f07135c6961e6f0e24d235c4cb7eacded192fa09] # # patch "policies/delegation.hh" # from [eab94abf3ef46037302c86df474cb8439539146d] # to [67ea638625029fc62827b9fa55e5fcc2c5aae8b3] # # patch "policies/policy.cc" # from [56c01f732a5be29d8584022a322b6516feb8d35d] # to [96779768279a3c5d1edec2daf75d69e3d78a6b2a] # # patch "project.cc" # from [a715b3fdaa732a08de9eb4f5d36c941be371a562] # to [6da439e7baec87534410df768d8398ba53eb469c] # # patch "tests/policy-netsync/__driver__.lua" # from [e7f90e5aefdca02e8103bf1daf06269f90995f40] # to [86d68a999aeecd7bd746eccb74b7410d9166a124] # # patch "tests/policy-tags/__driver__.lua" # from [a768859d89710cdd1ded5482f253a8fe12fca0b6] # to [6243335c2de53b2ef67f1a5c79618a50e2767b8d] # ============================================================ --- cmd_db.cc bb81c161035c666f5c625805bac19599c317e0d4 +++ cmd_db.cc d12f7b5a45aa0f00dcecf4939abce214efe1fff7 @@ -362,7 +362,6 @@ CMD(db_rosterify, "rosterify", "", CMD_R { database db(app); key_store keys(app); - project_t project(db, app.lua, app.opts); E(args.size() == 0, origin::user, F("no arguments needed")); @@ -371,6 +370,7 @@ CMD(db_rosterify, "rosterify", "", CMD_R db.check_is_not_rosterified(); // early short-circuit to avoid failure after lots of work + project_t project(db, app.lua, app.opts); cache_user_key(app.opts, project, keys, app.lua); build_roster_style_revs_from_manifest_style_revs(db, keys, project, ============================================================ --- cmd_netsync.cc 2f2e37097e69603ab5de2f7687eb950a561638a9 +++ cmd_netsync.cc 91c034049f4a24ee047e9e23a0af7a87f956c5af @@ -451,11 +451,11 @@ CMD_NO_WORKSPACE(clone, "clone", "", CMD helper.maybe_set_default_alias(app.opts); database db(app); - project_t project(db, app.lua, app.opts); key_store keys(app); db.create_if_not_exists(); db.ensure_open(); + project_t project(db, app.lua, app.opts); shared_conn_info info; arg_type server = idx(args, 0); ============================================================ --- project.cc a715b3fdaa732a08de9eb4f5d36c941be371a562 +++ project.cc 6da439e7baec87534410df768d8398ba53eb469c @@ -670,7 +670,7 @@ project_t::project_t(database & db, lua_ project_t::project_t(database & db, lua_hooks & lua, options & opts) : db(db), branch_option(opts.branch) { - shared_ptr bp(new policies::base_policy(opts, lua)); + shared_ptr bp(new policies::base_policy(opts, db)); project_policy.reset(new policy_info(bp->empty(), bp)); } ============================================================ --- cmd_policy.cc f01bd509de385a3022c6d892d53ea4c01b856f03 +++ cmd_policy.cc 96bdd43f72b7f20ff4c5a6d3e9db73e9cf08cf6f @@ -42,39 +42,53 @@ CMD(create_project, "create_project", "" } CMD(create_project, "create_project", "", CMD_REF(policy), - N_("NAME"), + N_("NAME [BRANCH_UID SIGNER SIGNER ...]"), N_("Bootstrap creation of a new project."), "", options::opts::none) { - if (args.size() != 1) + if (args.size() == 0 || args.size() == 2) throw usage(execid); database db(app); key_store keys(app); project_t project(db, app.lua, app.opts); - std::string project_name = idx(args, 0)(); - system_path project_dir = app.opts.conf_dir / "projects"; - system_path project_file = project_dir / path_component(project_name, origin::user); + string const project_name = idx(args, 0)(); - require_path_is_directory(app.opts.conf_dir, - F("Cannot find configuration directory."), - F("Configuration directory is a file.")); - require_path_is_nonexistent(project_file, - F("You already have a project with that name.")); + policies::editable_policy bp(project.get_base_policy()); - cache_user_key(app.opts, project, keys, app.lua); + if (args.size() == 1) + { + cache_user_key(app.opts, project, keys, app.lua); + std::set signers; + signers.insert(key_id_to_external_name(keys.signing_key)); - std::set signers; - signers.insert(key_id_to_external_name(keys.signing_key)); + bp.set_delegation(project_name, policies::delegation::create(signers)); + policies::delegation const & del = bp.get_delegation(project_name); + std::cout<::iterator i = signers.begin(); + i != signers.end(); ++i) + { + std::cout<<" "<<*i; + } + std::cout<<"\n"; + } + else + { + branch_uid const uid = typecast_vocab(idx(args, 1)); + std::set signers; + for (size_t i = 2; i < args.size(); ++i) + { + signers.insert(typecast_vocab(idx(args,i))); + } + bp.set_delegation(project_name, + policies::delegation::create(uid, signers)); + } - policies::editable_policy bp(project.get_base_policy()); - - bp.set_delegation(project_name, policies::delegation::create(signers)); - - policies::base_policy::write(app.lua, bp); + policies::base_policy::write(db, bp); } CMD(create_subpolicy, "create_subpolicy", "", CMD_REF(policy), ============================================================ --- tests/policy-netsync/__driver__.lua e7f90e5aefdca02e8103bf1daf06269f90995f40 +++ tests/policy-netsync/__driver__.lua 86d68a999aeecd7bd746eccb74b7410d9166a124 @@ -3,7 +3,12 @@ netsync.setup() mtn_setup() netsync.setup() -check(mtn("create_project", "test_project"), 0, false, false) +check(mtn("create_project", "test_project"), 0, true, false) +local project_args = {} +for w in string.gmatch(readfile("stdout"), "[^%s]+") do + table.insert(project_args, w) +end + check(mtn("create_branch", "test_project.testbranch"), 0, false, false) netsync.pull("test_project.*") @@ -12,6 +17,8 @@ rev1 = base_revision() commit("test_project.testbranch") rev1 = base_revision() +check(mtn2("create_project", unpack(project_args)), 0, false, false) + netsync.pull("test_project.*") check(mtn2("ls", "certs", rev1), 0, false) ============================================================ --- tests/policy-tags/__driver__.lua a768859d89710cdd1ded5482f253a8fe12fca0b6 +++ tests/policy-tags/__driver__.lua 6243335c2de53b2ef67f1a5c79618a50e2767b8d @@ -17,7 +17,8 @@ check(qgrep(revid:sub(0,10) .. ".*test_p check(qgrep(revid:sub(0,10) .. ".*test_project.testbranch", "stdout")) -rename("projects/test_project", "projects/testproj") +check(mtn("db", "execute", "update db_vars set name = cast('testproj' as blob) " .. + "where name = cast('test_project' as blob)"), 0, false, false) check(mtn("ls", "tags"), 0, true) check(qgrep("testproj.mytag", "stdout")) ============================================================ --- policies/base_policy.cc 9128088b7d91014132ff664c9b30436c0301e565 +++ policies/base_policy.cc bd24c2dd8a7cf76f531e77b3f473350c41d77d32 @@ -12,7 +12,7 @@ #include "policies/base_policy.hh" #include "branch_name.hh" -#include "lua_hooks.hh" +#include "database.hh" #include "options.hh" #include "transforms.hh" @@ -26,8 +26,9 @@ namespace policies { class database; namespace policies { - base_policy::base_policy(options const & opts, lua_hooks & lua): - _opts(opts), _lua(lua), _empty(true) + var_domain const policy_domain("policy_roots", origin::internal); + base_policy::base_policy(options const & opts, database & db): + _opts(opts), _db(db), _empty(true) { reload(); } @@ -49,24 +50,37 @@ namespace policies { _empty = false; } - typedef map hook_map; - hook_map hm; - _lua.hook_get_projects(hm); - for (hook_map::const_iterator i = hm.begin(); i != hm.end(); ++i) + map all_db_vars; + _db.get_vars(all_db_vars); + for (map::iterator i = all_db_vars.begin(); + i != all_db_vars.end(); ++i) { - if (delegations.find(i->first) == delegations.end()) + if (i->first.first != policy_domain) + continue; + string const delegation_name = i->first.second(); + string const delegation_data = i->second(); + pair r; + r = delegations.insert(make_pair(delegation_name, delegation())); + if (r.second) { - pair r; - r = delegations.insert(make_pair(i->first, delegation())); - r.first->second.deserialize(i->second()); + r.first->second.deserialize(delegation_data); _empty = false; } } } - void base_policy::write(lua_hooks & lua, policy const & pol) + void base_policy::write(database & db, policy const & pol) { - map hm; + transaction_guard guard(db); + map all_db_vars; + db.get_vars(all_db_vars); + for (map::iterator i = all_db_vars.begin(); + i != all_db_vars.end(); ++i) + { + if (i->first.first != policy_domain) + continue; + db.clear_var(i->first); + } policy::del_map const & delegations = pol.list_delegations(); for (policy::del_map::const_iterator d = delegations.begin(); @@ -74,10 +88,12 @@ namespace policies { { string s; d->second.serialize(s); - hm.insert(make_pair(d->first, data(s, origin::internal))); + var_name const delegation_name(d->first, origin::internal); + var_value const delegation_data(s, origin::internal); + db.set_var(make_pair(policy_domain, delegation_name), delegation_data); } - lua.hook_write_projects(hm); + guard.commit(); } } ============================================================ --- policies/base_policy.hh 5de53362e991cda313d70744f0de7fbd45d996d3 +++ policies/base_policy.hh 3ec29b21d8f445d3f7ba653110881ec0d3e0f723 @@ -14,7 +14,6 @@ class database; #include "policies/policy.hh" class database; -class lua_hooks; class options; namespace policies { @@ -22,16 +21,15 @@ namespace policies { class base_policy : public policy { options const & _opts; - lua_hooks & _lua; + database & _db; bool _empty; public: - base_policy(options const & opts, lua_hooks & lua); + base_policy(options const & opts, database & db); bool empty() const; void reload(); inline bool outdated() const { return false; } - // Use lua hooks to write out the given policy. - static void write(lua_hooks & lua, policy const & pol); + static void write(database & db, policy const & pol); }; } ============================================================ --- policies/branch.cc 38c0927a432186288494aff435c3676a7bd5398d +++ policies/branch.cc 4a716cffac6b04358b671879d1fc18de781cc3f5 @@ -39,6 +39,10 @@ namespace policies { namespace policies { branch::branch() { } + branch::branch(branch_uid const & uid, + std::set const & admins) + : uid(uid), signers(admins) + { } branch branch::create(std::set const & admins) { branch ret; ============================================================ --- policies/branch.hh 9ceb051153d9d73a97d4e265a8000edaa17cd72d +++ policies/branch.hh fd1bcfa0ac885f4694ab1c92a090277d6548f736 @@ -26,6 +26,8 @@ namespace policies { std::set signers; public: branch(); + branch(branch_uid const & uid, + std::set const & admins); static branch create(std::set const & admins); branch_uid const & get_uid() const; ============================================================ --- policies/delegation.cc ff7da4c3dac17be4d2ccc2196f3ead81f1dbc1f4 +++ policies/delegation.cc f07135c6961e6f0e24d235c4cb7eacded192fa09 @@ -42,6 +42,14 @@ namespace policies { ret.branch_desc = branch::create(admins); return ret; } + delegation delegation::create(branch_uid const & uid, + std::set const & admins) + { + delegation ret; + ret.type = branch_type; + ret.branch_desc = branch(uid, admins); + return ret; + } bool delegation::is_branch_type() const { ============================================================ --- policies/delegation.hh eab94abf3ef46037302c86df474cb8439539146d +++ policies/delegation.hh 67ea638625029fc62827b9fa55e5fcc2c5aae8b3 @@ -35,6 +35,8 @@ namespace policies { explicit delegation(revision_id const & r); explicit delegation(branch const & b); static delegation create(std::set const & admins); + static delegation create(branch_uid const & uid, + std::set const & admins); bool is_branch_type() const; branch const & get_branch_spec() const; ============================================================ --- policies/policy.cc 56c01f732a5be29d8584022a322b6516feb8d35d +++ policies/policy.cc 96779768279a3c5d1edec2daf75d69e3d78a6b2a @@ -65,6 +65,13 @@ namespace policies { return delegations; } + delegation const & policy::get_delegation(std::string const & name) const + { + del_map::const_iterator i = delegations.find(name); + I(i != delegations.end()); + return i->second; + } + map const & policy::list_branches() const { return branches;