# # # patch "app_state.cc" # from [4173b14541089d94af06287dca7782a65a9bbad6] # to [354e6301731ad03a7bc0a1ee2eead3de0bc75b7b] # # patch "app_state.hh" # from [22dc5f60fa3d331fb65a4ba92d6f18235900054d] # to [6cf59f29bb9989cafbb6d86bf09f48622974ff20] # # patch "key_store.cc" # from [94f2aac8313c841745ffe7caadc284f57d6cdd88] # to [f938c386df63885d1ccb75fb6e57c91e0172b24c] # # patch "lua_hooks.cc" # from [5f4045fd523ea215bfc705555b03c4f2dbd38b45] # to [8b2119a72410c7c5f7f997473c61010f4cb1473a] # # patch "lua_hooks.hh" # from [2604a4a3a5244ba91c7b74a60a5bb762b114ddc5] # to [e9569a63763815809452a9705e7ed2c2b3a63e66] # ============================================================ --- app_state.cc 4173b14541089d94af06287dca7782a65a9bbad6 +++ app_state.cc 354e6301731ad03a7bc0a1ee2eead3de0bc75b7b @@ -29,20 +29,15 @@ app_state::app_state() using std::vector; app_state::app_state() - : db(lua), keys(*this), work(lua), + : lua(this), keys(*this), db(lua), work(lua), branch_is_sticky(false), mtn_automate_allowed(false), project(db) -{ - lua.set_app(this); - keys.set_key_dir(opts.conf_dir / "keys"); -} +{} app_state::~app_state() -{ -} +{} - void app_state::allow_workspace() { @@ -58,7 +53,7 @@ app_state::allow_workspace() // dir's _MTN rather than the new workspace dir's _MTN. global_sanity.set_dump_path(system_path(dump_path, false).as_external()); } - load_rcfiles(); + lua.load_rcfiles(opts); } void @@ -77,11 +72,13 @@ app_state::process_options() key_option, keydir_option); // Workspace options are not to override the command line. - if (db.get_filename().as_internal().empty() && !database_option.as_internal().empty()) + if (db.get_filename().as_internal().empty() + && !database_option.as_internal().empty()) db.set_filename(database_option); - if (keys.get_key_dir().as_internal().empty() && !keydir_option.as_internal().empty()) - set_key_dir(keydir_option); + if (keys.get_key_dir().as_internal().empty() + && !keydir_option.as_internal().empty()) + keys.set_key_dir(keydir_option); if (opts.branchname().empty() && !branch_option().empty()) { @@ -164,7 +161,7 @@ app_state::create_workspace(system_path // dir's _MTN rather than the new workspace dir's _MTN. global_sanity.set_dump_path(system_path(dump_path, false).as_external()); - load_rcfiles(); + lua.load_rcfiles(opts); } void @@ -188,15 +185,6 @@ void } void -app_state::set_key_dir(system_path const & filename) -{ - if (!filename.empty()) - { - keys.set_key_dir(filename); - } -} - -void app_state::make_branch_sticky() { branch_is_sticky = true; @@ -220,36 +208,7 @@ app_state::get_project() // _MTN/monotonerc can be loaded between ~/.monotone/monotonerc and other // rcfiles. -void -app_state::load_rcfiles() -{ - // Built-in rc settings are defaults. - if (!opts.nostd) - lua.add_std_hooks(); - - // ~/.monotone/monotonerc overrides that, and - // _MTN/monotonerc overrides *that*. - - if (!opts.norc) - { - system_path default_rcfile; - bookkeeping_path workspace_rcfile; - lua.default_rcfilename(default_rcfile); - lua.workspace_rcfilename(workspace_rcfile); - lua.load_rcfile(default_rcfile, false); - lua.load_rcfile(workspace_rcfile, false); - } - - // Command-line rcfiles override even that. - - for (args_vector::const_iterator i = opts.extra_rcfiles.begin(); - i != opts.extra_rcfiles.end(); ++i) - { - lua.load_rcfile(*i); - } -} - // Local Variables: // mode: C++ // fill-column: 76 ============================================================ --- app_state.hh 22dc5f60fa3d331fb65a4ba92d6f18235900054d +++ app_state.hh 6cf59f29bb9989cafbb6d86bf09f48622974ff20 @@ -10,9 +10,6 @@ // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. -class app_state; -class lua_hooks; - #include "database.hh" #include "key_store.hh" #include "lua_hooks.hh" @@ -31,13 +28,12 @@ public: class app_state { public: + options opts; lua_hooks lua; - database db; key_store keys; + database db; workspace work; - options opts; - bool found_workspace; bool branch_is_sticky; bool mtn_automate_allowed; @@ -63,14 +59,11 @@ public: project_t & get_project(); // get_project(opts.project) or I() void set_database(system_path const & filename); - void set_key_dir(system_path const & filename); - void set_diff_format(diff_type dtype); explicit app_state(); ~app_state(); private: - void load_rcfiles(); void write_options(); }; ============================================================ --- key_store.cc 94f2aac8313c841745ffe7caadc284f57d6cdd88 +++ key_store.cc f938c386df63885d1ccb75fb6e57c91e0172b24c @@ -56,7 +56,7 @@ class key_store_state scoped_ptr agent; key_store_state(app_state & app) - : have_read(false), app(app) + : key_dir(app.opts.conf_dir / "keys"), have_read(false), app(app) {} public: @@ -130,8 +130,7 @@ key_store::key_store(app_state & a) key_store::key_store(app_state & a) : s(new key_store_state(a)) -{ -} +{} key_store::~key_store() {} ============================================================ --- lua_hooks.cc 5f4045fd523ea215bfc705555b03c4f2dbd38b45 +++ lua_hooks.cc 8b2119a72410c7c5f7f997473c61010f4cb1473a @@ -84,7 +84,7 @@ get_app_state(lua_State *L) return NULL; } -lua_hooks::lua_hooks() +lua_hooks::lua_hooks(app_state * app) { st = luaL_newstate(); I(st); @@ -109,6 +109,8 @@ lua_hooks::lua_hooks() if (!run_string(st, disable_dangerous, "")) throw oops("lua error while disabling existing functions"); + + map_of_lua_to_app.insert(make_pair(st, app)); } lua_hooks::~lua_hooks() @@ -120,12 +122,6 @@ lua_hooks::~lua_hooks() map_of_lua_to_app.erase(i); } -void -lua_hooks::set_app(app_state *_app) -{ - map_of_lua_to_app.insert(make_pair(st, _app)); -} - bool lua_hooks::check_lua_state(lua_State * p_st) const { @@ -140,21 +136,6 @@ void } void -lua_hooks::default_rcfilename(system_path & file) -{ - map::iterator i = map_of_lua_to_app.find(st); - I(i != map_of_lua_to_app.end()); - file = i->second->opts.conf_dir / "monotonerc"; -} - -void -lua_hooks::workspace_rcfilename(bookkeeping_path & file) -{ - file = bookkeeping_root / "monotonerc"; -} - - -void lua_hooks::load_rcfile(utf8 const & rc) { I(st); @@ -205,6 +186,29 @@ lua_hooks::load_rcfile(any_path const & } } +void +lua_hooks::load_rcfiles(options & opts) +{ + // Built-in rc settings are defaults. + if (!opts.nostd) + add_std_hooks(); + + // ~/.monotone/monotonerc overrides that, and + // _MTN/monotonerc overrides *that*. + + if (!opts.norc) + { + load_rcfile(opts.conf_dir / "monotonerc", false); + load_rcfile(bookkeeping_root / "monotonerc", false); + } + + // Command-line rcfiles override even that. + + for (args_vector::const_iterator i = opts.extra_rcfiles.begin(); + i != opts.extra_rcfiles.end(); ++i) + load_rcfile(*i); +} + bool lua_hooks::hook_exists(std::string const & func_name) { ============================================================ --- lua_hooks.hh 2604a4a3a5244ba91c7b74a60a5bb762b114ddc5 +++ lua_hooks.hh e9569a63763815809452a9705e7ed2c2b3a63e66 @@ -24,6 +24,7 @@ struct globish; class app_state; struct lua_State; struct globish; +struct options; extern app_state* get_app_state(lua_State *L); @@ -31,16 +32,15 @@ class lua_hooks { struct lua_State * st; -public: - lua_hooks(); - ~lua_hooks(); - void set_app(app_state *_app); - bool check_lua_state(lua_State * st) const; void add_std_hooks(); - void workspace_rcfilename(bookkeeping_path & file); - void default_rcfilename(system_path & file); void load_rcfile(utf8 const & file); void load_rcfile(any_path const & file, bool required); + +public: + lua_hooks(app_state * app); + ~lua_hooks(); + bool check_lua_state(lua_State * st) const; + void load_rcfiles(options & opts); bool hook_exists(std::string const & func_name); // cert hooks