# # add_file "tests/t_config_confdir.at" # # patch "ChangeLog" # from [4ab026edce5eb014efcd0f814a88afc27fa9d233] # to [e82e8b186856cd80765c372655b8fdb05398eb24] # # patch "app_state.cc" # from [7c07c3e2fdd93785501045113bb5ad53c7b9c8c6] # to [fd3e1deba7b7e624fbd20f765baf96b74fda7cb6] # # patch "app_state.hh" # from [3038b295c471109120a068d0219cfc96d06fb199] # to [70bf85df97ed32d4671b8ebf219bdde7ec851397] # # patch "key_store.cc" # from [32a483ab9e29305e02c76f9c7b0cac9ce6f723d5] # to [90b1da1b21ccd13d0de9285462f8a708773f0ecf] # # patch "lua.cc" # from [24a3cd17ad43d16e88444b9a64b50cf247a12c33] # to [2c76b85ac161a63912f30eab352abd8220b7b32c] # # patch "lua.hh" # from [a36a8bff73690208d4d879fc868696315881a465] # to [bcfc2e328c34272f77440bcb7e67f854b8f87f1f] # # patch "monotone.cc" # from [ac18f5db69aaf109485e4e807365247964ae955f] # to [8c23f5814ae8730ac72e4c4e51c5ea7aaed31a3b] # # patch "options.hh" # from [3fbf3de00d5b037c5de4cb232691e19a02488aa5] # to [7d90588b90ca771e06d433e2649d766690b2ed31] # # patch "tests/t_config_confdir.at" # from [] # to [0436211514ef07656dae6576dfb25edf9f6df3d4] # # patch "testsuite.at" # from [04961a46b716fbe9cb9a36e26361a14db6a44a31] # to [3dd7d23b79312c68c41089c651f9d1d7e91f150e] # ======================================================================== --- ChangeLog 4ab026edce5eb014efcd0f814a88afc27fa9d233 +++ ChangeLog e82e8b186856cd80765c372655b8fdb05398eb24 @@ -1,5 +1,17 @@ 2005-10-16 Timothy Brownawell + Make the configuration directory configurable and available to lua + * lua.cc: export new function to lua, "get_confdir" + * app_state.{cc,hh} monotone.cc options.hh: new option --confdir, + make the configuration directory something other than ~/.monotone + * lua.{cc,hh}: make the app_state availabe to lua callbacks + * key_store.cc: use get_confdir instead of hardcoded + * lua.cc: use get_confdir instead of hardcoded + * tests/t_config_confdir.at: test --confdir and lua get_confdir + * testsuite.at: add it + +2005-10-16 Timothy Brownawell + Teach client to optionally push unused keys; new pubkeys can now be given to a server without restarting it. * app_state.{cc,hh}, monotone.cc, options.hh: ======================================================================== --- app_state.cc 7c07c3e2fdd93785501045113bb5ad53c7b9c8c6 +++ app_state.cc fd3e1deba7b7e624fbd20f765baf96b74fda7cb6 @@ -39,9 +39,11 @@ no_merges(false), set_default(false), verbose(false), search_root("/"), depth(-1), last(-1), diff_format(unified_diff), diff_args_provided(false), use_lca(false), execute(false), bind_address(""), bind_port(""), - missing(false), unknown(false) + missing(false), unknown(false), + confdir(system_path(get_homedir()) / ".monotone") { db.set_app(this); + lua.set_app(this); } app_state::~app_state() @@ -404,6 +406,18 @@ extra_rcfiles.push_back(filename); } +void +app_state::set_confdir(system_path const & cd) +{ + confdir = cd; +} + +system_path +app_state::get_confdir() +{ + return confdir; +} + // rc files are loaded after we've changed to the working copy directory so // that MT/monotonerc can be loaded between ~/.monotone/monotonerc and other // rcfiles ======================================================================== --- app_state.hh 3038b295c471109120a068d0219cfc96d06fb199 +++ app_state.hh 70bf85df97ed32d4671b8ebf219bdde7ec851397 @@ -67,9 +67,9 @@ bool missing; bool unknown; std::vector keys_to_push; + system_path confdir; - // These are used to cache signers/verifiers (if the hook allows). // They can't be function-static variables in key.cc, since they must be // destroyed before the Botan deinitialize() function is called. */ @@ -120,6 +120,9 @@ void set_verbose(bool b); void add_rcfile(utf8 const & filename); + void set_confdir(system_path const & cd); + system_path get_confdir(); + explicit app_state(); ~app_state(); ======================================================================== --- key_store.cc 32a483ab9e29305e02c76f9c7b0cac9ce6f723d5 +++ key_store.cc 90b1da1b21ccd13d0de9285462f8a708773f0ecf @@ -63,7 +63,7 @@ key_store::key_store(app_state * a): have_read(false), app(a) { - key_dir = system_path(get_homedir()) / ".monotone/keys"; + key_dir = app->get_confdir() / "keys"; } void ======================================================================== --- lua.cc 24a3cd17ad43d16e88444b9a64b50cf247a12c33 +++ lua.cc 2c76b85ac161a63912f30eab352abd8220b7b32c @@ -43,6 +43,14 @@ using namespace std; using boost::lexical_cast; +// this lets the lua callbacks (monotone_*_for_lua) have access to the +// app_state the're associated with. +// it was added so that the confdir (normally ~/.monotone) can be specified on +// the command line (and so known only to the app_state), and still be +// available to lua +// please *don't* use it for complex things that can throw errors +static std::map map_of_lua_to_app; + static int panic_thrower(lua_State * st) { throw oops("lua panic"); @@ -625,6 +633,21 @@ lua_pushstring(L, gettext(msgid)); return 1; } + + static int + monotone_get_confdir_for_lua(lua_State *L) + { + map::iterator i = map_of_lua_to_app.find(L); + if (i != map_of_lua_to_app.end()) + { + system_path dir = i->second->get_confdir(); + string confdir = dir.as_external(); + lua_pushstring(L, confdir.c_str()); + } + else + lua_pushnil(L); + return 1; + } } @@ -655,6 +678,7 @@ lua_register(st, "include", monotone_include_for_lua); lua_register(st, "includedir", monotone_includedir_for_lua); lua_register(st, "gettext", monotone_gettext_for_lua); + lua_register(st, "get_confdir", monotone_get_confdir_for_lua); // add regex functions: lua_newtable(st); @@ -671,10 +695,19 @@ lua_hooks::~lua_hooks() { + map::iterator i = map_of_lua_to_app.find(st); if (st) lua_close (st); + if (i != map_of_lua_to_app.end()) + 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)); +} + static bool run_string(lua_State * st, string const &str, string const & identity) { @@ -717,7 +750,9 @@ void lua_hooks::default_rcfilename(system_path & file) { - file = system_path(get_homedir()) / ".monotone/monotonerc"; + map::iterator i = map_of_lua_to_app.find(st); + I(i != map_of_lua_to_app.end()); + file = i->second->get_confdir() / "monotonerc"; } void ======================================================================== --- lua.hh a36a8bff73690208d4d879fc868696315881a465 +++ lua.hh bcfc2e328c34272f77440bcb7e67f854b8f87f1f @@ -32,6 +32,7 @@ #ifdef BUILD_UNIT_TESTS void add_test_hooks(); #endif + void set_app(app_state *_app); void add_std_hooks(); void working_copy_rcfilename(bookkeeping_path & file); void default_rcfilename(system_path & file); ======================================================================== --- monotone.cc ac18f5db69aaf109485e4e807365247964ae955f +++ monotone.cc 8c23f5814ae8730ac72e4c4e51c5ea7aaed31a3b @@ -97,6 +97,7 @@ {"root", 0, POPT_ARG_STRING, &argstr, OPT_ROOT, gettext_noop("limit search for working copy to specified root"), NULL}, {"verbose", 0, POPT_ARG_NONE, NULL, OPT_VERBOSE, gettext_noop("verbose completion output"), NULL}, {"keydir", 0, POPT_ARG_STRING, &argstr, OPT_KEY_DIR, gettext_noop("set location of key store"), NULL}, + {"confdir", 0, POPT_ARG_STRING, &argstr, OPT_CONF_DIR, gettext_noop("set location of configuration directory"), NULL}, { NULL, 0, 0, NULL, 0, NULL, NULL } }; @@ -341,6 +342,10 @@ app.set_key_dir(system_path(argstr)); break; + case OPT_CONF_DIR: + app.set_confdir(system_path(argstr)); + break; + case OPT_TICKER: if (string(argstr) == "dot") ui.set_tick_writer(new tick_write_dot); ======================================================================== --- options.hh 3fbf3de00d5b037c5de4cb232691e19a02488aa5 +++ options.hh 7d90588b90ca771e06d433e2649d766690b2ed31 @@ -48,3 +48,4 @@ #define OPT_MISSING 39 #define OPT_UNKNOWN 40 #define OPT_KEY_TO_PUSH 41 +#define OPT_CONF_DIR 42 ======================================================================== --- tests/t_config_confdir.at +++ tests/t_config_confdir.at 0436211514ef07656dae6576dfb25edf9f6df3d4 @@ -0,0 +1,15 @@ +AT_SETUP([--confdir option and get_confdir lua function work]) +MONOTONE_SETUP + +AT_DATA([myhooks],[-- lua script to check that --condfir works +dir = get_confdir() +if string.find(dir, "fooxyzzybar$") then + file = io.open(dir .. "/checkfile", "w") + file:write("foobar") + io.close(file) +end +]) +AT_CHECK(mkdir fooxyzzybar) +AT_CHECK(MONOTONE --confdir=fooxyzzybar --rcfile=myhooks ls known) +AT_CHECK(cat fooxyzzybar/checkfile, [], [ignore]) +AT_CLEANUP ======================================================================== --- testsuite.at 04961a46b716fbe9cb9a36e26361a14db6a44a31 +++ testsuite.at 3dd7d23b79312c68c41089c651f9d1d7e91f150e @@ -716,3 +716,4 @@ m4_include(tests/t_log_outside_working_dir.at) m4_include(tests/t_add_inside_MT.at) m4_include(tests/t_annotate_renames.at) +m4_include(tests/t_config_confdir.at)