# # # patch "NEWS" # from [1906aeba854db64c27e2f183041338dbeb7629f0] # to [d7967f2eb3746ce5cf4e3e2b4c6222ace128c0e7] # # patch "cmd_automate.cc" # from [e93266b419cc95eeae2fedab02968517db6df522] # to [6bbbc31ad43b38d1302a66d9159161ae0a94af2c] # # patch "tests/user_commands/__driver__.lua" # from [7b9aabef505324310c292dd5913a04e271182279] # to [2b055b6f2260cca989d4355759f7b8710beef7fb] # # patch "tests/user_commands/extra_rc" # from [44cbc37ae51041e2ee4b8c3e7ea290d32b85a11b] # to [5664866b7fd6713b984be964b2684440748077a8] # ============================================================ --- NEWS 1906aeba854db64c27e2f183041338dbeb7629f0 +++ NEWS d7967f2eb3746ce5cf4e3e2b4c6222ace128c0e7 @@ -1,3 +1,19 @@ +??? ??? ?? ??:??:?? UTC 2009 + + 0.43 release. + + Changes + + Bugs fixed + + New features + + - The `mtn_automate' lua function now correctly parses and sets + options for executed automate commands. + + Internal + + Fri Dec 26 22:08:00 UTC 2008 0.42 release. ============================================================ --- cmd_automate.cc e93266b419cc95eeae2fedab02968517db6df522 +++ cmd_automate.cc 6bbbc31ad43b38d1302a66d9159161ae0a94af2c @@ -402,10 +402,8 @@ CMD_AUTOMATE(stdio, "", command const * cmd = CMD_REF(automate)->find_command(id); I(cmd != NULL); - automate const * acmd = reinterpret_cast< automate const * >(cmd); + opts = options::opts::globals() | cmd->opts(); - opts = options::opts::globals() | acmd->opts(); - if (cmd->use_workspace_options()) { // Re-read the ws options file, rather than just copying @@ -416,6 +414,8 @@ CMD_AUTOMATE(stdio, "", } opts.instantiate(&app.opts).from_key_value_pairs(params); + + automate const * acmd = reinterpret_cast< automate const * >(cmd); acmd->exec_from_automate(app, id, args, os); } else @@ -451,8 +451,6 @@ LUAEXT(mtn_automate, ) // don't allow recursive calls app_p->mtn_automate_allowed = false; - // automate_ostream os(output, app_p->opts.automate_stdio_size); - int n = lua_gettop(L); E(n > 0, F("Bad input to mtn_automate() lua extension: command name is missing")); @@ -466,6 +464,17 @@ LUAEXT(mtn_automate, ) args.push_back(next_arg); } + options::options_type opts; + opts = options::opts::all_options() - options::opts::globals(); + opts.instantiate(&app_p->opts).reset(); + + // the arguments for a command are read from app.opts.args which + // is already cleaned from all options. this variable, however, still + // contains the original arguments with which the user function was + // called. Since we're already in lua context, it makes no sense to + // preserve them for the outside world, so we're just clearing them. + app_p->opts.args.clear(); + commands::command_id id; for (args_vector::const_iterator iter = args.begin(); iter != args.end(); iter++) @@ -493,10 +502,23 @@ LUAEXT(mtn_automate, ) commands::command const * cmd = CMD_REF(automate)->find_command(id); I(cmd != NULL); - commands::automate const * acmd = reinterpret_cast< commands::automate const * >(cmd); + opts = options::opts::globals() | cmd->opts(); - acmd->exec(*app_p, id, args, os); + if (cmd->use_workspace_options()) + { + // Re-read the ws options file, rather than just copying + // the options from the previous apts.opts object, because + // the file may have changed due to user activity. + workspace::check_ws_format(); + workspace::get_ws_options(app_p->opts); + } + opts.instantiate(&app_p->opts).from_command_line(args, false); + args_vector & parsed_args = app_p->opts.args; + + commands::automate const * acmd = reinterpret_cast< commands::automate const * >(cmd); + acmd->exec(*app_p, id, app_p->opts.args, os); + // allow further calls app_p->mtn_automate_allowed = true; } ============================================================ --- tests/user_commands/__driver__.lua 7b9aabef505324310c292dd5913a04e271182279 +++ tests/user_commands/__driver__.lua 2b055b6f2260cca989d4355759f7b8710beef7fb @@ -6,6 +6,20 @@ rev_a = base_revision() commit() rev_a = base_revision() +-- a simple command w/o the use of options check(mtn("check_head", "--rcfile=extra_rc", rev_a), 0, true, false) +check(samelines("stdout", {"heads are equal", "end of command"})) -check(samelines("stdout", {"heads are equal", "end of command"})) +addfile("bar", "more random info\n") +commit() +rev_b = base_revision() + +-- another simple command this time with arguments which are set as options +-- in the underlying automate content_diff calls. we test here that +-- a) the basic call succeeds +-- b) options given to mtn_automate are parsed correctly (see extra_rc) +-- c) outer command line arguments are not passed to the inner mtn_automate +-- calls (otherwise both revisions would lead to path restriction errors) +check(mtn("diff_two_revs", "--rcfile=extra_rc", rev_a, rev_b), 0, false, false) + + ============================================================ --- tests/user_commands/extra_rc 44cbc37ae51041e2ee4b8c3e7ea290d32b85a11b +++ tests/user_commands/extra_rc 5664866b7fd6713b984be964b2684440748077a8 @@ -1,5 +1,5 @@ function check_head(...) function check_head(...) - mtn_automate("get_option", "branch") -- make sure we have a valid workspace + ok, branch = mtn_automate("get_option", "branch") -- make sure we have a valid workspace ok, heads = mtn_automate("heads") if not ok then print("automate call failed") @@ -17,3 +17,16 @@ register_command("check_head", "", "Chec register_command("check_head", "", "Check that the heads of the branch are what is passed in", "This is a bogus command used to demonstrate user commands.", "check_head") + +function diff_two_revs(rev_a, rev_b) + ok, out = mtn_automate("content_diff", "-r", rev_a, "-r", rev_b) + if not ok then + print("automate call failed: " .. out) + return 1 + end + return 0 +end + + +register_command("diff_two_revs", "", "Outputs the differences between two revs", + "This is a bogus command used to demonstrate user commands with options.", "diff_two_revs")