# # # patch "app_state.cc" # from [42d9c8b52697408e2e8c412b43da137fd93e1faf] # to [0e6eeee1fd1b550b884b73badf4dbf1811c721cf] # # patch "app_state.hh" # from [da07809aa88d917503bef7dcec8747ea1be036fd] # to [813313345c6967bd58fb2cd474f4124b74d43db2] # # patch "database.cc" # from [a66238a6b633d82f988003ae8c114bf19366b6a1] # to [9ca8614df165a0bacf041d38dd0e8f22deab9c72] # # patch "database.hh" # from [dd6db1d50f94c66c8b9a4090bd93c92d8885dcc3] # to [53d96fb6b25d162e5e684111d404edff5b049018] # # patch "paths.hh" # from [7dd47155b2962d3e4f5fe8764b11c955791803fc] # to [f0d9aab30593dfde43c6fc6f999619211184f9ed] # ============================================================ --- app_state.cc 42d9c8b52697408e2e8c412b43da137fd93e1faf +++ app_state.cc 0e6eeee1fd1b550b884b73badf4dbf1811c721cf @@ -9,14 +9,29 @@ #include "base.hh" #include "app_state.hh" +#include "database.hh" +#include + +class app_state_private +{ +public: + std::map > databases; +}; + app_state::app_state() - : lua(this), mtn_automate_allowed(false) + : _hidden(new app_state_private()), lua(this), mtn_automate_allowed(false) {} app_state::~app_state() {} +boost::shared_ptr & +app_state::lookup_db(system_path const & f) +{ + return _hidden->databases[f]; +} + // Local Variables: // mode: C++ // fill-column: 76 ============================================================ --- app_state.hh da07809aa88d917503bef7dcec8747ea1be036fd +++ app_state.hh 813313345c6967bd58fb2cd474f4124b74d43db2 @@ -13,27 +13,22 @@ #include "options.hh" #include "lua_hooks.hh" -// This class used to hold most of the state of the application (hence the -// name) but now it's just a wrapper around the options and lua_hooks -// objects, plus one bit of state needed by the Lua extension interfaces. -// -// It is not quite possible to eliminate this object altogether. The major -// remaining use is the Lua interface, which has a back-mapping from -// lua_state (not lua_hooks) objects to app_state objects. This is mainly -// needed for the mtn_automate() function, which allows lua-coded extension -// commands to call the automate commands. -// -// Since the options and lua_hooks objects are so frequently required -// together, it may make sense to merge them together and have that merged -// object replace the app_state. Or we could just go back to passing this -// around instead of separate options and lua_hooks objects. +// This class holds any state that needs to be persistent across multiple +// commands, or be accessible to the lua hooks (which includes anything +// needed by mtn_automate()). +class app_state_private; +class database_impl; class app_state { + boost::shared_ptr _hidden; public: explicit app_state(); ~app_state(); + boost::shared_ptr & + lookup_db(system_path const & f); + options opts; lua_hooks lua; bool mtn_automate_allowed; ============================================================ --- database.cc a66238a6b633d82f988003ae8c114bf19366b6a1 +++ database.cc 9ca8614df165a0bacf041d38dd0e8f22deab9c72 @@ -419,8 +419,15 @@ database::database(app_state & app) } database::database(app_state & app) - : imp(new database_impl(app.opts.dbname)), lua(app.lua) -{} + : lua(app.lua) +{ + boost::shared_ptr & i = app.lookup_db(app.opts.dbname); + if (!i) + { + i.reset(new database_impl(app.opts.dbname)); + } + imp = i; +} database::~database() {} ============================================================ --- database.hh dd6db1d50f94c66c8b9a4090bd93c92d8885dcc3 +++ database.hh 53d96fb6b25d162e5e684111d404edff5b049018 @@ -12,7 +12,7 @@ #include "vector.hh" #include -#include +#include #include "rev_types.hh" #include "cert.hh" @@ -433,7 +433,7 @@ private: revision_id const & id, cert_name const & name, cert_value const & val); private: - boost::scoped_ptr imp; + boost::shared_ptr imp; lua_hooks & lua; }; ============================================================ --- paths.hh 7dd47155b2962d3e4f5fe8764b11c955791803fc +++ paths.hh f0d9aab30593dfde43c6fc6f999619211184f9ed @@ -356,6 +356,9 @@ public: bool operator==(const system_path & other) const { return data== other.data; } + bool operator <(const system_path & other) const + { return data < other.data; } + system_path operator /(path_component const & to_append) const; system_path operator /(char const * to_append) const; system_path dirname() const;