# # # patch "cmd_policy.cc" # from [9ba12a36360c7f0169d527f7f3b62f703fbb898e] # to [e79e797749b222ee0a39f662ecea1dddc8627b66] # # patch "policies/policy_branch.cc" # from [148c64957fed2c05fc8ee69e2b31ec5552ae1399] # to [9f5cf990e17f3b68ea31d5bbf7829343098ae714] # # patch "policies/policy_branch.hh" # from [2cf62bc1c862c968fa2b660796fcd79ddee1bab3] # to [f333957457d5b6a866e7f7186651f0f194e4e60d] # # patch "project.cc" # from [bd4ba14ebb6347ab6b707b96624ea5fb0f915886] # to [0d4f00a7c962d3dbbff1d23bf80e825b9eb19d02] # # patch "tests/policy-subpolicies/__driver__.lua" # from [3bbc3c470bdc0575e0304aba59deebb94d10d720] # to [8b5e1949367181788b0b6b396736ceade92cb1cd] # ============================================================ --- cmd_policy.cc 9ba12a36360c7f0169d527f7f3b62f703fbb898e +++ cmd_policy.cc e79e797749b222ee0a39f662ecea1dddc8627b66 @@ -102,6 +102,9 @@ CMD(create_subpolicy, "create_subpolicy" F("Policy '%s' already exists") % name); E(gov.back().delegation.is_branch_type(), origin::user, F("cannot edit '%s', it is delegated to a specific revision") % name); + + P(F("Parent policy is '%s'") % gov.back().full_policy_name); + policies::policy_branch parent_branch(project, gov.back().policy, gov.back().delegation.get_branch_spec()); @@ -110,19 +113,15 @@ CMD(create_subpolicy, "create_subpolicy" parent_branch.get_policy(parent, origin::user); 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)); - } + admin_keys.insert(key_id_to_external_name(keys.signing_key)); branch_name del_name(name); del_name.strip_prefix(gov.back().full_policy_name); parent.set_delegation(del_name(), policies::delegation::create(app, admin_keys)); - parent_branch.commit(project, keys, parent, - utf8("Add delegation to new child policy"), - origin::user); + revision_id revid = parent_branch.commit(project, keys, parent, + utf8("Add delegation to new child policy"), + origin::user); + P(F("Committed revision '%s' to parent policy.") % revid); } CMD(create_branch, "create_branch", "", CMD_REF(policy), @@ -149,24 +148,24 @@ CMD(create_branch, "create_branch", "", E(gov.back().delegation.is_branch_type(), origin::user, F("cannot edit '%s', it is delegated to a specific revision") % branch); + P(F("Parent policy is '%s'") % gov.back().full_policy_name); + policies::policy_branch parent(project, gov.back().policy, gov.back().delegation.get_branch_spec()); policies::editable_policy ppol; parent.get_policy(ppol, origin::user); std::set admin_keys; - { - string k = encode_hexenc(keys.signing_key.inner()(), origin::internal); - admin_keys.insert(external_key_name(k, origin::internal)); - } + admin_keys.insert(key_id_to_external_name(keys.signing_key)); branch_name suffix(branch); suffix.strip_prefix(gov.back().full_policy_name); if (suffix().empty()) suffix = branch_name("__main__", origin::internal); ppol.set_branch(suffix(), policies::branch::create(app, admin_keys)); - parent.commit(project, keys, ppol, - utf8("Add branch."), - origin::user); + revision_id revid = parent.commit(project, keys, ppol, + utf8("Add branch."), + origin::user); + P(F("Committed revision '%s' to parent policy.") % revid); } CMD_FWD_DECL(list); @@ -181,7 +180,7 @@ void list_policy(project_t const & proj, for (std::set::const_iterator i = subpolicies.begin(); i != subpolicies.end(); ++i) { - list_policy(proj, *i, recursive); + std::cout<<*i<<'\n'; } } } @@ -204,7 +203,7 @@ CMD(policies, "policies", "", CMD_REF(li for (std::set::const_iterator i = subpolicies.begin(); i != subpolicies.end(); ++i) { - list_policy(project, *i, app.opts.recursive); + std::cout<<*i<<'\n'; } } else ============================================================ --- policies/policy_branch.cc 148c64957fed2c05fc8ee69e2b31ec5552ae1399 +++ policies/policy_branch.cc 9f5cf990e17f3b68ea31d5bbf7829343098ae714 @@ -335,20 +335,23 @@ namespace policies { }; } - void policy_branch::commit(project_t & project, - key_store & keys, - policy const & p, - utf8 const & changelog, - origin::type ty) + revision_id policy_branch::commit(project_t & project, + key_store & keys, + policy const & p, + utf8 const & changelog, + origin::type ty) { - E(try_commit(project, keys, p, changelog), ty, + revision_id result; + E(try_commit(project, keys, p, changelog, result), ty, F("cannot automatically merge %d heads of policy branch") % _num_heads); + return result; } bool policy_branch::try_commit(project_t & project, key_store & keys, policy const & p, - utf8 const & changelog) + utf8 const & changelog, + revision_id & result) { std::set heads; get_heads(project, spec, spec_owner, heads); @@ -442,6 +445,7 @@ namespace policies { date_t::now(), author); guard.commit(); + result = revid; return true; } } ============================================================ --- policies/policy_branch.hh 2cf62bc1c862c968fa2b660796fcd79ddee1bab3 +++ policies/policy_branch.hh f333957457d5b6a866e7f7186651f0f194e4e60d @@ -51,12 +51,13 @@ namespace policies { // having multiple heads that can't be auto-merged bool try_commit(project_t & project, key_store & keys, policy const & pol, - utf8 const & message); + utf8 const & message, + revision_id & result); // wrapper that will E() for you - void commit(project_t & project, key_store & keys, - policy const & pol, - utf8 const & message, - origin::type ty); + revision_id commit(project_t & project, key_store & keys, + policy const & pol, + utf8 const & message, + origin::type ty); }; } ============================================================ --- project.cc bd4ba14ebb6347ab6b707b96624ea5fb0f915886 +++ project.cc 0d4f00a7c962d3dbbff1d23bf80e825b9eb19d02 @@ -552,6 +552,7 @@ project_t::get_subpolicies(branch_name c return; project_policy->list_policies(*this, name, names); + names.erase(name); } ============================================================ --- tests/policy-subpolicies/__driver__.lua 3bbc3c470bdc0575e0304aba59deebb94d10d720 +++ tests/policy-subpolicies/__driver__.lua 8b5e1949367181788b0b6b396736ceade92cb1cd @@ -12,19 +12,23 @@ check(exists("checkout/delegations/subsu check(exists("checkout/delegations/subsub")) +function require_parent_is(parent_policy) + check(qgrep("Parent policy is '"..parent_policy.."'", "stderr")) +end + policies = "test_project\n" policies = policies .. "test_project.subproject\n" policies = policies .. "test_project.subproject.subsub\n" check(mtn("ls", "policies", "-R"), 0, policies) check(mtn("create_branch", "test_project.firstbranch"), 0, false, true) -check(qgrep("Parent policy: test_project$", "stderr")) +require_parent_is("test_project") check(mtn("create_branch", "test_project.subproject.secondbranch"), 0, false, true) -check(qgrep("Parent policy: test_project.subproject$", "stderr")) +require_parent_is("test_project.subproject") check(mtn("create_branch", "test_project.subproject.subsub.thirdbranch"), 0, false, true) -check(qgrep("Parent policy: test_project.subproject.subsub$", "stderr")) +require_parent_is("test_project.subproject.subsub") check(mtn("ls", "branches"), 0, true)