# # add_file "tests/t_set_default.at" # # patch "ChangeLog" # from [c2fc356cdd5b7eab95ae345c04e45ece26d2adb3] # to [4cba7d28463e719bd4539506b9c74dda5b3fa4dd] # # patch "app_state.cc" # from [d4bde5580532bd066167f9ece19ac0410398fdde] # to [9c37128fc8af7ad8bb4f5327dee434b430af4323] # # patch "app_state.hh" # from [ba2b8d968ce1eabe69b2c7fb60a7c666cfa4ada7] # to [2e07ee9fa9f8a9b3e25c4956cc998e63fd346dbd] # # patch "commands.cc" # from [d155ea587e6ee57f7057e497579cf08a4882fb8c] # to [63e8fe8b10f79c4800d9ff1a0b298d486a99f75b] # # patch "monotone.cc" # from [21b832dddae51e882d8df1c744b159f1a7642c22] # to [edc6e4d96379486380caa5fe383a857378b2be4e] # # patch "monotone.texi" # from [344377efb15388541a16b1b453eefe80eff1a7a2] # to [8af73572851f7411e064aab907c3d296ce4d4191] # # patch "options.hh" # from [bb33c449ff288021098ac00c045e862806e42b9f] # to [8c52cb173884c36f1427b428f26817806be57a26] # # patch "tests/t_set_default.at" # from [] # to [95505520a46b66a6120dae44779dbb01f16fdafb] # # patch "testsuite.at" # from [4cbb082cf10749231aaffa05b12dfdd51e8e2096] # to [a25816f59fe97b9948421613a85948bc25282fd2] # --- ChangeLog +++ ChangeLog @@ -1,3 +1,12 @@ +2005-07-06 Nathaniel Smith + + * options.hh (OPT_SET_DEFAULT): + * app_state.{hh,cc} (app_state::set_default): + * monotone.cc (coptions, cpp_main): New option. + * commands.cc (pull, push, sync): Accept it. + (process_netsync_args): Use it. + * tests/t_set_default.at, testsuite.at: New test. + 2005-07-05 Nathaniel Smith * debian/rules (config.status): Use bundled sqlite. --- app_state.cc +++ app_state.cc @@ -33,7 +33,8 @@ app_state::app_state() : branch_name(""), db(""), stdhooks(true), rcfiles(true), diffs(false), - no_merges(false), verbose(false), search_root("/"), depth(-1), last(-1) + no_merges(false), set_default(false), verbose(false), search_root("/"), + depth(-1), last(-1) { db.set_app(this); } --- app_state.hh +++ app_state.hh @@ -33,6 +33,7 @@ bool rcfiles; bool diffs; bool no_merges; + bool set_default; bool verbose; options_map options; utf8 message; --- commands.cc +++ commands.cc @@ -1993,7 +1993,8 @@ if (args.size() >= 1) { addr = idx(args, 0); - if (use_defaults && !app.db.var_exists(default_server_key)) + if (use_defaults + && (!app.db.var_exists(default_server_key) || app.set_default)) { P(F("setting default server to %s\n") % addr); app.db.set_var(default_server_key, var_value(addr())); @@ -2013,7 +2014,8 @@ { std::set patterns(args.begin() + 1, args.end()); combine_and_check_globish(patterns, include_pattern); - if (use_defaults && !app.db.var_exists(default_include_pattern_key)) + if (use_defaults && + (!app.db.var_exists(default_include_pattern_key) || app.set_default)) { P(F("setting default branch pattern to %s\n") % include_pattern); app.db.set_var(default_include_pattern_key, var_value(include_pattern())); @@ -2035,7 +2037,7 @@ } CMD(push, "network", "[ADDRESS[:PORTNUMBER] [PATTERN]]", - "push branches matching REGEX to netsync server at ADDRESS", OPT_NONE) + "push branches matching REGEX to netsync server at ADDRESS", OPT_SET_DEFAULT) { utf8 addr, include_pattern, exclude_pattern; process_netsync_args(name, args, addr, include_pattern, exclude_pattern, true, app); @@ -2049,7 +2051,7 @@ } CMD(pull, "network", "[ADDRESS[:PORTNUMBER] [PATTERN]]", - "pull branches matching REGEX from netsync server at ADDRESS", OPT_NONE) + "pull branches matching REGEX from netsync server at ADDRESS", OPT_SET_DEFAULT) { utf8 addr, include_pattern, exclude_pattern; process_netsync_args(name, args, addr, include_pattern, exclude_pattern, true, app); @@ -2062,7 +2064,7 @@ } CMD(sync, "network", "[ADDRESS[:PORTNUMBER] [PATTERN]]", - "sync branches matching REGEX with netsync server at ADDRESS", OPT_NONE) + "sync branches matching REGEX with netsync server at ADDRESS", OPT_SET_DEFAULT) { utf8 addr, include_pattern, exclude_pattern; process_netsync_args(name, args, addr, include_pattern, exclude_pattern, true, app); --- monotone.cc +++ monotone.cc @@ -57,6 +57,7 @@ {"brief", 0, POPT_ARG_NONE, NULL, OPT_BRIEF, "print a brief version of the normal output", NULL}, {"diffs", 0, POPT_ARG_NONE, NULL, OPT_DIFFS, "print diffs along with logs", NULL}, {"no-merges", 0, POPT_ARG_NONE, NULL, OPT_NO_MERGES, "skip merges when printing logs", NULL}, + {"set-default", 0, POPT_ARG_NONE, NULL, OPT_SET_DEFAULT, "use the current arguments as the future default", NULL}, { NULL, 0, 0, NULL, 0, NULL, NULL } }; @@ -389,6 +390,10 @@ app.no_merges = true; break; + case OPT_SET_DEFAULT: + app.set_default = true; + break; + case OPT_PIDFILE: app.set_pidfile(absolutify(tilde_expand(string(argstr)))); break; --- monotone.texi +++ monotone.texi @@ -3656,9 +3656,9 @@ @ftable @command @item monotone serve @var{address}[:@var{port}] @var{glob} [...] address@hidden monotone pull address@hidden:@var{port}] address@hidden [...]]] address@hidden monotone push address@hidden:@var{port}] address@hidden [...]]] address@hidden monotone sync address@hidden:@var{port}] address@hidden [...]]] address@hidden monotone pull [--set-default] address@hidden:@var{port}] address@hidden [...]]] address@hidden monotone push [--set-default] address@hidden:@var{port}] address@hidden [...]]] address@hidden monotone sync [--set-default] address@hidden:@var{port}] address@hidden [...]]] These commands operate the ``netsync'' protocol built into monotone. This is a custom protocol for rapidly synchronizing two @@ -3717,10 +3717,9 @@ Of course, he can still @command{sync} with other people and other branches by passing an address or address plus globs on the command line; this will not affect his default affinity for Alice. If you ever -do want to change your defaults, use @code{monotone unset database -default-server} or @code{monotone unset database -default-include-pattern}; these will clear your defaults, and cause them -to be reset to the next person you netsync with. +do want to change your defaults, simply pass the @option{--set-default} +option when connecting to the server and branch pattern that you want to +make the new default. If a @option{--pid-file} option is specified, the command @command{serve} will create the specified file and record the process --- options.hh +++ options.hh @@ -35,3 +35,4 @@ #define OPT_NO_MERGES 26 #define OPT_LAST 27 #define OPT_VERBOSE 28 +#define OPT_SET_DEFAULT 29 --- tests/t_set_default.at +++ tests/t_set_default.at @@ -0,0 +1,44 @@ +AT_SETUP([--set-default]) +AT_KEYWORDS(netsync) +MONOTONE_SETUP +NETSYNC_SETUP + +ADD_FILE(testfile, [foo +]) +COMMIT(testbranch) +T1=`BASE_REVISION` + +# set defaults in db 2 +RUN_NETSYNC(pull, testbranch) +AT_CHECK(MONOTONE2 cat revision $T1, [], [ignore], [ignore]) + +SET_FILE(testfile, [blah blah +]) +COMMIT(testbranch) +T2=`BASE_REVISION` + +# make sure the defaults really were set to 'testbranch' +NETSYNC_SERVE_START(testbranch) +AT_CHECK(MONOTONE2 pull, [], [ignore], [ignore]) +NETSYNC_SERVE_STOP +AT_CHECK(MONOTONE2 cat revision $T2, [], [ignore], [ignore]) + +# do a --set-default pull of another branch +NETSYNC_SERVE_START(otherbranch) +AT_CHECK(MONOTONE2 --set-default pull localhost:$_PORT otherbranch, [], [ignore], [ignore]) +NETSYNC_SERVE_STOP + +# create a new revision on that branch +SET_FILE(testfile, [other1 +]) +COMMIT(otherbranch) +O1=`BASE_REVISION` + +# and make sure that our default is now it +NETSYNC_SERVE_START(otherbranch) +AT_CHECK(MONOTONE2 pull, [], [ignore], [ignore]) +NETSYNC_SERVE_STOP + +AT_CHECK(MONOTONE2 cat revision $O1, [], [ignore], [ignore]) + +AT_CLEANUP --- testsuite.at +++ testsuite.at @@ -665,3 +665,4 @@ m4_include(tests/t_existsonpath.at) m4_include(tests/t_db_kill_branch_locally.at) m4_include(tests/t_netsync_globs.at) +m4_include(tests/t_set_default.at)