# # # patch "app_state.cc" # from [ffe7d555550ba0029a88e3e0fcfdfe99c1a8720b] # to [ecc7ff55c4dbe286fe568bda51ca826b8d31e3ac] # # patch "automate.cc" # from [ee573f26aa839258423b024608db769f87f02483] # to [eafada922c297d508bb1e327a56c40d539d65e81] # # patch "cmd.hh" # from [5c6809b9a65951b6e69d3bb80ff2d6d42781c511] # to [fc17371af6593442b631faf4d4e35388138a5360] # # patch "cmd_automate.cc" # from [69aefb502195a4d228f1cc39045ee72d42958b84] # to [7506aaf4ba90dd26d31ba28574fd12bd0d838daf] # # patch "cmd_diff_log.cc" # from [1b7f8c23e25beaa81669eefb504de8315b7fbd4d] # to [0d01fb3a1b4c83bbd1384519f8c10b1a34acfcb5] # # patch "cmd_list.cc" # from [0ff9de55b90f18b284382b82ebfd43b405567a41] # to [0c16e7edb207dfbae0dd6ee15c7a726e250aae11] # # patch "cmd_merging.cc" # from [af61f02853172ea7a6c53cee6579c0220766d53d] # to [224a6b50161b9a26ae50652692b83a436911704d] # # patch "cmd_netsync.cc" # from [85389e376de990a6beb16c7cef2a9508e58c460c] # to [aa81112e296118c43d11d34a5988ca388c5d3125] # # patch "cmd_othervcs.cc" # from [daf6234e9e5fa47816ab74830e2de1973fe44712] # to [2dc414d94f7efd36cc5a71f0b39d43bf737dcf5c] # # patch "cmd_packet.cc" # from [ff0d753e667e71cb26fa883ba005bed5925ee092] # to [ff08a7d9d9aa7231b754f8df9265bc1280fd9f5e] # # patch "cmd_ws_commit.cc" # from [981134c77ca685b9872bfffe1814efefb686a7f8] # to [9238e6d8b83227d4b8d9cf5f328cd700343bc8e9] # # patch "commands.cc" # from [b75ca8fe6164c20993fe90c5383ebc888e2eae98] # to [8bea7ece804f39195e7a72a27f7d0d69f7d202a6] # # patch "commands.hh" # from [ca9f64fec576524a9f7ca2cf84c75bb3f6eee05a] # to [b8bbd646e07600a69d6a8a9e04dc45dad3f5c5ba] # # patch "lua_hooks.cc" # from [10b40cfc6a783fb5e80f7221d15a72918e475bcf] # to [62b18336673c9a818e8b90d9920aae58c9b32d07] # # patch "lua_hooks.hh" # from [647093e940b9ce9013f8bd3d3e4660e9018351ba] # to [adaf62d6ed60b08b82bf56f368f2494018e01013] # # patch "monotone.cc" # from [c1d774218a91a191fcd1894c3fc02c9aa0747dcf] # to [6e6729a617c6ebccb3f0a61122850334f521dee6] # # patch "option.cc" # from [599f4f7ffea913627169c06d4130207c3f2d2479] # to [a3a863fb7c8212577e85905ea530e615d126b7ee] # # patch "option.hh" # from [5c956e9f2279ea87311cece08f00c568da8b6be9] # to [f2b79ebaeeffec218059a2682e5fb5273c3ab12a] # # patch "options_list.hh" # from [c232a5b2e9e84041361ba6a81689406db3110d39] # to [c6f757559003724a53598a123eaad448274ecaec] # ============================================================ --- app_state.cc ffe7d555550ba0029a88e3e0fcfdfe99c1a8720b +++ app_state.cc ecc7ff55c4dbe286fe568bda51ca826b8d31e3ac @@ -270,7 +270,7 @@ app_state::load_rcfiles() // Command-line rcfiles override even that. - for (vector::const_iterator i = opts.extra_rcfiles.begin(); + for (args_vector::const_iterator i = opts.extra_rcfiles.begin(); i != opts.extra_rcfiles.end(); ++i) { lua.load_rcfile(*i); ============================================================ --- automate.cc ee573f26aa839258423b024608db769f87f02483 +++ automate.cc eafada922c297d508bb1e327a56c40d539d65e81 @@ -92,7 +92,7 @@ AUTOMATE(ancestors, N_("REV1 [REV2 [REV3 set ancestors; vector frontier; - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (args_vector::const_iterator i = args.begin(); i != args.end(); ++i) { revision_id rid((*i)()); N(app.db.revision_exists(rid), F("No such revision %s") % rid); @@ -139,7 +139,7 @@ AUTOMATE(descendents, N_("REV1 [REV2 [RE set descendents; vector frontier; - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (args_vector::const_iterator i = args.begin(); i != args.end(); ++i) { revision_id rid((*i)()); N(app.db.revision_exists(rid), F("No such revision %s") % rid); @@ -183,7 +183,7 @@ AUTOMATE(erase_ancestors, N_("[REV1 [REV AUTOMATE(erase_ancestors, N_("[REV1 [REV2 [REV3 [...]]]]"), options::opts::none) { set revs; - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (args_vector::const_iterator i = args.begin(); i != args.end(); ++i) { revision_id rid((*i)()); N(app.db.revision_exists(rid), F("No such revision %s") % rid); @@ -329,7 +329,7 @@ AUTOMATE(toposort, N_("[REV1 [REV2 [REV3 AUTOMATE(toposort, N_("[REV1 [REV2 [REV3 [...]]]]"), options::opts::none) { set revs; - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (args_vector::const_iterator i = args.begin(); i != args.end(); ++i) { revision_id rid((*i)()); N(app.db.revision_exists(rid), F("No such revision %s") % rid); @@ -365,7 +365,7 @@ AUTOMATE(ancestry_difference, N_("NEW_RE revision_id a; set bs; - vector::const_iterator i = args.begin(); + args_vector::const_iterator i = args.begin(); a = revision_id((*i)()); N(app.db.revision_exists(a), F("No such revision %s") % a); for (++i; i != args.end(); ++i) @@ -1207,7 +1207,7 @@ AUTOMATE(common_ancestors, N_("REV1 [REV set ancestors, common_ancestors; vector frontier; - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (args_vector::const_iterator i = args.begin(); i != args.end(); ++i) { revision_id rid((*i)()); N(app.db.revision_exists(rid), F("No such revision %s") % rid); ============================================================ --- cmd.hh 5c6809b9a65951b6e69d3bb80ff2d6d42781c511 +++ cmd.hh fc17371af6593442b631faf4d4e35388138a5360 @@ -40,17 +40,17 @@ namespace commands virtual ~command(); virtual std::string params(); virtual std::string desc(); - virtual options::options_type get_options(std::vector const & args); + virtual options::options_type get_options(args_vector const & args); virtual void exec(app_state & app, - std::vector const & args) = 0; + args_vector const & args) = 0; }; }; inline std::vector -args_to_paths(std::vector const & args) +args_to_paths(args_vector const & args) { std::vector paths; - for (std::vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (args_vector::const_iterator i = args.begin(); i != args.end(); ++i) { if (bookkeeping_path::external_string_is_bookkeeping_path(*i)) W(F("ignored bookkeeping path '%s'") % *i); @@ -100,12 +100,12 @@ namespace commands { options::options_type() | opts) \ {} \ virtual void exec(app_state & app, \ - std::vector const & args); \ + args_vector const & args); \ }; \ static cmd_ ## C C ## _cmd; \ } \ void commands::cmd_ ## C::exec(app_state & app, \ - std::vector const & args) + args_vector const & args) // Use this for commands that want to define a params() function // instead of having a static description. (Good for "automate" @@ -118,14 +118,14 @@ namespace commands { options::options_type() | opts) \ {} \ virtual void exec(app_state & app, \ - std::vector const & args); \ + args_vector const & args); \ std::string params(); \ - options::options_type get_options(vector const & args); \ + options::options_type get_options(args_vector const & args); \ }; \ static cmd_ ## C C ## _cmd; \ } \ void commands::cmd_ ## C::exec(app_state & app, \ - std::vector const & args) + args_vector const & args) // Use this for commands that should specifically _not_ look for an // _MTN dir and load options from it. @@ -138,12 +138,12 @@ namespace commands { options::options_type() | opts) \ {} \ virtual void exec(app_state & app, \ - std::vector const & args); \ + args_vector const & args); \ }; \ static cmd_ ## C C ## _cmd; \ } \ void commands::cmd_ ## C::exec(app_state & app, \ - std::vector const & args) \ + args_vector const & args) #define ALIAS(C, realcommand) \ namespace commands { \ @@ -156,7 +156,7 @@ namespace commands { {} \ virtual std::string desc(); \ virtual void exec(app_state & app, \ - std::vector const & args); \ + args_vector const & args); \ }; \ static cmd_ ## C C ## _cmd; \ } \ @@ -168,7 +168,7 @@ void commands::cmd_ ## C::exec(app_state return result; \ } \ void commands::cmd_ ## C::exec(app_state & app, \ - std::vector const & args) \ + args_vector const & args) \ { \ process(app, std::string(#realcommand), args); \ } @@ -181,7 +181,7 @@ namespace automation { options::options_type opts; automate(std::string const & n, std::string const & p, options::options_type const & o); - virtual void run(std::vector args, + virtual void run(args_vector args, std::string const & help_name, app_state & app, std::ostream & output) const = 0; @@ -196,13 +196,13 @@ namespace automation { auto_ ## NAME () \ : automate(#NAME, PARAMS, options::options_type() | OPTIONS) \ {} \ - void run(std::vector args, std::string const & help_name, \ + void run(args_vector args, std::string const & help_name, \ app_state & app, std::ostream & output) const; \ virtual ~auto_ ## NAME() {} \ }; \ static auto_ ## NAME NAME ## _auto; \ } \ -void automation::auto_ ## NAME :: run(std::vector args, \ +void automation::auto_ ## NAME :: run(args_vector args, \ std::string const & help_name,\ app_state & app, \ std::ostream & output) const ============================================================ --- cmd_automate.cc 69aefb502195a4d228f1cc39045ee72d42958b84 +++ cmd_automate.cc 7506aaf4ba90dd26d31ba28574fd12bd0d838daf @@ -42,7 +42,7 @@ automation::automate & } automation::automate & -find_automation(utf8 const & name, string const & root_cmd_name) +find_automation(arg_type const & name, string const & root_cmd_name) { map::const_iterator i = automation::automations->find(name()); @@ -53,7 +53,7 @@ void } void -automate_command(utf8 cmd, vector args, +automate_command(arg_type cmd, args_vector args, string const & root_cmd_name, app_state & app, ostream & output) @@ -341,15 +341,15 @@ AUTOMATE(stdio, "", options::opts::autom vector cmdline; while(ar.get_command(params, cmdline))//while(!EOF) { - utf8 cmd; - vector args; + arg_type cmd; + args_vector args; vector::iterator i = cmdline.begin(); E(i != cmdline.end(), F("Bad input to automate stdio: command name is missing")); - cmd = utf8(*i); + cmd = arg_type(*i); for (++i; i != cmdline.end(); ++i) { - args.push_back(utf8(*i)); + args.push_back(arg_type(*i)); } try { @@ -381,10 +381,10 @@ CMD_WITH_SUBCMDS(automate, N_("automatio if (args.size() == 0) throw usage(name); - vector::const_iterator i = args.begin(); - utf8 cmd = *i; + args_vector::const_iterator i = args.begin(); + arg_type cmd = *i; ++i; - vector cmd_args(i, args.end()); + args_vector cmd_args(i, args.end()); make_io_binary(); @@ -406,7 +406,7 @@ options::options_type } options::options_type -commands::cmd_automate::get_options(vector const & args) +commands::cmd_automate::get_options(args_vector const & args) { if (args.size() < 2) return options::options_type(); ============================================================ --- cmd_diff_log.cc 1b7f8c23e25beaa81669eefb504de8315b7fbd4d +++ cmd_diff_log.cc 0d01fb3a1b4c83bbd1384519f8c10b1a34acfcb5 @@ -338,7 +338,7 @@ prepare_diff(cset & included, static void prepare_diff(cset & included, app_state & app, - std::vector args, + args_vector args, bool & new_is_archived, std::string & revheader) { @@ -632,7 +632,7 @@ CMD(log, N_("informative"), N_("[FILE] . } else { - for (vector::const_iterator i = app.opts.from.begin(); + for (args_vector::const_iterator i = app.opts.from.begin(); i != app.opts.from.end(); i++) { set rids; @@ -686,7 +686,7 @@ CMD(log, N_("informative"), N_("[FILE] . if (use_disallowed) { std::deque to; - for (vector::const_iterator i = app.opts.to.begin(); + for (args_vector::const_iterator i = app.opts.to.begin(); i != app.opts.to.end(); i++) { MM(*i); ============================================================ --- cmd_list.cc 0ff9de55b90f18b284382b82ebfd43b405567a41 +++ cmd_list.cc 0c16e7edb207dfbae0dd6ee15c7a726e250aae11 @@ -40,7 +40,7 @@ static void using std::vector; static void -ls_certs(string const & name, app_state & app, vector const & args) +ls_certs(string const & name, app_state & app, args_vector const & args) { if (args.size() != 1) throw usage(name); @@ -142,7 +142,7 @@ ls_keys(string const & name, app_state & static void ls_keys(string const & name, app_state & app, - vector const & args) + args_vector const & args) { vector pubs; vector privkeys; @@ -234,7 +234,7 @@ static void } static void -ls_branches(string name, app_state & app, vector const & args) +ls_branches(string name, app_state & app, args_vector const & args) { globish inc("*"); globish exc; @@ -260,7 +260,7 @@ static void } static void -ls_epochs(string name, app_state & app, vector const & args) +ls_epochs(string name, app_state & app, args_vector const & args) { map epochs; app.db.get_epochs(epochs); @@ -276,7 +276,7 @@ ls_epochs(string name, app_state & app, } else { - for (vector::const_iterator i = args.begin(); + for (args_vector::const_iterator i = args.begin(); i != args.end(); ++i) { @@ -288,7 +288,7 @@ static void } static void -ls_tags(string name, app_state & app, vector const & args) +ls_tags(string name, app_state & app, args_vector const & args) { set tags; app.get_project().get_tags(tags); @@ -302,7 +302,7 @@ static void } static void -ls_vars(string name, app_state & app, vector const & args) +ls_vars(string name, app_state & app, args_vector const & args) { bool filterp; var_domain filter; @@ -334,7 +334,7 @@ static void } static void -ls_known(app_state & app, vector const & args) +ls_known(app_state & app, args_vector const & args) { roster_t new_roster; temp_node_id_source nis; @@ -375,7 +375,7 @@ ls_unknown_or_ignored(app_state & app, b static void ls_unknown_or_ignored(app_state & app, bool want_ignored, - vector const & args) + args_vector const & args) { app.require_workspace(); @@ -401,7 +401,7 @@ static void } static void -ls_missing(app_state & app, vector const & args) +ls_missing(app_state & app, args_vector const & args) { temp_node_id_source nis; roster_t current_roster_shape; @@ -423,7 +423,7 @@ static void static void -ls_changed(app_state & app, vector const & args) +ls_changed(app_state & app, args_vector const & args) { parent_map parents; roster_t new_roster; @@ -497,9 +497,9 @@ CMD(list, N_("informative"), if (args.size() == 0) throw usage(name); - vector::const_iterator i = args.begin(); + args_vector::const_iterator i = args.begin(); ++i; - vector removed (i, args.end()); + args_vector removed(i, args.end()); if (idx(args, 0)() == "certs") ls_certs(name, app, removed); else if (idx(args, 0)() == "keys") ============================================================ --- cmd_merging.cc af61f02853172ea7a6c53cee6579c0220766d53d +++ cmd_merging.cc 224a6b50161b9a26ae50652692b83a436911704d @@ -434,8 +434,8 @@ CMD(propagate, N_("tree"), N_("SOURCE-BR { if (args.size() != 2) throw usage(name); - vector a = args; - a.push_back(utf8()); + args_vector a = args; + a.push_back(arg_type()); process(app, "merge_into_dir", a); } ============================================================ --- cmd_netsync.cc 85389e376de990a6beb16c7cef2a9508e58c460c +++ cmd_netsync.cc aa81112e296118c43d11d34a5988ca388c5d3125 @@ -31,8 +31,8 @@ static void static string const ws_internal_db_file_name("mtn.db"); static void -extract_address(vector const & args, - utf8 & addr, +extract_address(args_vector const & args, + arg_type & addr, app_state & app) { if (args.size() >= 1) @@ -40,7 +40,7 @@ extract_address(vector const & arg addr = idx(args, 0); if (!app.db.var_exists(default_server_key) || app.opts.set_default) { - P(F("setting default server to %s") % addr); + P(F("setting default server to %s") % addr()); app.db.set_var(default_server_key, var_value(addr())); } } @@ -50,8 +50,8 @@ extract_address(vector const & arg F("no server given and no default server set")); var_value addr_value; app.db.get_var(default_server_key, addr_value); - addr = utf8(addr_value()); - L(FL("using default server address: %s") % addr); + addr = arg_type(addr_value()); + L(FL("using default server address: %s") % addr()); } } @@ -73,7 +73,7 @@ static void } static void -extract_patterns(vector const & args, +extract_patterns(args_vector const & args, globish & include_pattern, globish & exclude_pattern, app_state & app) { @@ -126,7 +126,7 @@ CMD(push, N_("network"), N_("[ADDRESS[:P options::opts::set_default | options::opts::exclude | options::opts::key_to_push) { - utf8 addr; + arg_type addr; globish include_pattern, exclude_pattern; extract_address(args, addr, app); find_key_if_needed(addr, app); @@ -140,7 +140,7 @@ CMD(pull, N_("network"), N_("[ADDRESS[:P N_("pull branches matching PATTERN from netsync server at ADDRESS"), options::opts::set_default | options::opts::exclude) { - utf8 addr; + arg_type addr; globish include_pattern, exclude_pattern; extract_address(args, addr, app); extract_patterns(args, include_pattern, exclude_pattern, app); @@ -157,7 +157,7 @@ CMD(sync, N_("network"), N_("[ADDRESS[:P options::opts::set_default | options::opts::exclude | options::opts::key_to_push) { - utf8 addr; + arg_type addr; globish include_pattern, exclude_pattern; extract_address(args, addr, app); find_key_if_needed(addr, app); ============================================================ --- cmd_othervcs.cc daf6234e9e5fa47816ab74830e2de1973fe44712 +++ cmd_othervcs.cc 2dc414d94f7efd36cc5a71f0b39d43bf737dcf5c @@ -22,7 +22,7 @@ CMD(rcs_import, N_("debug"), N_("RCSFILE if (args.size() < 1) throw usage(name); - for (vector::const_iterator i = args.begin(); + for (args_vector::const_iterator i = args.begin(); i != args.end(); ++i) { test_parse_rcs_file(system_path((*i)()), app.db); ============================================================ --- cmd_packet.cc ff0d753e667e71cb26fa883ba005bed5925ee092 +++ cmd_packet.cc ff08a7d9d9aa7231b754f8df9265bc1280fd9f5e @@ -141,7 +141,7 @@ CMD(read, N_("packet i/o"), "[FILE1 [FIL } else { - for (vector::const_iterator i = args.begin(); + for (args_vector::const_iterator i = args.begin(); i != args.end(); ++i) { data dat; ============================================================ --- cmd_ws_commit.cc 981134c77ca685b9872bfffe1814efefb686a7f8 +++ cmd_ws_commit.cc 9238e6d8b83227d4b8d9cf5f328cd700343bc8e9 @@ -274,7 +274,7 @@ CMD(mkdir, N_("workspace"), N_("[DIRECTO //spin through args and try to ensure that we won't have any collisions //before doing any real filesystem modification. we'll also verify paths //against .mtn-ignore here. - for (vector::const_iterator i = args.begin(); + for (args_vector::const_iterator i = args.begin(); i != args.end(); ++i) { split_path sp; @@ -1031,11 +1031,11 @@ CMD_NO_WORKSPACE(import, N_("tree"), N_( // prepare stuff for 'add' and so on. app.found_workspace = true; // Yup, this is cheating! - vector empty_args; + args_vector empty_args; options save_opts; // add --unknown save_opts.exclude_patterns = app.opts.exclude_patterns; - app.opts.exclude_patterns = std::vector(); + app.opts.exclude_patterns = args_vector(); app.opts.unknown = true; app.opts.recursive = true; process(app, "add", empty_args); ============================================================ --- commands.cc b75ca8fe6164c20993fe90c5383ebc888e2eae98 +++ commands.cc 8bea7ece804f39195e7a72a27f7d0d69f7d202a6 @@ -81,7 +81,7 @@ namespace commands command::~command() {} std::string command::params() {return safe_gettext(params_.c_str());} std::string command::desc() {return safe_gettext(desc_.c_str());} - options::options_type command::get_options(vector const & args) + options::options_type command::get_options(args_vector const & args) { return opts; } @@ -231,7 +231,7 @@ namespace commands out << "\n\n"; } - int process(app_state & app, string const & cmd, vector const & args) + int process(app_state & app, string const & cmd, args_vector const & args) { if ((*cmds).find(cmd) != (*cmds).end()) { @@ -252,7 +252,7 @@ namespace commands } } - options::options_type command_options(vector const & cmdline) + options::options_type command_options(args_vector const & cmdline) { if (cmdline.empty()) return options::options_type(); ============================================================ --- commands.hh ca9f64fec576524a9f7ca2cf84c75bb3f6eee05a +++ commands.hh b8bbd646e07600a69d6a8a9e04dc45dad3f5c5ba @@ -30,8 +30,8 @@ namespace commands { void explain_usage(std::string const & cmd, std::ostream & out); std::string complete_command(std::string const & cmd); int process(app_state & app, std::string const & cmd, - std::vector const & args); - options::options_type command_options(std::vector const & cmdline); + args_vector const & args); + options::options_type command_options(args_vector const & cmdline); options::options_type toplevel_command_options(std::string const & cmd); }; ============================================================ --- lua_hooks.cc 10b40cfc6a783fb5e80f7221d15a72918e475bcf +++ lua_hooks.cc 62b18336673c9a818e8b90d9920aae58c9b32d07 @@ -918,15 +918,15 @@ bool } bool -lua_hooks::hook_note_mtn_startup(vector const & args) +lua_hooks::hook_note_mtn_startup(args_vector const & args) { Lua ll(st); ll.func("note_mtn_startup"); int n=0; - for (vector::const_iterator i = args.begin(); i != args.end(); ++i, ++n) - ll.push_str(*i); + for (args_vector::const_iterator i = args.begin(); i != args.end(); ++i, ++n) + ll.push_str((*i)()); ll.call(n, 0); return ll.ok(); ============================================================ --- lua_hooks.hh 647093e940b9ce9013f8bd3d3e4660e9018351ba +++ lua_hooks.hh adaf62d6ed60b08b82bf56f368f2494018e01013 @@ -17,6 +17,7 @@ #include #include #include "file_io.hh" +#include "option.hh" #include "vocab.hh" #include "paths.hh" @@ -149,7 +150,7 @@ public: size_t certs_in, size_t certs_out, size_t revs_in, size_t revs_out, size_t keys_in, size_t keys_out); - bool hook_note_mtn_startup(std::vector const & args); + bool hook_note_mtn_startup(args_vector const & args); }; // Local Variables: ============================================================ --- monotone.cc c1d774218a91a191fcd1894c3fc02c9aa0747dcf +++ monotone.cc 6e6729a617c6ebccb3f0a61122850334f521dee6 @@ -125,7 +125,7 @@ void localize_monotone() } // read command-line options and return the command name -string read_options(options & opts, vector args) +string read_options(options & opts, args_vector args) { option::concrete_option_set optset = options::opts::all_options().instantiate(&opts); @@ -179,13 +179,13 @@ cpp_main(int argc, char ** argv) save_initial_path(); // decode all argv values into a UTF-8 array - vector args; + args_vector args; for (int i = 1; i < argc; ++i) { external ex(argv[i]); utf8 ut; system_to_utf8(ex, ut); - args.push_back(ut()); + args.push_back(arg_type(ut)); } // find base name of executable, convert to utf8, and save it in the @@ -256,8 +256,7 @@ cpp_main(int argc, char ** argv) } else { - vector args(app.opts.args.begin(), app.opts.args.end()); - return commands::process(app, cmd, args); + return commands::process(app, cmd, app.opts.args); } } catch (option::option_error const & e) ============================================================ --- option.cc 599f4f7ffea913627169c06d4130207c3f2d2479 +++ option.cc a3a863fb7c8212577e85905ea530e615d126b7ee @@ -28,15 +28,15 @@ extra_arg::extra_arg(std::string const & : option_error((F("option '%s' does not take an argument") % opt).str()) {} -bad_arg::bad_arg(std::string const & opt, std::string const & arg) - : option_error((F("bad argument '%s' to option '%s'") % arg % opt).str()) +bad_arg::bad_arg(std::string const & opt, arg_type const & arg) + : option_error((F("bad argument '%s' to option '%s'") % arg() % opt).str()) {} bad_arg::bad_arg(std::string const & opt, - std::string const & arg, + arg_type const & arg, std::string const & reason) : option_error((F("bad argument '%s' to option '%s': %s") - % arg % opt % reason).str()) + % arg() % opt % reason).str()) {} bad_arg_internal::bad_arg_internal(string const & str) @@ -166,7 +166,7 @@ static void } static void -tokenize_for_command_line(string const & from, vector & to) +tokenize_for_command_line(string const & from, args_vector & to) { // Unfortunately, the tokenizer in basic_io is too format-specific to.clear(); @@ -214,7 +214,7 @@ tokenize_for_command_line(string const & if (type == none) { if (have_tok) - to.push_back(cur); + to.push_back(arg_type(cur)); cur.clear(); have_tok = false; } @@ -231,14 +231,14 @@ tokenize_for_command_line(string const & } } if (have_tok) - to.push_back(cur); + to.push_back(arg_type(cur)); } void concrete_option_set::from_command_line(int argc, char const * const * argv) { - vector arguments; + args_vector arguments; for (int i = 1; i < argc; ++i) - arguments.push_back(argv[i]); + arguments.push_back(arg_type(argv[i])); from_command_line(arguments, true); } @@ -267,7 +267,7 @@ get_by_name(std::set co return by_name; } -void concrete_option_set::from_command_line(std::vector & args, +void concrete_option_set::from_command_line(args_vector & args, bool allow_xargs) { map by_name = get_by_name(options); @@ -276,9 +276,10 @@ void concrete_option_set::from_command_l for (unsigned int i = 0; i < args.size(); ++i) { concrete_option o; - string name, arg; + string name; + arg_type arg; bool separate_arg(false); - if (idx(args,i) == "--" || seen_dashdash) + if (idx(args,i)() == "--" || seen_dashdash) { if (!seen_dashdash) { @@ -290,13 +291,13 @@ void concrete_option_set::from_command_l o = getopt(by_name, name); arg = idx(args,i); } - else if (idx(args,i).substr(0,2) == "--") + else if (idx(args,i)().substr(0,2) == "--") { - string::size_type equals = idx(args,i).find('='); + string::size_type equals = idx(args,i)().find('='); if (equals == string::npos) - name = idx(args,i).substr(2); + name = idx(args,i)().substr(2); else - name = idx(args,i).substr(2, equals-2); + name = idx(args,i)().substr(2, equals-2); o = getopt(by_name, name); if (!o.has_arg && equals != string::npos) @@ -312,20 +313,20 @@ void concrete_option_set::from_command_l arg = idx(args,i+1); } else - arg = idx(args,i).substr(equals+1); + arg = arg_type(idx(args,i)().substr(equals+1)); } } - else if (idx(args,i).substr(0,1) == "-") + else if (idx(args,i)().substr(0,1) == "-") { - name = idx(args,i).substr(1,1); + name = idx(args,i)().substr(1,1); o = getopt(by_name, name); - if (!o.has_arg && idx(args,i).size() != 2) + if (!o.has_arg && idx(args,i)().size() != 2) throw extra_arg(name); if (o.has_arg) { - if (idx(args,i).size() == 2) + if (idx(args,i)().size() == 2) { separate_arg = true; if (i+1 == args.size()) @@ -333,7 +334,7 @@ void concrete_option_set::from_command_l arg = idx(args,i+1); } else - arg = idx(args,i).substr(2); + arg = arg_type(idx(args,i)().substr(2)); } } else @@ -347,8 +348,8 @@ void concrete_option_set::from_command_l { // expand the --xargs in place data dat; - read_data_for_command_line(utf8(arg), dat); - vector fargs; + read_data_for_command_line(arg, dat); + args_vector fargs; tokenize_for_command_line(dat(), fargs); args.erase(args.begin() + i); @@ -364,7 +365,7 @@ void concrete_option_set::from_command_l try { if (o.setter) - o.setter(arg); + o.setter(arg()); } catch (boost::bad_lexical_cast) { @@ -389,14 +390,14 @@ void concrete_option_set::from_key_value i != keyvals.end(); ++i) { string const & key(i->first); - string const & value(i->second); + arg_type const & value(arg_type(i->second)); concrete_option o = getopt(by_name, key); try { if (o.setter) - o.setter(value); + o.setter(value()); } catch (boost::bad_lexical_cast) { @@ -533,11 +534,11 @@ UNIT_TEST(option, concrete_options) BOOST_CHECK(v.empty()); { - vector cmdline; - cmdline.push_back("--bool"); - cmdline.push_back("-s"); - cmdline.push_back("-s"); - cmdline.push_back("foo"); + args_vector cmdline; + cmdline.push_back(arg_type("--bool")); + cmdline.push_back(arg_type("-s")); + cmdline.push_back(arg_type("-s")); + cmdline.push_back(arg_type("foo")); os.from_command_line(cmdline); } BOOST_CHECK(b); ============================================================ --- option.hh 5c956e9f2279ea87311cece08f00c568da8b6be9 +++ option.hh f2b79ebaeeffec218059a2682e5fb5273c3ab12a @@ -11,7 +11,19 @@ #include #include "sanity.hh" +#include "vocab.hh" +// The types to represent the command line's parameters. +class arg_type : public utf8 { +public: + explicit arg_type(void) : utf8() {} + explicit arg_type(std::string const & s) : utf8(s) {} + explicit arg_type(utf8 const & u) : utf8(u) {} +}; +template <> +inline void dump(arg_type const & a, std::string & out) { out = a(); } +typedef std::vector< arg_type > args_vector; + namespace option { // Base for errors thrown by this code. struct option_error : public std::invalid_argument @@ -35,9 +47,9 @@ namespace option { // by either boost::bad_lexical_cast or bad_arg_internal struct bad_arg : public option_error { - bad_arg(std::string const & opt, std::string const & arg); + bad_arg(std::string const & opt, arg_type const & arg); bad_arg(std::string const & opt, - std::string const & arg, + arg_type const & arg, std::string const & reason); }; // from_command_line() catches this and boost::bad_lexical_cast @@ -96,7 +108,7 @@ namespace option { concrete_option_set operator | (concrete_option_set const & other) const; void reset() const; std::string get_usage_str() const; - void from_command_line(std::vector & args, bool allow_xargs = true); + void from_command_line(args_vector & args, bool allow_xargs = true); void from_command_line(int argc, char const * const * argv); void from_key_value_pairs(std::vector > const & keyvals); }; ============================================================ --- options_list.hh c232a5b2e9e84041361ba6a81689406db3110d39 +++ options_list.hh c6f757559003724a53598a123eaad448274ecaec @@ -8,11 +8,11 @@ OPTSET(globals) OPTSET(globals) -OPTVAR(globals, std::vector, args, ) +OPTVAR(globals, args_vector, args, ) OPTION(globals, positionals, true, "--", "") #ifdef option_bodies { - args.push_back(utf8(arg)); + args.push_back(arg_type(arg)); } #endif @@ -233,12 +233,12 @@ OPTION(globals, dump, true, "dump", } #endif -OPTVAR(exclude, std::vector, exclude_patterns, ) +OPTVAR(exclude, args_vector, exclude_patterns, ) OPTION(exclude, exclude, true, "exclude", gettext_noop("leave out anything described by its argument")) #ifdef option_bodies { - exclude_patterns.push_back(utf8(arg)); + exclude_patterns.push_back(arg_type(arg)); } #endif @@ -273,12 +273,12 @@ GOPT(help, "help,h", bool, false, gettex } #endif -OPTVAR(include, std::vector, include_patterns, ) +OPTVAR(include, args_vector, include_patterns, ) OPTION(include, include, true, "include", gettext_noop("include anything described by its argument")) #ifdef option_bodies { - include_patterns.push_back(utf8(arg)); + include_patterns.push_back(arg_type(arg)); } #endif @@ -428,11 +428,11 @@ GOPT(quiet, "quiet", bool, false, } #endif -GOPT(extra_rcfiles, "rcfile", std::vector, , +GOPT(extra_rcfiles, "rcfile", args_vector, , gettext_noop("load extra rc file")) #ifdef option_bodies { - extra_rcfiles.push_back(utf8(arg)); + extra_rcfiles.push_back(arg_type(arg)); } #endif @@ -454,12 +454,12 @@ OPT(recursive, "recursive,R", bool, fals } #endif -OPTVAR(revision, std::vector, revision_selectors, ) +OPTVAR(revision, args_vector, revision_selectors, ) OPTION(revision, revision, true, "revision,r", gettext_noop("select revision id for operation")) #ifdef option_bodies { - revision_selectors.push_back(utf8(arg)); + revision_selectors.push_back(arg_type(arg)); } #endif @@ -495,17 +495,17 @@ GOPT(ticker, "ticker", std::string, , } #endif -OPT(from, "from", std::vector, , gettext_noop("revision(s) to start logging at")) +OPT(from, "from", args_vector, , gettext_noop("revision(s) to start logging at")) #ifdef option_bodies { - from.push_back(utf8(arg)); + from.push_back(arg_type(arg)); } #endif -OPT(to, "to", std::vector, , gettext_noop("revision(s) to stop logging at")) +OPT(to, "to", args_vector, , gettext_noop("revision(s) to stop logging at")) #ifdef option_bodies { - to.push_back(utf8(arg)); + to.push_back(arg_type(arg)); } #endif