# # # patch "cmd_netsync.cc" # from [bf1c5ae3d0a899d7d85818a6f54c68f937f23ae7] # to [1d285784b434393d4c08c0753b4f6f13acfe57eb] # # patch "cmd_ws_commit.cc" # from [17c00aea77ee4dfa4c94c73e502c18e9b5b090bb] # to [66f5a553e8431f3601880f1e03a2c143daf33771] # # patch "database.cc" # from [bfdca9782fd3065ea71c1d998cb863f6435efd13] # to [dd9e4ede72cfad9baaa9a66b9a8452502eb703cb] # # patch "database.hh" # from [49cf3e9f724bbebad9e0dd6412f7721986507f42] # to [7dfab82fad19276b981ad2abdad2c839335672a6] # # patch "lua_hooks.cc" # from [0833ddc36db81324641d7dbfdbfe4c1f8af2821a] # to [24acf3a1517806ad897f64f2787381d5ececd47f] # # patch "lua_hooks.hh" # from [c399d6fc2272cc4e44c3ca94a715c91dd433b9d6] # to [c17cea632b5a2fc1ceca34cfc3a7b1b75ae81246] # # patch "paths.hh" # from [20b799a53ccd8b1c6188c554d24e15f2872be59a] # to [9935beaae625aabbc9db1c24abac9c36ab2210f3] # # patch "std_hooks.lua" # from [eb6553628775cb5738d5320866a724c55e78e329] # to [9e851adae19356e30aaf341ae08881f895297087] # ============================================================ --- cmd_netsync.cc bf1c5ae3d0a899d7d85818a6f54c68f937f23ae7 +++ cmd_netsync.cc 1d285784b434393d4c08c0753b4f6f13acfe57eb @@ -421,7 +421,7 @@ CMD_AUTOMATE_NO_STDIO(remote, if (app.opts.dbname.empty()) { W(F("No database given; assuming ':memory:' database. This means that we can't\n" - "verify the server key, because we have no record of what it should be.") + "verify the server key, because we have no record of what it should be.") % memory_db_identifier); app.opts.dbname_type = memory_db; } @@ -703,12 +703,13 @@ CMD(clone, "clone", "", CMD_REF(network) target_is_current_dir ? _MTN_dir : workspace_dir ); - // paths.cc's idea of the current workspace root is wrong at this point - if (!app.opts.dbname_given || app.opts.dbname.empty()) - app.opts.dbname = system_path(workspace_dir - / bookkeeping_root_component - / bookkeeping_internal_db_file_name); + database db(app); + db.create_if_not_exists(); + db.ensure_open(); + // FIXME: newly created databases are not saved to _MTN/options since + // we're not updating app.opts yet + // this is actually stupid, but app.opts.branch must be set here // otherwise it will not be written into _MTN/options, in case // a revision is chosen which has multiple branch certs @@ -716,12 +717,6 @@ CMD(clone, "clone", "", CMD_REF(network) workspace::create_workspace(app.opts, app.lua, workspace_dir); app.opts.branch = branch_name(); - database db(app); - if (get_path_status(db.get_filename()) == path::nonexistent) - db.initialize(); - - db.ensure_open(); - key_store keys(app); project_t project(db); ============================================================ --- cmd_ws_commit.cc 17c00aea77ee4dfa4c94c73e502c18e9b5b090bb +++ cmd_ws_commit.cc 66f5a553e8431f3601880f1e03a2c143daf33771 @@ -199,9 +199,9 @@ get_log_message_interactively(lua_hooks revision_header(rid, rev, author, date, branch, changelog, date_fmt, header); revision_summary(rev, summary); - utf8 full_message(instructions() + cancel() + header() + notes() + summary(), + utf8 full_message(instructions() + cancel() + header() + notes() + summary(), origin::internal); - + external input_message; external output_message; @@ -787,8 +787,8 @@ CMD(status, "status", "", CMD_REF(inform string formatted = now.as_formatted_localtime(date_fmt); parsed = date_t::from_formatted_localtime(formatted, date_fmt); } - catch (recoverable_failure const & e) - { + catch (recoverable_failure const & e) + { L(FL("date check failed: %s") % e.what()); } @@ -1461,16 +1461,16 @@ CMD(commit, "commit", "ci", CMD_REF(work string formatted = date.as_formatted_localtime(date_fmt); parsed = date_t::from_formatted_localtime(formatted, date_fmt); } - catch (recoverable_failure const & e) - { + catch (recoverable_failure const & e) + { L(FL("date check failed: %s") % e.what()); } - + if (parsed != date) { L(FL("date check failed: %s != %s") % date % parsed); } - + E(parsed == date, origin::user, F("date format '%s' cannot be used for commit") % date_fmt); } @@ -1702,24 +1702,15 @@ CMD_NO_WORKSPACE(setup, "setup", "", CMD : workspace_dir ); - workspace::create_workspace(app.opts, app.lua, workspace_dir); + database db(app); + db.create_if_not_exists(); + db.ensure_open(); - if (!app.opts.dbname_given || app.opts.dbname.empty()) - { - app.opts.dbname = system_path(workspace_dir - / bookkeeping_root_component - / bookkeeping_internal_db_file_name); - } + // FIXME: newly created databases are not saved to _MTN/options since + // we're not updating app.opts yet - database db(app); - if (get_path_status(db.get_filename()) == path::nonexistent) - { - P(F("initializing new database '%s'") % db.get_filename()); - db.initialize(); - } + workspace::create_workspace(app.opts, app.lua, workspace_dir); - db.ensure_open(); - workspace work(app); revision_t rev; make_revision_for_workspace(revision_id(), cset(), rev); ============================================================ --- database.cc bfdca9782fd3065ea71c1d998cb863f6435efd13 +++ database.cc dd9e4ede72cfad9baaa9a66b9a8452502eb703cb @@ -618,6 +618,25 @@ void } void +database::create_if_not_exists() +{ + if (!opts.dbname_given) + { + string alias; + E(lua.hook_get_default_database_alias(alias) || alias.empty(), + origin::user, F("could not query default database alias")); + resolve_db_alias(lua, alias, imp->filename); + imp->type = managed_db; + } + + if (get_path_status(imp->filename) == path::nonexistent) + { + P(F("initializing new database '%s'") % imp->filename); + initialize(); + } +} + +void database::check_is_not_rosterified() { E(!imp->table_has_data("rosters"), origin::user, ============================================================ --- database.hh 49cf3e9f724bbebad9e0dd6412f7721986507f42 +++ database.hh 7dfab82fad19276b981ad2abdad2c839335672a6 @@ -93,6 +93,7 @@ public: bool is_dbfile(any_path const & file); bool database_specified(); void check_is_not_rosterified(); + void create_if_not_exists(); void ensure_open(); void ensure_open_for_format_changes(); ============================================================ --- lua_hooks.cc 0833ddc36db81324641d7dbfdbfe4c1f8af2821a +++ lua_hooks.cc 24acf3a1517806ad897f64f2787381d5ececd47f @@ -36,12 +36,7 @@ using std::make_pair; extern char const std_hooks_constant[]; using std::make_pair; -using std::map; -using std::pair; -using std::set; using std::sort; -using std::string; -using std::vector; static int panic_thrower(lua_State * st) { @@ -85,7 +80,7 @@ extern "C" int nArgs = lua_gettop(LS); lua_getglobal(LS, "tostring"); - std::string ret; + string ret; for (int i = 1; i <= nArgs; ++i) { const char *s; @@ -284,7 +279,7 @@ bool } bool -lua_hooks::hook_exists(std::string const & func_name) +lua_hooks::hook_exists(string const & func_name) { return Lua(st) .func(func_name) @@ -463,7 +458,7 @@ namespace { template bool shared_trust_function_body(Lua & ll, - set const & signers, + std::set const & signers, id const & hash, cert_name const & name, cert_value const & val) @@ -471,7 +466,7 @@ namespace { ll.push_table(); int k = 1; - for (typename set::const_iterator v = signers.begin(); + for (typename std::set::const_iterator v = signers.begin(); v != signers.end(); ++v) { ll.push_int(k); @@ -495,7 +490,7 @@ bool } bool -lua_hooks::hook_get_revision_cert_trust(set const & signers, +lua_hooks::hook_get_revision_cert_trust(std::set const & signers, id const & hash, cert_name const & name, cert_value const & val) @@ -506,7 +501,7 @@ bool } bool -lua_hooks::hook_get_manifest_cert_trust(set const & signers, +lua_hooks::hook_get_manifest_cert_trust(std::set const & signers, id const & hash, cert_name const & name, cert_value const & val) @@ -619,7 +614,7 @@ lua_hooks::hook_get_encloser_pattern(fil bool lua_hooks::hook_get_encloser_pattern(file_path const & path, - std::string & pattern) + string & pattern) { bool exec_ok = Lua(st) @@ -664,7 +659,7 @@ lua_hooks::hook_get_default_command_opti ll.begin(); while (ll.next()) { - std::string arg; + string arg; ll.extract_str(arg).pop(); args.push_back(arg_type(arg, origin::user)); } @@ -672,7 +667,7 @@ bool } bool -lua_hooks::hook_get_date_format_spec(date_format_spec in, std::string & out) +lua_hooks::hook_get_date_format_spec(date_format_spec in, string & out) { string in_spec; switch (in) @@ -700,8 +695,20 @@ lua_hooks::hook_get_date_format_spec(dat return exec_ok; } -bool lua_hooks::hook_get_default_database_locations(std::vector & out) +bool lua_hooks::hook_get_default_database_alias(string & alias) { + bool exec_ok + = Lua(st) + .func("get_default_database_alias") + .call(0, 1) + .extract_str(alias) + .ok(); + + return exec_ok; +} + +bool lua_hooks::hook_get_default_database_locations(vector & out) +{ Lua ll(st); ll.func("get_default_database_locations"); ll.call(0, 1); @@ -709,22 +716,22 @@ bool lua_hooks::hook_get_default_databas ll.begin(); while (ll.next()) { - std::string path; + string path; ll.extract_str(path).pop(); out.push_back(system_path(path, origin::user)); } return ll.ok() && !out.empty(); } -bool lua_hooks::hook_hook_wrapper(std::string const & func_name, - std::vector const & args, - std::string & out) +bool lua_hooks::hook_hook_wrapper(string const & func_name, + vector const & args, + string & out) { Lua ll(st); ll.func("hook_wrapper") .push_str(func_name); - for (std::vector::const_iterator i = args.begin(); + for (vector::const_iterator i = args.begin(); i != args.end(); ++i) { ll.push_str(*i); @@ -838,7 +845,7 @@ lua_hooks::hook_get_netsync_connect_comm globish const & include_pattern, globish const & exclude_pattern, bool debug, - std::vector & argv) + vector & argv) { bool cmd = false, exec_ok = false; Lua ll(st); @@ -876,7 +883,7 @@ lua_hooks::hook_get_netsync_connect_comm argv.clear(); while(ll.next()) { - std::string s; + string s; ll.extract_str(s).pop(); argv.push_back(s); } @@ -1151,7 +1158,7 @@ lua_hooks::hook_note_netsync_revision_re bool lua_hooks::hook_note_netsync_revision_received(revision_id const & new_id, revision_data const & rdat, - set > > const & certs, size_t session_id) @@ -1164,7 +1171,7 @@ lua_hooks::hook_note_netsync_revision_re ll.push_table(); - typedef set > > cdat; + typedef std::set > > cdat; int n = 1; for (cdat::const_iterator i = certs.begin(); i != certs.end(); ++i) @@ -1188,7 +1195,7 @@ lua_hooks::hook_note_netsync_revision_se bool lua_hooks::hook_note_netsync_revision_sent(revision_id const & new_id, revision_data const & rdat, - set > > const & certs, size_t session_id) @@ -1201,7 +1208,7 @@ lua_hooks::hook_note_netsync_revision_se ll.push_table(); - typedef set > > cdat; + typedef std::set > > cdat; int n = 1; for (cdat::const_iterator i = certs.begin(); i != certs.end(); ++i) ============================================================ --- lua_hooks.hh c399d6fc2272cc4e44c3ca94a715c91dd433b9d6 +++ lua_hooks.hh c17cea632b5a2fc1ceca34cfc3a7b1b75ae81246 @@ -22,6 +22,11 @@ #include "paths.hh" #include "commands.hh" +using std::string; +using std::vector; +using std::map; +using std::pair; + struct uri_t; class app_state; class key_store; @@ -46,20 +51,20 @@ public: ~lua_hooks(); bool check_lua_state(lua_State * st) const; void load_rcfiles(options & opts); - bool hook_exists(std::string const & func_name); + bool hook_exists(string const & func_name); // cert hooks - bool hook_expand_selector(std::string const & sel, std::string & exp); - bool hook_expand_date(std::string const & sel, std::string & exp); + bool hook_expand_selector(string const & sel, string & exp); + bool hook_expand_date(string const & sel, string & exp); bool hook_get_branch_key(branch_name const & branchname, key_store & keys, project_t & project, key_id & k); bool hook_get_passphrase(key_identity_info const & info, - std::string & phrase); + string & phrase); bool hook_get_local_key_name(key_identity_info & info); bool hook_get_author(branch_name const & branchname, key_identity_info const & info, - std::string & author); + string & author); bool hook_edit_comment(external const & user_log_message, external & result); bool hook_persist_phrase_ok(); @@ -71,8 +76,8 @@ public: id const & hash, cert_name const & name, cert_value const & val); - bool hook_accept_testresult_change(std::map const & old_results, - std::map const & new_results); + bool hook_accept_testresult_change(map const & old_results, + map const & new_results); // network hooks bool hook_get_netsync_key(utf8 const & server_address, @@ -85,18 +90,18 @@ public: globish const & include_pattern, globish const & exclude_pattern, bool debug, - std::vector & argv); + vector & argv); bool hook_use_transport_auth(uri_t const & uri); - bool hook_get_netsync_read_permitted(std::string const & branch, + bool hook_get_netsync_read_permitted(string const & branch, key_identity_info const & identity); // anonymous no-key version - bool hook_get_netsync_read_permitted(std::string const & branch); + bool hook_get_netsync_read_permitted(string const & branch); bool hook_get_netsync_write_permitted(key_identity_info const & identity); bool hook_get_remote_automate_permitted(key_identity_info const & identity, - std::vector const & command_line, - std::vector > const & command_opts); + vector const & command_line, + vector > const & command_opts); // local repo hooks bool hook_ignore_file(file_path const & p); @@ -115,30 +120,32 @@ public: data const & data_new, bool is_binary, bool diff_args_provided, - std::string const & diff_args, - std::string const & oldrev, - std::string const & newrev); + string const & diff_args, + string const & oldrev, + string const & newrev); bool hook_get_encloser_pattern(file_path const & path, - std::string & pattern); + string & pattern); bool hook_get_default_command_options(commands::command_id const & cmd, args_vector & args); - bool hook_get_date_format_spec(date_format_spec in, std::string & out); + bool hook_get_date_format_spec(date_format_spec in, string & out); - bool hook_get_default_database_locations(std::vector & out); + bool hook_get_default_database_alias(string & alias); + bool hook_get_default_database_locations(vector & out); + // workspace hooks bool hook_use_inodeprints(); // attribute hooks bool hook_init_attributes(file_path const & filename, - std::map & attrs); - bool hook_set_attribute(std::string const & attr, + map & attrs); + bool hook_set_attribute(string const & attr, file_path const & filename, - std::string const & value); - bool hook_clear_attribute(std::string const & attr, + string const & value); + bool hook_clear_attribute(string const & attr, file_path const & filename); // validation hooks @@ -146,35 +153,35 @@ public: revision_data const & new_rev, branch_name const & branchname, bool & validated, - std::string & reason); + string & reason); // meta hooks - bool hook_hook_wrapper(std::string const & func_name, - std::vector const & args, - std::string & out); + bool hook_hook_wrapper(string const & func_name, + vector const & args, + string & out); // notification hooks bool hook_note_commit(revision_id const & new_id, revision_data const & rdat, - std::map const & certs); + map const & certs); bool hook_note_netsync_start(size_t session_id, - std::string my_role, + string my_role, int sync_type, - std::string remote_host, + string remote_host, key_identity_info const & remote_key, globish include_pattern, globish exclude_pattern); bool hook_note_netsync_revision_received(revision_id const & new_id, revision_data const & rdat, - std::set > > const & certs, size_t session_id); bool hook_note_netsync_revision_sent(revision_id const & new_id, revision_data const & rdat, - std::set > > const & certs, size_t session_id); bool hook_note_netsync_pubkey_received(key_identity_info const & identity, @@ -199,15 +206,14 @@ public: bool hook_note_mtn_startup(args_vector const & args); // git export hooks - bool hook_unmapped_git_author(std::string const & unmapped_author, - std::string & fixed_author); - bool hook_validate_git_author(std::string const & author); + bool hook_unmapped_git_author(string const & unmapped_author, + string & fixed_author); + bool hook_validate_git_author(string const & author); }; #endif // __LUA_HOOKS_HH__ -// Local Variables: // mode: C++ // fill-column: 76 // c-file-style: "gnu" ============================================================ --- paths.hh 20b799a53ccd8b1c6188c554d24e15f2872be59a +++ paths.hh 9935beaae625aabbc9db1c24abac9c36ab2210f3 @@ -348,7 +348,6 @@ private: #define bookkeeping_root (bookkeeping_path("_MTN")) #define bookkeeping_root_component (path_component("_MTN")) -#define bookkeeping_internal_db_file_name (path_component("mtn.db")) // for migration #define old_bookkeeping_root_component (path_component("MT")) ============================================================ --- std_hooks.lua eb6553628775cb5738d5320866a724c55e78e329 +++ std_hooks.lua 9e851adae19356e30aaf341ae08881f895297087 @@ -1251,6 +1251,10 @@ end return default_args end +function get_default_database_alias() + return ":default.mtn" +end + function get_default_database_locations() local paths = {} table.insert(paths, get_confdir() .. "/databases")