# # # rename "branch.cc" # to "project.cc" # # rename "branch.hh" # to "project.hh" # # patch "ChangeLog" # from [c150fac3a4989663e6f93f85c2807ff7f13aee64] # to [a570a499de20c936ad8eba878639e76f6478e313] # # patch "Makefile.am" # from [a1bb9b6a8e0323dab754103d76ff302fa08cb6e6] # to [4da41ad5f850629a5da1e19298b1543c197d55fb] # # patch "app_state.cc" # from [4c1ac983529b930a7ec449de19fd6cd04b3f8ea1] # to [008934c37947ce841574efb158c152114310f4ea] # # patch "app_state.hh" # from [f80f87e780b717e5a27e70d716364193f3e33d02] # to [05687e8b874e1fef4b1ae9a36f7f4951f33db5ca] # # patch "automate.cc" # from [e60ee7f88520b2a22f5ff1fb01af375b74381ca4] # to [13931985b523348adcc5d79939d96d03a433bcbc] # # patch "cert.cc" # from [7b6c1ee29936bcdcb470a76fa415a750c77bc51a] # to [1a96ec763ca93eb1030f15933253400605452b93] # # patch "cert.hh" # from [9802985dc9185a37739575d5a4c84d41f4acd286] # to [b2f4de53a290497a08a5185d382aa980ea291f09] # # patch "cmd_list.cc" # from [2251384099a9d52d757829f388a0dde3013f0f94] # to [b69a404855438771549c21fe10eba21d84141501] # # patch "cmd_merging.cc" # from [da91fb262ffa57750a82b15e68ad885a1e22b8f3] # to [3ef9847e6ff8415c6b5ad2a2f9c57310f8ae54d4] # # patch "cmd_ws_commit.cc" # from [306acc01a0bd314725219d4e352c74cfb21e6538] # to [cc19f101c180eca53c931d850ec31da23f6a5ad2] # # patch "commands.cc" # from [67676365ab02c505dbf5467645943b2a84f1d8b2] # to [36bada37724baaddac588fc57fa399b73a96d331] # # patch "database.cc" # from [4b2f6a180ecf2de37eca6e6d5388625665fc9c5e] # to [764005eb7a22748052b1b2d2165963182dec9fa2] # # patch "database.hh" # from [a3a95224391592f5f83b4da6864c8d330e563bc5] # to [1d756ecc4f072ea6a163643d9ba1787a75675507] # # patch "netsync.cc" # from [c309066e1f171b13eda8869c2955d1e1b427cf8a] # to [5c0cf0c90abf7f629193c65896ffae48182f9c24] # # patch "project.cc" # from [8fcf3617d3c24fc6f53b515c203cd0693baea311] # to [604d146bc88be450386d755a1783533834d98361] # # patch "project.hh" # from [4f64260d0b85965f7bac3854db20b609c075b35b] # to [0146006f7d817638f02fdf281f093e64dc5ff5aa] # ============================================================ --- ChangeLog c150fac3a4989663e6f93f85c2807ff7f13aee64 +++ ChangeLog a570a499de20c936ad8eba878639e76f6478e313 @@ -1,3 +1,10 @@ +2007-01-10 Timothy Brownawell + + Rename branch.* to project.* . + Have places that used get_branches() now go through this code. + The general idea here is to prepare for having actual projects, + with policy branches and whatnot. + 2007-01-09 Timothy Brownawell * outdated_indicator.{cc,hh}: Allows code that caches replys to ============================================================ --- Makefile.am a1bb9b6a8e0323dab754103d76ff302fa08cb6e6 +++ Makefile.am 4da41ad5f850629a5da1e19298b1543c197d55fb @@ -33,8 +33,8 @@ MOST_SOURCES = \ update.cc update.hh \ work.cc work_migration.cc work.hh \ cert.cc cert.hh \ - branch.cc branch.hh \ - outdated_indicator.cc outdated_indicator.hh \ + project.cc project.hh \ + outdated_indicator.cc outdated_indicator.hh \ database.cc database.hh \ key_store.cc key_store.hh \ localized_file_io.cc localized_file_io.hh \ ============================================================ --- app_state.cc 4c1ac983529b930a7ec449de19fd6cd04b3f8ea1 +++ app_state.cc 008934c37947ce841574efb158c152114310f4ea @@ -41,7 +41,7 @@ app_state::app_state() // search_root(current_root_path()), // diff_format(unified_diff), branch_is_sticky(false), - branches(*this) + project(*this) { db.set_app(this); lua.set_app(this); ============================================================ --- app_state.hh f80f87e780b717e5a27e70d716364193f3e33d02 +++ app_state.hh 05687e8b874e1fef4b1ae9a36f7f4951f33db5ca @@ -19,12 +19,12 @@ class lua_hooks; #include #include -#include "branch.hh" #include "database.hh" #include "key_store.hh" #include "lua_hooks.hh" #include "options.hh" #include "paths.hh" +#include "project.hh" #include "vocab.hh" #include "work.hh" @@ -82,7 +82,7 @@ public: void make_branch_sticky(); - branch_list branches; + project_t project; void set_database(system_path const & filename); void set_key_dir(system_path const & filename); ============================================================ --- automate.cc e60ee7f88520b2a22f5ff1fb01af375b74381ca4 +++ automate.cc 13931985b523348adcc5d79939d96d03a433bcbc @@ -71,7 +71,7 @@ AUTOMATE(heads, N_("[BRANCH]"), options: app.opts.branch_name = idx(args, 0); } set heads; - app.branches.get(app.opts.branch_name()).heads(heads); + app.project.get_branch(app.opts.branch_name()).heads(heads); for (set::const_iterator i = heads.begin(); i != heads.end(); ++i) output << (*i).inner()() << "\n"; } @@ -1255,15 +1255,16 @@ AUTOMATE(branches, "", options::opts::no N(args.size() == 0, F("no arguments needed")); - vector names; + set names; - app.db.get_branches(names); - sort(names.begin(), names.end()); + app.project.get_branch_list(names); - for (vector::const_iterator i = names.begin(); + for (set::const_iterator i = names.begin(); i != names.end(); ++i) - if (!app.lua.hook_ignore_branch(*i)) - output << (*i) << "\n"; + { + if (!app.lua.hook_ignore_branch((*i)())) + output << (*i) << "\n"; + } } // Name: tags ============================================================ --- cert.cc 7b6c1ee29936bcdcb470a76fa415a750c77bc51a +++ cert.cc 1a96ec763ca93eb1030f15933253400605452b93 @@ -542,50 +542,7 @@ cert_revision_in_branch(revision_id cons branchname, app, pc); } -namespace -{ - struct not_in_branch : public is_failure - { - app_state & app; - base64 const & branch_encoded; - not_in_branch(app_state & app, - base64 const & branch_encoded) - : app(app), branch_encoded(branch_encoded) - {} - virtual bool operator()(revision_id const & rid) - { - vector< revision > certs; - app.db.get_revision_certs(rid, - cert_name(branch_cert_name), - branch_encoded, - certs); - erase_bogus_certs(certs, app); - return certs.empty(); - } - }; -} -outdated_indicator -get_branch_heads(cert_value const & branchname, - app_state & app, - set & heads) -{ - L(FL("getting heads of branch %s") % branchname); - base64 branch_encoded; - encode_base64(branchname, branch_encoded); - - outdated_indicator stamp; - stamp = app.db.get_revisions_with_cert(cert_name(branch_cert_name), - branch_encoded, - heads); - - not_in_branch p(app, branch_encoded); - erase_ancestors_and_failures(heads, p, app); - L(FL("found heads of branch %s (%s heads)") % branchname % heads.size()); - return stamp; -} - - // "standard certs" string const date_cert_name = "date"; ============================================================ --- cert.hh 9802985dc9185a37739575d5a4c84d41f4acd286 +++ cert.hh b2f4de53a290497a08a5185d382aa980ea291f09 @@ -17,7 +17,6 @@ #include #include -#include "outdated_indicator.hh" #include "vocab.hh" // Certs associate an opaque name/value pair with a revision ID, and @@ -90,10 +89,6 @@ cert_revision_in_branch(revision_id cons app_state & app, packet_consumer & pc); -outdated_indicator -get_branch_heads(cert_value const & branchname, - app_state & app, - std::set & heads); // We also define some common cert types, to help establish useful // conventions. you should use these unless you have a compelling ============================================================ --- cmd_list.cc 2251384099a9d52d757829f388a0dde3013f0f94 +++ cmd_list.cc b69a404855438771549c21fe10eba21d84141501 @@ -240,14 +240,17 @@ ls_branches(string name, app_state & app throw usage(name); combine_and_check_globish(app.opts.exclude_patterns, exc); globish_matcher match(inc, exc); - vector names; - app.db.get_branches(names); + set names; + app.project.get_branch_list(names); - sort(names.begin(), names.end()); - for (size_t i = 0; i < names.size(); ++i) - if (match(idx(names, i)) - && !app.lua.hook_ignore_branch(idx(names, i))) - cout << idx(names, i) << "\n"; + for (set::const_iterator i = names.begin(); + i != names.end(); ++i) + { + if (match((*i)()) && !app.lua.hook_ignore_branch((*i)())) + { + cout << *i << "\n"; + } + } } static void ============================================================ --- cmd_merging.cc da91fb262ffa57750a82b15e68ad885a1e22b8f3 +++ cmd_merging.cc 3ef9847e6ff8415c6b5ad2a2f9c57310f8ae54d4 @@ -330,7 +330,7 @@ CMD(merge, N_("tree"), "", N_("merge unm F("please specify a branch, with --branch=BRANCH")); set heads; - app.branches.get(app.opts.branch_name()).heads(heads); + app.project.get_branch(app.opts.branch_name()).heads(heads); N(heads.size() != 0, F("branch '%s' is empty") % app.opts.branch_name); if (heads.size() == 1) @@ -398,7 +398,7 @@ CMD(merge, N_("tree"), "", N_("merge unm ancestors.clear(); heads_for_ancestor.clear(); - app.branches.get(app.opts.branch_name()).heads(heads); + app.project.get_branch(app.opts.branch_name()).heads(heads); pass++; } @@ -463,8 +463,8 @@ CMD(merge_into_dir, N_("tree"), N_("SOUR if (args.size() != 3) throw usage(name); - app.branches.get(idx(args, 0)()).heads(src_heads); - app.branches.get(idx(args, 1)()).heads(dst_heads); + app.project.get_branch(idx(args, 0)()).heads(src_heads); + app.project.get_branch(idx(args, 1)()).heads(dst_heads); N(src_heads.size() != 0, F("branch '%s' is empty") % idx(args, 0)()); N(src_heads.size() == 1, F("branch '%s' is not merged") % idx(args, 0)()); @@ -828,7 +828,7 @@ CMD(heads, N_("tree"), "", N_("show unme N(app.opts.branch_name() != "", F("please specify a branch, with --branch=BRANCH")); - app.branches.get(app.opts.branch_name()).heads(heads); + app.project.get_branch(app.opts.branch_name()).heads(heads); if (heads.size() == 0) P(F("branch '%s' is empty") % app.opts.branch_name); ============================================================ --- cmd_ws_commit.cc 306acc01a0bd314725219d4e352c74cfb21e6538 +++ cmd_ws_commit.cc cc19f101c180eca53c931d850ec31da23f6a5ad2 @@ -502,7 +502,7 @@ CMD(checkout, N_("tree"), N_("[DIRECTORY F("use --revision or --branch to specify what to checkout")); set heads; - app.branches.get(app.opts.branch_name).heads(heads); + app.project.get_branch(app.opts.branch_name).heads(heads); N(heads.size() > 0, F("branch '%s' is empty") % app.opts.branch_name); if (heads.size() > 1) @@ -758,7 +758,7 @@ CMD(commit, N_("workspace"), N_("[PATH]. I(restricted_rev.edges.size() == 1); set heads; - app.branches.get(app.opts.branch_name).heads(heads); + app.project.get_branch(app.opts.branch_name).heads(heads); unsigned int old_head_size = heads.size(); if (app.opts.branch_name() != "") @@ -931,7 +931,7 @@ CMD(commit, N_("workspace"), N_("[PATH]. app.work.blank_user_log(); - app.branches.get(app.opts.branch_name).heads(heads); + app.project.get_branch(app.opts.branch_name).heads(heads); if (heads.size() > old_head_size && old_head_size > 0) { P(F("note: this revision creates divergence\n" "note: you may (or may not) wish to run '%s merge'") @@ -1036,7 +1036,7 @@ CMD_NO_WORKSPACE(import, N_("tree"), N_( F("use --revision or --branch to specify what to checkout")); set heads; - app.branches.get(app.opts.branch_name).heads(heads); + app.project.get_branch(app.opts.branch_name).heads(heads); if (heads.size() > 1) { P(F("branch %s has multiple heads:") % app.opts.branch_name); ============================================================ --- commands.cc 67676365ab02c505dbf5467645943b2a84f1d8b2 +++ commands.cc 36bada37724baaddac588fc57fa399b73a96d331 @@ -462,7 +462,7 @@ notify_if_multiple_heads(app_state & app notify_if_multiple_heads(app_state & app) { set heads; - get_branch_heads(app.opts.branch_name(), app, heads); + app.project.get_branch(app.opts.branch_name).heads(heads); if (heads.size() > 1) { string prefixedline; prefix_lines_with(_("note: "), ============================================================ --- database.cc 4b2f6a180ecf2de37eca6e6d5388625665fc9c5e +++ database.cc 764005eb7a22748052b1b2d2165963182dec9fa2 @@ -2592,31 +2592,24 @@ void database::complete(selector_type ty else if (i->first == selectors::sel_head) { // get branch names - vector branch_names; + set branch_names; if (i->second.size() == 0) { __app->require_workspace("the empty head selector h: refers to the head of the current branch"); - branch_names.push_back((__app->opts.branch_name)()); + branch_names.insert(__app->opts.branch_name); } else { - query subquery("SELECT DISTINCT value FROM revision_certs WHERE name=? AND CAST(value AS TEXT) glob ?"); - subquery % text(branch_cert_name) % text(i->second); - results res; - fetch(res, one_col, any_rows, subquery); - for (size_t i = 0; i < res.size(); ++i) - { - data row_decoded(res[i][0]); - branch_names.push_back(row_decoded()); - } + __app->project.get_branch_list(i->second, branch_names); } // for each branch name, get the branch heads set heads; - for (vector::const_iterator bn = branch_names.begin(); bn != branch_names.end(); bn++) + for (set::const_iterator bn = branch_names.begin(); + bn != branch_names.end(); bn++) { set branch_heads; - get_branch_heads(*bn, *__app, branch_heads); + __app->project.get_branch(*bn).heads(branch_heads); heads.insert(branch_heads.begin(), branch_heads.end()); L(FL("after get_branch_heads for %s, heads has %d entries") % (*bn) % heads.size()); } @@ -2865,6 +2858,21 @@ database::get_branches(vector & return cert_stamper.get_indicator(); } +outdated_indicator +database::get_branches(string const & glob, + vector & names) +{ + results res; + query q("SELECT DISTINCT value FROM revision_certs WHERE name = ? AND CAST(value AS TEXT) glob ?"); + string cert_name = "branch"; + fetch(res, one_col, any_rows, q % text(cert_name) % text(glob)); + for (size_t i = 0; i < res.size(); ++i) + { + names.push_back(res[i][0]); + } + return cert_stamper.get_indicator(); +} + void database::get_roster(revision_id const & rev_id, roster_t & roster) ============================================================ --- database.hh a3a95224391592f5f83b4da6864c8d330e563bc5 +++ database.hh 1d756ecc4f072ea6a163643d9ba1787a75675507 @@ -531,6 +531,8 @@ public: public: // branches outdated_indicator get_branches(std::vector & names); + outdated_indicator get_branches(std::string const & glob, + std::vector & names); bool check_integrity(); ============================================================ --- netsync.cc c309066e1f171b13eda8869c2955d1e1b427cf8a +++ netsync.cc 5c0cf0c90abf7f629193c65896ffae48182f9c24 @@ -1268,13 +1268,6 @@ session::process_error_cmd(string const throw bad_decode(F("received network error: %s") % errmsg); } -void -get_branches(app_state & app, vector & names) -{ - app.db.get_branches(names); - sort(names.begin(), names.end()); -} - static const var_domain known_servers_domain = var_domain("known-servers"); bool @@ -1343,7 +1336,7 @@ session::process_hello_cmd(rsa_keypair_i // clients always include in the synchronization set, every branch that the // user requested set all_branches, ok_branches; - app.branches.list_all(all_branches); + app.project.get_branch_list(all_branches); for (set::const_iterator i = all_branches.begin(); i != all_branches.end(); i++) { @@ -1436,7 +1429,7 @@ session::process_anonymous_cmd(protocol_ } set all_branches, ok_branches; - app.branches.list_all(all_branches); + app.project.get_branch_list(all_branches); globish_matcher their_matcher(their_include_pattern, their_exclude_pattern); for (set::const_iterator i = all_branches.begin(); i != all_branches.end(); i++) @@ -1569,7 +1562,7 @@ session::process_auth_cmd(protocol_role } set all_branches, ok_branches; - app.branches.list_all(all_branches); + app.project.get_branch_list(all_branches); for (set::const_iterator i = all_branches.begin(); i != all_branches.end(); i++) { ============================================================ --- branch.cc 8fcf3617d3c24fc6f53b515c203cd0693baea311 +++ project.cc 604d146bc88be450386d755a1783533834d98361 @@ -1,14 +1,64 @@ // 2007 Timothy Brownawell // GNU GPL V2 or later +#include + #include "app_state.hh" -#include "branch.hh" #include "cert.hh" +#include "project.hh" +#include "revision.hh" +#include "transforms.hh" +using std::set; +using std::vector; + branch::branch(app_state & app, utf8 const & name) : app(app), name(name) {} +namespace +{ + struct not_in_branch : public is_failure + { + app_state & app; + base64 const & branch_encoded; + not_in_branch(app_state & app, + base64 const & branch_encoded) + : app(app), branch_encoded(branch_encoded) + {} + virtual bool operator()(revision_id const & rid) + { + vector< revision > certs; + app.db.get_revision_certs(rid, + cert_name(branch_cert_name), + branch_encoded, + certs); + erase_bogus_certs(certs, app); + return certs.empty(); + } + }; +} + +outdated_indicator +get_branch_heads(cert_value const & branchname, + app_state & app, + set & heads) +{ + L(FL("getting heads of branch %s") % branchname); + base64 branch_encoded; + encode_base64(branchname, branch_encoded); + + outdated_indicator stamp; + stamp = app.db.get_revisions_with_cert(cert_name(branch_cert_name), + branch_encoded, + heads); + + not_in_branch p(app, branch_encoded); + erase_ancestors_and_failures(heads, p, app); + L(FL("found heads of branch %s (%s heads)") % branchname % heads.size()); + return stamp; +} + void branch::heads(std::set & h) { @@ -20,32 +70,46 @@ branch::heads(std::set & h) } -branch_list::branch_list(app_state & app) +project_t::project_t(app_state & app) : app(app) {} void -branch_list::list_all(std::set & names) +project_t::get_branch_list(std::set & names) { if (indicator.outdated()) { std::vector got; indicator = app.db.get_branches(got); - actual.clear(); + actual_branches.clear(); for (std::vector::iterator i = got.begin(); i != got.end(); ++i) { - actual.insert(*i); + actual_branches.insert(*i); } } - names = actual; + names = actual_branches; } +void +project_t::get_branch_list(utf8 const & glob, + std::set & names) +{ + std::vector got; + app.db.get_branches(glob(), got); + names.clear(); + for (std::vector::iterator i = got.begin(); + i != got.end(); ++i) + { + names.insert(*i); + } +} + branch & -branch_list::get(utf8 const & name) +project_t::get_branch(utf8 const & name) { std::pair::iterator, bool> res; - res = known.insert(std::make_pair(name, branch(app, name))); + res = known_branches.insert(std::make_pair(name, branch(app, name))); return res.first->second; } ============================================================ --- branch.hh 4f64260d0b85965f7bac3854db20b609c075b35b +++ project.hh 0146006f7d817638f02fdf281f093e64dc5ff5aa @@ -7,6 +7,7 @@ #include #include +#include "cert.hh" #include "outdated_indicator.hh" #include "vocab.hh" @@ -24,18 +25,19 @@ public: void heads(std::set & h); }; -class branch_list +class project_t { app_state & app; - std::map known; - std::set actual; + std::map known_branches; + std::set actual_branches; outdated_indicator indicator; public: - branch_list(app_state & app); + project_t(app_state & app); - void list_all(std::set & names); - branch & get(utf8 const & name); + void get_branch_list(std::set & names); + void get_branch_list(utf8 const & glob, std::set & names); + branch & get_branch(utf8 const & name); }; #endif