# # # patch "branch_name.cc" # from [288529d51201f24a6dd1ea352defc66befb2b304] # to [c99f6e6b55de00a9bf720a4e872b1b2bc571f984] # # patch "editable_policy.cc" # from [fbbf12bf1b3bf07a6148fd9f5ef9a7981e4d776a] # to [d1fb22b9a7f5f1a637a4e15b99c21599524479aa] # # patch "editable_policy.hh" # from [4ec915784541263f8dc823826d7dd28af1cdcb20] # to [fd828eb31b270be2506394bebf8d64baa65f5a30] # # patch "policy.cc" # from [e20582e31520a24bea1dc882511772489859f0c9] # to [dee33538419609912f1d564b9c820b5e46e9cee3] # # patch "policy.hh" # from [18aaebbe4df42d9a4f3446f7a5ac0404947ea89c] # to [bd69fc16360de313c6c03c1df6e4da756b554dca] # # patch "project.cc" # from [765971106387dbf944b79a1e3c2698366cb82de3] # to [3d2308d7759d8d65cc4c1abc9fd34ba122413d9f] # # patch "project.hh" # from [11a4e111004808faec2e5c48f10b8e6598c68de4] # to [384cf940dfccba015069502e1eb4c133e8791e92] # ============================================================ --- branch_name.cc 288529d51201f24a6dd1ea352defc66befb2b304 +++ branch_name.cc c99f6e6b55de00a9bf720a4e872b1b2bc571f984 @@ -22,6 +22,8 @@ branch_name::has_prefix(branch_name cons bool branch_name::has_prefix(branch_name const & pre) const { + if (pre.data.empty()) + return true; if (data.size() == pre.data.size()) return data == pre.data; else if (data.size() > pre.data.size()) @@ -34,6 +36,8 @@ branch_name::strip_prefix(branch_name co bool branch_name::strip_prefix(branch_name const & pre) { + if (pre.data.empty()) + return true; if (!has_prefix(pre)) return false; @@ -47,13 +51,21 @@ branch_name::prepend(branch_name const & void branch_name::prepend(branch_name const & pre) { - data = pre.data + "." + data; + if (pre.data.empty()) + return; + if (data.empty()) + data = pre.data; + else + data = pre.data + "." + data; } void branch_name::append(branch_name const & post) { - data += "."; + if (post.data.empty()) + return; + if (!data.empty()) + data += "."; data += post.data; } ============================================================ --- editable_policy.cc fbbf12bf1b3bf07a6148fd9f5ef9a7981e4d776a +++ editable_policy.cc d1fb22b9a7f5f1a637a4e15b99c21599524479aa @@ -190,6 +190,7 @@ namespace { info.new_name = i->first(); info.new_value.reset(new typename T::value_type::item_type()); info.new_value->read(fdat.inner()); + cont.insert(info); } } void @@ -218,23 +219,18 @@ editable_policy::editable_policy(databas } editable_policy::editable_policy(database & db, - branch_policy const & policy_policy) - : impl(new editable_policy_impl(db)) -{ - branch br; - br.uid = policy_policy.branch_cert_value; - br.committers = policy_policy.committers; - init(br); -} - -editable_policy::editable_policy(database & db, editable_policy::delegation const & del) : impl(new editable_policy_impl(db)) { - branch br; - br.uid = del.uid; - br.committers = del.committers; - init(br); + if (null_id(del.rev)) + { + branch br; + br.uid = del.uid; + br.committers = del.committers; + init(br); + } + else + init(del.rev); } editable_policy::editable_policy() @@ -275,11 +271,22 @@ editable_policy::init(editable_policy::b uid = br.uid; set heads; get_branch_heads(br, false, impl->db, heads, NULL); - E(heads.size() == 1, - F("Policy branch %s does not have exactly 1 head") % uid); - impl->old_rev_id = *heads.begin(); - impl->db.get_roster(impl->old_rev_id, impl->old_roster); - load_policy(impl); + E(heads.size() <= 1, + F("Policy branch %s has too many heads") % uid); + if (heads.empty()) + { + W(F("Cannot find policy %s, loading an empty policy") % br.uid); + branch_holder::info_type self; + self.new_name = "__policy__"; + self.new_value.reset(new branch(br)); + impl->branches.insert(self); + } + else + { + impl->old_rev_id = *heads.begin(); + impl->db.get_roster(impl->old_rev_id, impl->old_roster); + load_policy(impl); + } } ============================================================ --- editable_policy.hh 4ec915784541263f8dc823826d7dd28af1cdcb20 +++ editable_policy.hh fd828eb31b270be2506394bebf8d64baa65f5a30 @@ -15,7 +15,6 @@ #include "vocab.hh" -class branch_policy; class database; class key_store; class lua_hooks; @@ -67,7 +66,6 @@ public: editable_policy(database & db, revision_id const & rev); // Edit an existing policy branch. This will fail if the branch // doesn't have exactly one head. - editable_policy(database & db, branch_policy const & policy_policy); editable_policy(database & db, delegation const & del); editable_policy(); editable_policy(editable_policy const & other); ============================================================ --- policy.cc e20582e31520a24bea1dc882511772489859f0c9 +++ policy.cc dee33538419609912f1d564b9c820b5e46e9cee3 @@ -52,6 +52,7 @@ policy_branch::policy_branch(shared_ptr< database & db) : db(db), policy(pol) { + init_lower(); } shared_ptr @@ -79,14 +80,18 @@ policy_branch::init() policy.reset(new editable_policy(db, *delayed)); delayed.reset(); + init_lower(); + return true; +} +void +policy_branch::init_lower() +{ editable_policy::const_delegation_map dels = policy->get_all_delegations(); for (editable_policy::const_delegation_map::const_iterator i = dels.begin(); i != dels.end(); ++i) { delegations.insert(make_pair(i->first, create(*i->second, db))); } - - return true; } shared_ptr @@ -227,21 +232,6 @@ outdated_indicator } outdated_indicator -get_branch_heads(branch_policy const & pol, - bool ignore_suspend_certs, - database & db, - std::set & heads, - multimap - * inverse_graph_cache_ptr) -{ - editable_policy::branch br; - br.uid = pol.branch_cert_value; - br.committers = pol.committers; - return get_branch_heads(br, ignore_suspend_certs, db, heads, - inverse_graph_cache_ptr); -} - -outdated_indicator get_branch_heads(editable_policy::branch const & br, bool ignore_suspend_certs, database & db, @@ -274,16 +264,6 @@ bool } bool -revision_is_in_branch(branch_policy const & pol, - revision_id const & rid, - database & db) -{ - not_in_managed_branch p(db, - cert_value(pol.branch_cert_value()), - pol.committers); - return !p(rid); -} -bool revision_is_in_branch(editable_policy::branch const & br, revision_id const & rid, database & db) ============================================================ --- policy.hh 18aaebbe4df42d9a4f3446f7a5ac0404947ea89c +++ policy.hh bd69fc16360de313c6c03c1df6e4da756b554dca @@ -15,58 +15,7 @@ #include "editable_policy.hh" #include "vocab.hh" - -class branch_policy -{ - branch_name _visible_name; - branch_uid _branch_cert_value; - std::set _committers; -public: - branch_name const & visible_name; - branch_uid const & branch_cert_value; - std::set const & committers; - - branch_policy() - : visible_name(_visible_name), - branch_cert_value(_branch_cert_value), - committers(_committers) - { } - branch_policy(branch_name const & name, - branch_uid const & value, - std::set const & keys) - : _visible_name(name), - _branch_cert_value(value), - _committers(keys), - visible_name(_visible_name), - branch_cert_value(_branch_cert_value), - committers(_committers) - { } - branch_policy(branch_policy const & rhs) - : _visible_name(rhs._visible_name), - _branch_cert_value(rhs._branch_cert_value), - _committers(rhs._committers), - visible_name(_visible_name), - branch_cert_value(_branch_cert_value), - committers(_committers) - { } - branch_policy const & - operator=(branch_policy const & rhs) - { - _visible_name = rhs._visible_name; - _branch_cert_value = rhs._branch_cert_value; - _committers = rhs._committers; - return *this; - } -}; - outdated_indicator -get_branch_heads(branch_policy const & pol, - bool ignore_suspend_certs, - database & db, - std::set & heads, - std::multimap - * inverse_graph_cache_ptr); -outdated_indicator get_branch_heads(editable_policy::branch const & br, bool ignore_suspend_certs, database & db, @@ -75,10 +24,6 @@ bool * inverse_graph_cache_ptr); bool -revision_is_in_branch(branch_policy const & pol, - revision_id const & rid, - database & db); -bool revision_is_in_branch(editable_policy::branch const & br, revision_id const & rid, database & db); @@ -93,6 +38,8 @@ class policy_branch : public boost::enab // Load from the db. bool init(); + // Process the loaded policy info. + void init_lower(); policy_branch(database & db); public: ============================================================ --- project.cc 765971106387dbf944b79a1e3c2698366cb82de3 +++ project.cc 3d2308d7759d8d65cc4c1abc9fd34ba122413d9f @@ -43,11 +43,17 @@ project_t::project_t(database & db, lua_ }; project_t::project_t(database & db, lua_hooks & lua, options & opts) - : db(db)//, project_policy(db, lua, opts) + : db(db) { shared_ptr ep(new editable_policy(db, set())); + // Empty editable_policy's start with (at least) a self-referencing + // __policy__ branch. We don't want that. + while (!ep->get_all_branches().empty()) + { + ep->remove_branch(ep->get_all_branches().begin()->first); + } - std::map delegations; + bool have_delegation(false); for (map >::const_iterator i = opts.policy_revisions.begin(); @@ -55,6 +61,7 @@ project_t::project_t(database & db, lua_ { data dat("revision_id ["+i->second()+"]\n"); ep->get_delegation(i->first(), true)->read(dat); + have_delegation = true; } std::map defs; @@ -62,12 +69,17 @@ project_t::project_t(database & db, lua_ for (map::const_iterator i = defs.begin(); i != defs.end(); ++i) { + // Don't overwrite something that was overridden + // from the command line (above). + if (ep->get_delegation(i->first)) + continue; ep->get_delegation(i->first, true)->read(i->second); + have_delegation = true; } - if (delegations.empty()) - project_policy.reset(new policy_info(db)); + if (have_delegation) + project_policy.reset(new policy_info(ep, db)); else - project_policy.reset(new policy_info(ep, db)); + project_policy.reset(new policy_info(db)); } bool ============================================================ --- project.hh 11a4e111004808faec2e5c48f10b8e6598c68de4 +++ project.hh 384cf940dfccba015069502e1eb4c133e8791e92 @@ -17,7 +17,6 @@ class lua_hooks; class key_store; class options; class lua_hooks; -class branch_policy; class tag_t {