# # # patch "cmd_merging.cc" # from [cfe1134fb6abc7d5ddd980d09df99a44f7080476] # to [011fc4334eddeea5b99ef179987f9a3f95df7751] # # patch "project.cc" # from [30eceeb9fc7019117418ebcf28505a103196c5bc] # to [5d3ae7981240fe8b8e5ce5807d6f8f213ca13d3f] # ============================================================ --- cmd_merging.cc cfe1134fb6abc7d5ddd980d09df99a44f7080476 +++ cmd_merging.cc 011fc4334eddeea5b99ef179987f9a3f95df7751 @@ -89,18 +89,8 @@ pick_branch_for_update(revision_id chose bool switched_branch = false; // figure out which branches the target is in - vector< revision > certs; - app.db.get_revision_certs(chosen_rid, branch_cert_name, certs); - erase_bogus_certs(certs, app.db); - set< branch_name > branches; - for (vector< revision >::const_iterator i = certs.begin(); - i != certs.end(); i++) - { - cert_value b; - decode_base64(i->inner().value, b); - branches.insert(branch_name(b())); - } + app.projects.get_revision_branches(chosen_rid, branches); if (branches.find(app.opts.branchname) != branches.end()) { ============================================================ --- project.cc 30eceeb9fc7019117418ebcf28505a103196c5bc +++ project.cc 5d3ae7981240fe8b8e5ce5807d6f8f213ca13d3f @@ -99,6 +99,17 @@ public: } shared_ptr get_policy(); map branches(); + + shared_ptr + maybe_get_branch_policy(branch_name const & name) + { + map bm = branches(); + map::const_iterator i = bm.find(name); + if (i != bm.end()) + return shared_ptr(new branch_policy(i->second)); + else + return shared_ptr(); + } }; class policy_revision @@ -211,7 +222,7 @@ namespace namespace { - struct not_in_policy_branch : public is_failure + struct not_in_managed_branch : public is_failure { database & db; base64 const & branch_encoded; @@ -230,9 +241,9 @@ namespace } return false; } - not_in_policy_branch(database & db, - base64 const & branch_encoded, - set const & trusted) + not_in_managed_branch(database & db, + base64 const & branch_encoded, + set const & trusted) : db(db), branch_encoded(branch_encoded), trusted_signers(trusted) {} virtual bool operator()(revision_id const & rid) @@ -243,13 +254,53 @@ namespace branch_encoded, certs); erase_bogus_certs(certs, - boost::bind(¬_in_policy_branch::is_trusted, + boost::bind(¬_in_managed_branch::is_trusted, this, _1, _2, _3, _4), db); return certs.empty(); } }; + struct suspended_in_managed_branch : public is_failure + { + database & db; + base64 const & branch_encoded; + set const & trusted_signers; + bool is_trusted(set const & signers, + hexenc const & rid, + cert_name const & name, + cert_value const & value) + { + for (set::const_iterator i = signers.begin(); + i != signers.end(); ++i) + { + set::const_iterator t = trusted_signers.find(*i); + if (t != trusted_signers.end()) + return true; + } + return false; + } + suspended_in_managed_branch(database & db, + base64 const & branch_encoded, + set const & trusted) + : db(db), branch_encoded(branch_encoded), trusted_signers(trusted) + {} + virtual bool operator()(revision_id const & rid) + { + vector< revision > certs; + db.get_revision_certs(rid, + cert_name(suspend_cert_name), + branch_encoded, + certs); + erase_bogus_certs(certs, + boost::bind(&suspended_in_managed_branch::is_trusted, + this, _1, _2, _3, _4), + db); + return !certs.empty(); + } + }; + + bool maybe_get_policy_branch_head(branch_uid const & name, set const & trusted_signers, database & db, @@ -264,7 +315,7 @@ namespace branch_encoded, heads); - not_in_policy_branch p(db, branch_encoded, trusted_signers); + not_in_managed_branch p(db, branch_encoded, trusted_signers); erase_ancestors_and_failures(heads, p, db, NULL); if (heads.size() != 1) @@ -520,7 +571,19 @@ project_t::get_branch_heads(branch_name if (branch.first.outdated()) { L(FL("getting heads of branch %s") % name); - branch_uid uid = translate_branch(name); + shared_ptr bp; + if (!project_policy->passthru) + { + bp = project_policy->policy.maybe_get_branch_policy(name); + E(bp, F("Cannot find policy for branch %s.") % name); + } + + branch_uid uid; + if (project_policy->passthru) + uid = branch_uid(name()); + else + uid = bp->branch_cert_value; + base64 branch_encoded; encode_base64(cert_value(uid()), branch_encoded); @@ -529,19 +592,41 @@ project_t::get_branch_heads(branch_name branch_encoded, branch.second); - not_in_branch p(db, branch_encoded); - erase_ancestors_and_failures(branch.second, p, db, - inverse_graph_cache_ptr); + if (project_policy->passthru) + { + not_in_branch p(db, branch_encoded); + erase_ancestors_and_failures(branch.second, p, db, + inverse_graph_cache_ptr); + } + else + { + not_in_managed_branch p(db, branch_encoded, bp->committers); + erase_ancestors_and_failures(branch.second, p, db, + inverse_graph_cache_ptr); + } if (!ignore_suspend_certs) { - suspended_in_branch s(db, branch_encoded); - std::set::iterator it = branch.second.begin(); - while (it != branch.second.end()) - if (s(*it)) - branch.second.erase(it++); - else - it++; + if (project_policy->passthru) + { + suspended_in_branch s(db, branch_encoded); + std::set::iterator it = branch.second.begin(); + while (it != branch.second.end()) + if (s(*it)) + branch.second.erase(it++); + else + it++; + } + else + { + suspended_in_managed_branch s(db, branch_encoded, bp->committers); + std::set::iterator it = branch.second.begin(); + while (it != branch.second.end()) + if (s(*it)) + branch.second.erase(it++); + else + it++; + } } L(FL("found heads of branch %s (%s heads)")