# # # patch "app_state.cc" # from [69a320265889e76fe5dcf52fe4bf44e3b6008795] # to [d524c53fd059fe136e61516c92268a87a0562fb0] # # patch "cmd_db.cc" # from [6e0eed17a107e27235d68204bc4dde35b3f78c5e] # to [27578e1b76f4949f9c6b6d34f90a548497079c9b] # # patch "cmd_list.cc" # from [d673c46c744088510cfd0fc8b8b972f94708d52d] # to [e26505586c5755b0e2b98cadb237487b230ebe60] # # patch "database.cc" # from [a43b661056bacfe298863382b8dc145285aea772] # to [b4e2c094ff42cb1cc2df1c58f5c0261ad10fee02] # # patch "database.hh" # from [e0a41892c27ca9c23da4ddb55462e102d314e2fd] # to [6f6a1582af2c27cc6d02f2b88a0a646f6691d71a] # # patch "epoch.cc" # from [c9f85974e9799b788d75863843977c8fc405d38d] # to [682f3de8cabc192d17ec24c2609b832da1df2317] # # patch "epoch.hh" # from [9d4366878bee862bbdf1f04b107e780e1225a340] # to [534b6a45ecfc2b9b9246ae0f726922e2de28cad3] # # patch "netsync.cc" # from [4d388b36d00bcfa1aba5ffcb1f767f6737488673] # to [c6f2fdec70930eae322dcbf5c560135db07342bd] # # patch "project.cc" # from [088016ccc2c17ed40e53c0ab4ce27b8576fb20ad] # to [3a88d948dad77b6339c41972a0215ee7df52758e] # # patch "project.hh" # from [219133cc611351b778348c9ea310606f7bb6d55f] # to [2816798abe99c9d158db9c81a72168f0690597ab] # # patch "rcs_import.cc" # from [352e42220856fef882d4125ca9df95c1896ceffb] # to [598256b753605b6452cfb1367aa8b2952ac9357e] # # patch "revision.cc" # from [725c74dec3553f8e4a5f5d341b7101518fb83aba] # to [7614a884a28582cbaf5d9cd98b3438c4ab0858fc] # # patch "vocab_terms.hh" # from [80283d95bc08f3a9f8c1c503ebeebb51b03c384e] # to [72f09f044b17a05a71bd9b738d99fd32ed279d3a] # ============================================================ --- app_state.cc 69a320265889e76fe5dcf52fe4bf44e3b6008795 +++ app_state.cc d524c53fd059fe136e61516c92268a87a0562fb0 @@ -224,7 +224,7 @@ app_state::get_project() i != project_definitions.end(); ++i) { projects.insert(make_pair(i->first, - project_t(i->first, + project_t(branch_prefix(i->first), i->second, db))); } ============================================================ --- cmd_db.cc 6e0eed17a107e27235d68204bc4dde35b3f78c5e +++ cmd_db.cc 27578e1b76f4949f9c6b6d34f90a548497079c9b @@ -272,7 +272,9 @@ CMD_HIDDEN(clear_epoch, "clear_epoch", " if (args.size() != 1) throw usage(execid); - app.db.clear_epoch(branch_name(idx(args, 0)())); + branch_name name(idx(args, 0)()); + branch_uid branch = app.get_project().translate_branch(name); + app.db.clear_epoch(branch); } CMD(db_set_epoch, "set_epoch", "", CMD_REF(db), "BRANCH EPOCH", @@ -286,7 +288,9 @@ CMD(db_set_epoch, "set_epoch", "", CMD_R epoch_data ed(idx(args, 1)()); N(ed.inner()().size() == constants::epochlen, F("The epoch must be %s characters") % constants::epochlen); - app.db.set_epoch(branch_name(idx(args, 0)()), ed); + branch_name name(idx(args, 0)()); + branch_uid branch = app.get_project().translate_branch(name); + app.db.set_epoch(branch, ed); } CMD(set, "set", "", CMD_REF(variables), N_("DOMAIN NAME VALUE"), ============================================================ --- cmd_list.cc d673c46c744088510cfd0fc8b8b972f94708d52d +++ cmd_list.cc e26505586c5755b0e2b98cadb237487b230ebe60 @@ -294,25 +294,41 @@ CMD(epochs, "epochs", "", CMD_REF(list), "", options::opts::depth | options::opts::exclude) { - map epochs; + map epochs; app.db.get_epochs(epochs); if (args.size() == 0) { - for (map::const_iterator + std::set branches; + app.get_project().get_branch_list(branches); + for (map::const_iterator i = epochs.begin(); i != epochs.end(); ++i) { - cout << i->second << ' ' << i->first << '\n'; + if (branches.find(i->first) == branches.end()) + { + cout << i->second << ' ' << i->first << '\n'; + } + else + { + branch_name branch = app.get_project().translate_branch(i->first); + cout << i->second << ' ' << branch << '\n'; + } } } else { + std::set branches; + app.get_project().get_branch_list(branches, false); for (args_vector::const_iterator i = args.begin(); i != args.end(); ++i) { - map::const_iterator j = epochs.find(branch_name((*i)())); + branch_name branch((*i)()); + N(branches.find(branch) != branches.end(), + F("Unknown branch %s") % branch); + branch_uid b = app.get_project().translate_branch(branch); + map::const_iterator j = epochs.find(b); N(j != epochs.end(), F("no epoch for branch %s") % *i); cout << j->second << ' ' << j->first << '\n'; } ============================================================ --- database.cc a43b661056bacfe298863382b8dc145285aea772 +++ database.cc b4e2c094ff42cb1cc2df1c58f5c0261ad10fee02 @@ -3281,14 +3281,14 @@ void // epochs void -database::get_epochs(map & epochs) +database::get_epochs(map & epochs) { epochs.clear(); results res; imp->fetch(res, 2, any_rows, query("SELECT branch, epoch FROM branch_epochs")); for (results::const_iterator i = res.begin(); i != res.end(); ++i) { - branch_name decoded(idx(*i, 0)); + branch_uid decoded(idx(*i, 0)); I(epochs.find(decoded) == epochs.end()); epochs.insert(make_pair(decoded, epoch_data(idx(*i, 1)))); } @@ -3296,7 +3296,7 @@ database::get_epoch(epoch_id const & eid void database::get_epoch(epoch_id const & eid, - branch_name & branch, epoch_data & epo) + branch_uid & branch, epoch_data & epo) { I(epoch_exists(eid)); results res; @@ -3305,7 +3305,7 @@ database::get_epoch(epoch_id const & eid " WHERE hash = ?") % text(eid.inner()())); I(res.size() == 1); - branch = branch_name(idx(idx(res, 0), 0)); + branch = branch_uid(idx(idx(res, 0), 0)); epo = epoch_data(idx(idx(res, 0), 1)); } @@ -3321,7 +3321,7 @@ void } void -database::set_epoch(branch_name const & branch, epoch_data const & epo) +database::set_epoch(branch_uid const & branch, epoch_data const & epo) { epoch_id eid; epoch_hash_code(branch, epo, eid); @@ -3333,7 +3333,7 @@ void } void -database::clear_epoch(branch_name const & branch) +database::clear_epoch(branch_uid const & branch) { imp->execute(query("DELETE FROM branch_epochs WHERE branch = ?") % blob(branch())); ============================================================ --- database.hh e0a41892c27ca9c23da4ddb55462e102d314e2fd +++ database.hh 6f6a1582af2c27cc6d02f2b88a0a646f6691d71a @@ -320,15 +320,15 @@ public: // --== Epochs ==-- // public: - void get_epochs(std::map & epochs); + void get_epochs(std::map & epochs); - void get_epoch(epoch_id const & eid, branch_name & branch, epoch_data & epo); + void get_epoch(epoch_id const & eid, branch_uid & branch, epoch_data & epo); bool epoch_exists(epoch_id const & eid); - void set_epoch(branch_name const & branch, epoch_data const & epo); + void set_epoch(branch_uid const & branch, epoch_data const & epo); - void clear_epoch(branch_name const & branch); + void clear_epoch(branch_uid const & branch); // // --== Database 'vars' ==-- ============================================================ --- epoch.cc c9f85974e9799b788d75863843977c8fc405d38d +++ epoch.cc 682f3de8cabc192d17ec24c2609b832da1df2317 @@ -18,7 +18,7 @@ read_epoch(string const & in, void read_epoch(string const & in, - branch_name & branch, epoch_data & epoch) + branch_uid & branch, epoch_data & epoch) { size_t pos = 0; string raw_branch; @@ -26,14 +26,14 @@ read_epoch(string const & in, extract_variable_length_string(in, raw_branch, pos, "epoch, branch name"); raw_epoch = data(extract_substring(in, pos, constants::epochlen_bytes, "epoch, epoch data")); - branch = branch_name(raw_branch); + branch = branch_uid(raw_branch); hexenc tmp; encode_hexenc(raw_epoch, tmp); epoch = epoch_data(tmp); } void -write_epoch(branch_name const & branch, epoch_data const & epoch, +write_epoch(branch_uid const & branch, epoch_data const & epoch, string & out) { insert_variable_length_string(branch(), out); @@ -43,7 +43,7 @@ void } void -epoch_hash_code(branch_name const & branch, epoch_data const & epoch, +epoch_hash_code(branch_uid const & branch, epoch_data const & epoch, epoch_id & eid) { string tmp(branch() + ":" + epoch.inner()()); ============================================================ --- epoch.hh 9d4366878bee862bbdf1f04b107e780e1225a340 +++ epoch.hh 534b6a45ecfc2b9b9246ae0f726922e2de28cad3 @@ -16,10 +16,10 @@ void read_epoch(std::string const & in, // epochs are pairs (branch name, random data) void read_epoch(std::string const & in, - branch_name & branch, epoch_data & epoch); -void write_epoch(branch_name const & branch, epoch_data const & epoch, + branch_uid & branch, epoch_data & epoch); +void write_epoch(branch_uid const & branch, epoch_data const & epoch, std::string & out); -void epoch_hash_code(branch_name const & branch, epoch_data const & epoch, +void epoch_hash_code(branch_uid const & branch, epoch_data const & epoch, epoch_id & eid); // Local Variables: ============================================================ --- netsync.cc 4d388b36d00bcfa1aba5ffcb1f767f6737488673 +++ netsync.cc c6f2fdec70930eae322dcbf5c560135db07342bd @@ -1863,7 +1863,7 @@ session::load_data(netcmd_item_type type { case epoch_item: { - branch_name branch; + branch_uid branch; epoch_data epoch; db.get_epoch(epoch_id(hitem), branch, epoch); write_epoch(branch, epoch, out); @@ -1932,13 +1932,13 @@ session::process_data_cmd(netcmd_item_ty { case epoch_item: { - branch_name branch; + branch_uid branch; epoch_data epoch; read_epoch(dat, branch, epoch); L(FL("received epoch %s for branch %s") % epoch % branch); - map epochs; + map epochs; db.get_epochs(epochs); - map::const_iterator i; + map::const_iterator i; i = epochs.find(branch); if (i == epochs.end()) { @@ -3196,15 +3196,15 @@ session::rebuild_merkle_trees(set epochs; + map epochs; db.get_epochs(epochs); epoch_data epoch_zero(string(constants::epochlen, '0')); for (set::const_iterator i = branchnames.begin(); i != branchnames.end(); ++i) { - branch_name const & branch(*i); - map::const_iterator j; + branch_uid branch = project.translate_branch(*i); + map::const_iterator j; j = epochs.find(branch); // Set to zero any epoch which is not yet set. ============================================================ --- project.cc 088016ccc2c17ed40e53c0ab4ce27b8576fb20ad +++ project.cc 3a88d948dad77b6339c41972a0215ee7df52758e @@ -27,7 +27,7 @@ namespace basic_io { namespace syms { - symbol const branch_id("branch_id"); + symbol const branch_uid("branch_uid"); symbol const committer("committer"); symbol const policy("policy_branch_id"); symbol const administrator("administrator"); @@ -37,11 +37,11 @@ struct branch_policy struct branch_policy { branch_name const visible_name; - branch_name const branch_cert_value; + branch_uid const branch_cert_value; set const committers; branch_policy(branch_name const & name, - branch_name const & value, + branch_uid const & value, set const & keys) : visible_name(name), branch_cert_value(value), @@ -53,8 +53,8 @@ class policy_branch class policy_branch { - branch_name prefix; - branch_name my_branch_cert_value; + branch_prefix prefix; + branch_uid my_branch_cert_value; set my_committers; database & db; @@ -72,7 +72,7 @@ class policy_branch pa.sym(); string branch; pa.str(branch); - my_branch_cert_value = branch_name(branch); + my_branch_cert_value = branch_uid(branch); } else if (pa.symp(basic_io::syms::administrator)) { @@ -91,14 +91,14 @@ public: } public: policy_branch(data const & spec, - branch_name const & prefix, + branch_prefix const & prefix, database & db) : prefix(prefix), db(db) { init(spec); } policy_branch(system_path const & spec_file, - branch_name const & prefix, + branch_prefix const & prefix, database & db) : prefix(prefix), db(db) { @@ -116,11 +116,11 @@ class policy_revision class policy_revision { map branches; - map delegations; + map delegations; public: policy_revision(database & db, revision_id const & rev, - branch_name const & prefix) + branch_prefix const & prefix) { roster_t roster; db.get_roster(rev, roster); @@ -141,13 +141,13 @@ public: } else { - branch = prefix; + branch = branch_name(prefix()); } file_id ident = downcast_to_file_t(i->second)->content; file_data spec; db.get_file_version(ident, spec); - branch_name branch_cert_value; + branch_uid branch_cert_value; set committers; basic_io::input_source src(spec.inner()(), "branch spec"); @@ -156,12 +156,12 @@ public: while (pa.symp()) { - if (pa.symp(basic_io::syms::branch_id)) + if (pa.symp(basic_io::syms::branch_uid)) { pa.sym(); string branch; pa.str(branch); - branch_cert_value = branch_name(branch); + branch_cert_value = branch_uid(branch); } else if (pa.symp(basic_io::syms::committer)) { @@ -190,7 +190,7 @@ public: for (dir_map::const_iterator i = delegation_node->children.begin(); i != delegation_node->children.end(); ++i) { - branch_name subprefix(prefix() + "." + i->first()); + branch_prefix subprefix(prefix() + "." + i->first()); file_id ident = downcast_to_file_t(i->second)->content; file_data spec; db.get_file_version(ident, spec); @@ -205,7 +205,7 @@ public: map all_branches() { typedef map branch_policies; - typedef map policy_branches; + typedef map policy_branches; branch_policies out = branches; for (policy_branches::iterator i = delegations.begin(); i != delegations.end(); ++i) @@ -262,7 +262,7 @@ namespace } }; - revision_id policy_branch_head(branch_name const & name, + revision_id policy_branch_head(branch_uid const & name, set const & trusted_signers, database & db) { @@ -311,21 +311,21 @@ public: policy_branch policy; bool passthru; policy_info(system_path const & spec_file, - branch_name const & prefix, + branch_prefix const & prefix, database & db) : policy(spec_file, prefix, db), passthru(false) { } explicit policy_info(database & db) - : policy(data(""), branch_name(""), db), passthru(true) + : policy(data(""), branch_prefix(""), db), passthru(true) { } }; -project_t::project_t(string const & project_name, +project_t::project_t(branch_prefix const & project_name, system_path const & spec_file, database & db) - : project_policy(new policy_info(spec_file, branch_name(project_name), db)), db(db) + : project_policy(new policy_info(spec_file, project_name, db)), db(db) {} project_t::project_t(database & db) @@ -407,6 +407,58 @@ project_t::get_branch_list(globish const } } +void +project_t::get_branch_list(std::set & branch_ids) +{ + branch_ids.clear(); + if (project_policy->passthru) + { + std::set names; + get_branch_list(names, false); + for (std::set::const_iterator i = names.begin(); + i != names.end(); ++i) + { + branch_ids.insert(branch_uid((*i)())); + } + return; + } + typedef map branchlist; + branchlist branches = project_policy->policy.branches(); + for (branchlist::const_iterator i = branches.begin(); + i != branches.end(); ++i) + { + branch_ids.insert(i->second.branch_cert_value); + } +} + +branch_uid +project_t::translate_branch(branch_name const & name) +{ + if (project_policy->passthru) + return branch_uid(name()); + typedef map branchlist; + branchlist branches = project_policy->policy.branches(); + branchlist::iterator i = branches.find(name); + I(i != branches.end()); + return i->second.branch_cert_value; +} + +branch_name +project_t::translate_branch(branch_uid const & uid) +{ + if (project_policy->passthru) + return branch_name(uid()); + typedef map branchlist; + branchlist branches = project_policy->policy.branches(); + for (branchlist::const_iterator i = branches.begin(); + i != branches.end(); ++i) + { + if (i->second.branch_cert_value == uid) + return i->first; + } + I(false); +} + namespace { struct not_in_branch : public is_failure ============================================================ --- project.hh 219133cc611351b778348c9ea310606f7bb6d55f +++ project.hh 2816798abe99c9d158db9c81a72168f0690597ab @@ -37,7 +37,7 @@ public: outdated_indicator indicator; public: - project_t(std::string const & project_name, + project_t(branch_prefix const & project_name, system_path const & spec_file, database & db); explicit project_t(database & db); @@ -45,6 +45,12 @@ public: void get_branch_list(std::set & names, bool check_certs_valid); void get_branch_list(globish const & glob, std::set & names, bool check_certs_valid); + + // used by 'ls epochs' + void get_branch_list(std::set & ids); + branch_uid translate_branch(branch_name const & branch); + branch_name translate_branch(branch_uid const & branch); + void get_branch_heads(branch_name const & name, std::set & heads, std::multimap *inverse_graph_cache_ptr = NULL); ============================================================ --- rcs_import.cc 352e42220856fef882d4125ca9df95c1896ceffb +++ rcs_import.cc 598256b753605b6452cfb1367aa8b2952ac9357e @@ -626,7 +626,7 @@ process_branch(string const & begin_vers { string branch; data branch_data; - hexenc branch_id; + hexenc branch_uid; vector< piece > branch_lines; bool priv = false; map::const_iterator be = cvs.branch_first_entries.find(*i); @@ -640,10 +640,10 @@ process_branch(string const & begin_vers construct_version(*curr_lines, *i, branch_lines, r); insert_into_db(curr_data, curr_id, - branch_lines, branch_data, branch_id, db); + branch_lines, branch_data, branch_uid, db); cvs.push_branch(branch, priv); - process_branch(*i, branch_lines, branch_data, branch_id, r, db, cvs); + process_branch(*i, branch_lines, branch_data, branch_uid, r, db, cvs); cvs.pop_branch(); L(FL("finished RCS branch %s = '%s'") % (*i) % branch); ============================================================ --- revision.cc 725c74dec3553f8e4a5f5d341b7101518fb83aba +++ revision.cc 7614a884a28582cbaf5d9cd98b3438c4ab0858fc @@ -923,7 +923,7 @@ void anc_graph::write_certs() encode_hexenc(data(string(buf, buf + constants::epochlen_bytes)), hexdata); epoch_data new_epoch(hexdata); L(FL("setting epoch for %s to %s") % *i % new_epoch); - db.set_epoch(branch_name(*i), new_epoch); + db.set_epoch(branch_uid(*i), new_epoch); } } ============================================================ --- vocab_terms.hh 80283d95bc08f3a9f8c1c503ebeebb51b03c384e +++ vocab_terms.hh 72f09f044b17a05a71bd9b738d99fd32ed279d3a @@ -21,6 +21,8 @@ ATOMIC_NOVERIFY(branch_name); // utf-8 ATOMIC_NOVERIFY(inodeprint); // fingerprint of an inode ATOMIC_NOVERIFY(branch_name); // utf-8 +ATOMIC_NOVERIFY(branch_prefix); // a partial branch name +ATOMIC_NOVERIFY(branch_uid); // what goes in the database ATOMIC(cert_name); // symbol-of-your-choosing ATOMIC_NOVERIFY(cert_value); // symbol-of-your-choosing