# # # patch "cmd_policy.cc" # from [5962413a38906b1c862afa55dd1059ae2f43106a] # to [7d52becabc871309313d51c8e6aa2de07fc010a0] # # patch "project.cc" # from [f9eb9aba664b6fd0cc2c26060b6cdd57cb20305f] # to [9c1b0a62e26875c7b8991d5a3c3fdc57f894a347] # # patch "project.hh" # from [f18835d5a0bc939f48558bc121af77288aff4a5e] # to [5e66ecaf7dff55782fe4997e8c713cb4fb196595] # ============================================================ --- cmd_policy.cc 5962413a38906b1c862afa55dd1059ae2f43106a +++ cmd_policy.cc 7d52becabc871309313d51c8e6aa2de07fc010a0 @@ -97,40 +97,21 @@ CMD(create_subpolicy, "create_subpolicy" branch_name name = prefix; name.append(branch_name("__policy__", origin::internal)); - editable_policy parent; - branch_name parent_prefix; - E(project.get_policy_branch_policy_of(name, parent, parent_prefix), - origin::user, - F("Cannot find parent policy for %s") % prefix); - P(F("Parent policy: %s") % parent_prefix); + governing_policy_info gov; + project.find_governing_policy(name(), gov); - std::string subprefix; - E(prefix() != parent_prefix(), origin::user, - F("A policy for %s already exists.") % prefix); - I(prefix().find(parent_prefix() + ".") == 0); - subprefix = prefix().substr(parent_prefix().size()+1); + policies::policy_branch parent_branch(gov.governing_policy_parent->get_delegation(gov.delegation_to_governing_policy)); - cache_user_key(app.opts, app.lua, db, keys, project); - std::set admin_keys; - { - key_identity_info ident; - ident.id = keys.signing_key; - project.complete_key_identity(keys, app.lua, ident); - admin_keys.insert(typecast_vocab(ident.official_name)); - } + policies::editable_policy parent(*parent_branch.begin()); + policies::policy_branch new_policy_branch(policy_branch::new_branch()); + policies::policy new_policy(new_policy_branch.create_initial_revision()); - editable_policy child(db, admin_keys); - shared_ptr - del = parent.get_delegation(subprefix, true); - del->uid = child.uid; - del->committers = admin_keys; + parent.set_delegation(name, new_policy.get_delegation("__policy__")); transaction_guard guard(db); - project_t p = project_t::empty_project(db); - child.commit(p, keys, utf8(N_("Create new policy branch"))); - parent.commit(p, keys, utf8(N_("Add new delegation"))); - + new_policy_branch.commit(new_policy, utf8("")); + parent_branch.commit(parent, utf8("Add delegation to new child policy")); guard.commit(); } ============================================================ --- project.cc f9eb9aba664b6fd0cc2c26060b6cdd57cb20305f +++ project.cc 9c1b0a62e26875c7b8991d5a3c3fdc57f894a347 @@ -157,14 +157,7 @@ public: }; -struct governing_policy_info -{ - shared_ptr governing_policy; - std::string governing_policy_name; - shared_ptr governing_policy_parent; - std::string delegation_to_governing_policy; -}; // find the policy governing a particular name class policy_finder { @@ -886,6 +879,14 @@ void } void +project_t::find_governing_policy(string const & of_what, + governing_policy_info & info) +{ + I(!project_policy->passthru); + project_policy->find_governing_policy(of_what, info); +} + +void project_t::put_tag(key_store & keys, revision_id const & id, string const & name) ============================================================ --- project.hh f18835d5a0bc939f48558bc121af77288aff4a5e +++ project.hh 5e66ecaf7dff55782fe4997e8c713cb4fb196595 @@ -78,6 +78,15 @@ namespace policies { class policy; } +struct governing_policy_info +{ + boost::shared_ptr governing_policy; + std::string governing_policy_name; + + boost::shared_ptr governing_policy_parent; + std::string delegation_to_governing_policy; +}; + class project_t { // In the hypothetical future situation where one monotone process is @@ -105,6 +114,9 @@ public: policies::policy & get_base_policy() const; + void find_governing_policy(std::string const & of_what, + governing_policy_info & info); + //bool get_policy_branch_policy_of(branch_name const & name, // editable_policy & policy_branch_policy, // branch_name & policy_prefix);