# # patch "ChangeLog" # from [d6117311bb0a53d044ff16bc5dd2694080dc41d3] # to [903334a73c0c015e1ce5b9a51c8a2304a8c330e6] # # patch "commands.cc" # from [48d30d4a94c85c3495de55cc06f7bdbb6347337b] # to [c20f279625ddbfae2957ccfa54961b85a68318fc] # --- ChangeLog +++ ChangeLog @@ -1,3 +1,10 @@ +2005-04-30 Nathaniel Smith + + * commands.cc: Add a placeholder OPT_NONE for commands that don't + take any command-specific options; use it everywhere. Now the + last argument to CMD never starts with %, and the last argument is + always required to be present. + 2005-04-30 Richard Levitte * contrib/monotone-nav.el (mnav-rev-make): Move it so it's defined --- commands.cc +++ commands.cc @@ -84,12 +84,16 @@ static map cmds; + struct no_opts {}; + struct command_opts { set opts; command_opts() {} command_opts & operator%(int o) { opts.insert(o); return *this; } + command_opts & operator%(no_opts o) + { return *this; } command_opts & operator%(command_opts const &o) { opts.insert(o.opts.begin(), o.opts.end()); return *this; } }; @@ -253,11 +257,13 @@ } } +static const no_opts OPT_NONE = no_opts(); + #define CMD(C, group, params, desc, opts) \ struct cmd_ ## C : public command \ { \ cmd_ ## C() : command(#C, group, params, desc, \ - command_opts() opts) \ + command_opts() % opts) \ {} \ virtual void exec(app_state & app, \ vector const & args); \ @@ -269,7 +275,7 @@ #define ALIAS(C, realcommand) \ CMD(C, realcommand##_cmd.cmdgroup, realcommand##_cmd.params, \ realcommand##_cmd.desc + "\nAlias for " #realcommand, \ - % realcommand##_cmd.options) \ + realcommand##_cmd.options) \ { \ process(app, string(#realcommand), args); \ } @@ -1008,7 +1014,7 @@ #undef PRINT_INDENTED_SET } -CMD(genkey, "key and cert", "KEYID", "generate an RSA key-pair",) +CMD(genkey, "key and cert", "KEYID", "generate an RSA key-pair", OPT_NONE) { if (args.size() != 1) throw usage(name); @@ -1030,7 +1036,7 @@ guard.commit(); } -CMD(dropkey, "key and cert", "KEYID", "drop a public and private key",) +CMD(dropkey, "key and cert", "KEYID", "drop a public and private key", OPT_NONE) { bool key_deleted = false; @@ -1063,7 +1069,7 @@ } CMD(chkeypass, "key and cert", "KEYID", "change passphrase of a private RSA key", - ) + OPT_NONE) { if (args.size() != 1) throw usage(name); @@ -1086,7 +1092,7 @@ } CMD(cert, "key and cert", "REVISION CERTNAME [CERTVAL]", - "create a cert for a revision",) + "create a cert for a revision", OPT_NONE) { if ((args.size() != 3) && (args.size() != 2)) throw usage(name); @@ -1127,7 +1133,7 @@ CMD(trusted, "key and cert", "REVISION NAME VALUE SIGNER1 [SIGNER2 [...]]", "test whether a hypothetical cert would be trusted\n" - "by current settings",) + "by current settings", OPT_NONE) { if (args.size() < 4) throw usage(name); @@ -1164,7 +1170,7 @@ } CMD(tag, "review", "REVISION TAGNAME", - "put a symbolic tag cert on a revision version",) + "put a symbolic tag cert on a revision version", OPT_NONE) { if (args.size() != 2) throw usage(name); @@ -1177,7 +1183,7 @@ CMD(testresult, "review", "ID (pass|fail|true|false|yes|no|1|0)", - "note the results of running a test on a revision",) + "note the results of running a test on a revision", OPT_NONE) { if (args.size() != 2) throw usage(name); @@ -1190,7 +1196,7 @@ CMD(approve, "review", "REVISION", "approve of a particular revision", - % OPT_BRANCH_NAME) + OPT_BRANCH_NAME) { if (args.size() != 1) throw usage(name); @@ -1207,7 +1213,7 @@ CMD(disapprove, "review", "REVISION", "disapprove of a particular revision", - % OPT_BRANCH_NAME) + OPT_BRANCH_NAME) { if (args.size() != 1) throw usage(name); @@ -1252,7 +1258,7 @@ } CMD(comment, "review", "REVISION [COMMENT]", - "comment on a particular revision",) + "comment on a particular revision", OPT_NONE) { if (args.size() != 1 && args.size() != 2) throw usage(name); @@ -1275,7 +1281,7 @@ -CMD(add, "working copy", "PATH...", "add files to working copy",) +CMD(add, "working copy", "PATH...", "add files to working copy", OPT_NONE) { if (args.size() < 1) throw usage(name); @@ -1299,7 +1305,7 @@ update_any_attrs(app); } -CMD(drop, "working copy", "PATH...", "drop files from working copy",) +CMD(drop, "working copy", "PATH...", "drop files from working copy", OPT_NONE) { if (args.size() < 1) throw usage(name); @@ -1324,7 +1330,8 @@ } -CMD(rename, "working copy", "SRC DST", "rename entries in the working copy",) +CMD(rename, "working copy", "SRC DST", "rename entries in the working copy", + OPT_NONE) { if (args.size() != 2) throw usage(name); @@ -1350,7 +1357,7 @@ // (such as automated processes might want to do). CMD(fcommit, "tree", "REVISION FILENAME [LOG_MESSAGE]", - "commit change to a single file",) + "commit change to a single file", OPT_NONE) { if (args.size() != 2 && args.size() != 3) throw usage(name); @@ -1432,7 +1439,7 @@ } -CMD(fload, "debug", "", "load file contents into db",) +CMD(fload, "debug", "", "load file contents into db", OPT_NONE) { string s = get_stdin(); @@ -1445,7 +1452,8 @@ dbw.consume_file_data(f_id, f_data); } -CMD(fmerge, "debug", " ", "merge 3 files and output result",) +CMD(fmerge, "debug", " ", "merge 3 files and output result", + OPT_NONE) { if (args.size() != 3) throw usage(name); @@ -1476,7 +1484,7 @@ } -CMD(status, "informative", "[PATH]...", "show status of working copy",) +CMD(status, "informative", "[PATH]...", "show status of working copy", OPT_NONE) { revision_set rs; manifest_map m_old, m_new; @@ -1490,7 +1498,8 @@ cout << endl << tmp << endl; } -CMD(identify, "working copy", "[PATH]", "calculate identity of PATH or stdin",) +CMD(identify, "working copy", "[PATH]", "calculate identity of PATH or stdin", + OPT_NONE) { if (!(args.size() == 0 || args.size() == 1)) throw usage(name); @@ -1514,7 +1523,8 @@ CMD(cat, "informative", "(file|manifest|revision) [ID]\n" "file REVISION FILENAME", - "write file, manifest, or revision from database to stdout",) + "write file, manifest, or revision from database to stdout", + OPT_NONE) { if (args.size() < 1 || args.size() > 3) throw usage(name); @@ -1617,7 +1627,7 @@ CMD(checkout, "tree", "REVISION DIRECTORY\nDIRECTORY\n", "check out revision from database into directory", - % OPT_BRANCH_NAME) + OPT_BRANCH_NAME) { revision_id ident; @@ -1712,7 +1722,7 @@ ALIAS(co, checkout) CMD(heads, "tree", "", "show unmerged head revisions of branch", - % OPT_BRANCH_NAME) + OPT_BRANCH_NAME) { set heads; if (args.size() != 0) @@ -1980,7 +1990,7 @@ CMD(inventory, "informative", "[PATH]...", "inventory of every file in working copy with associated status", - % OPT_BRANCH_NAME % OPT_ALL_FILES) + OPT_BRANCH_NAME % OPT_ALL_FILES) { manifest_id old_manifest_id; revision_id old_revision_id; @@ -2085,7 +2095,8 @@ "ignored\n" "missing", "show database objects, or the current working copy manifest,\n" - "or unknown, intentionally ignored, or missing state files",) + "or unknown, intentionally ignored, or missing state files", + OPT_NONE) { if (args.size() == 0) throw usage(name); @@ -2121,7 +2132,7 @@ CMD(mdelta, "packet i/o", "OLDID NEWID", "write manifest delta packet to stdout", - ) + OPT_NONE) { if (args.size() != 2) throw usage(name); @@ -2145,7 +2156,8 @@ manifest_delta(del)); } -CMD(fdelta, "packet i/o", "OLDID NEWID", "write file delta packet to stdout",) +CMD(fdelta, "packet i/o", "OLDID NEWID", "write file delta packet to stdout", + OPT_NONE) { if (args.size() != 2) throw usage(name); @@ -2167,7 +2179,8 @@ pw.consume_file_delta(f_old_id, f_new_id, file_delta(del)); } -CMD(rdata, "packet i/o", "ID", "write revision data packet to stdout",) +CMD(rdata, "packet i/o", "ID", "write revision data packet to stdout", + OPT_NONE) { if (args.size() != 1) throw usage(name); @@ -2184,7 +2197,8 @@ pw.consume_revision_data(r_id, r_data); } -CMD(mdata, "packet i/o", "ID", "write manifest data packet to stdout",) +CMD(mdata, "packet i/o", "ID", "write manifest data packet to stdout", + OPT_NONE) { if (args.size() != 1) throw usage(name); @@ -2202,7 +2216,8 @@ } -CMD(fdata, "packet i/o", "ID", "write file data packet to stdout",) +CMD(fdata, "packet i/o", "ID", "write file data packet to stdout", + OPT_NONE) { if (args.size() != 1) throw usage(name); @@ -2220,7 +2235,8 @@ } -CMD(certs, "packet i/o", "ID", "write cert packets to stdout",) +CMD(certs, "packet i/o", "ID", "write cert packets to stdout", + OPT_NONE) { if (args.size() != 1) throw usage(name); @@ -2237,7 +2253,8 @@ pw.consume_revision_cert(idx(certs, i)); } -CMD(pubkey, "packet i/o", "ID", "write public key packet to stdout",) +CMD(pubkey, "packet i/o", "ID", "write public key packet to stdout", + OPT_NONE) { if (args.size() != 1) throw usage(name); @@ -2252,7 +2269,8 @@ pw.consume_public_key(ident, key); } -CMD(privkey, "packet i/o", "ID", "write private key packet to stdout",) +CMD(privkey, "packet i/o", "ID", "write private key packet to stdout", + OPT_NONE) { if (args.size() != 1) throw usage(name); @@ -2268,7 +2286,8 @@ } -CMD(read, "packet i/o", "", "read packets from stdin",) +CMD(read, "packet i/o", "", "read packets from stdin", + OPT_NONE) { packet_db_writer dbw(app, true); size_t count = read_packets(cin, dbw); @@ -2281,7 +2300,8 @@ CMD(reindex, "network", "", - "rebuild the indices used to sync over the network",) + "rebuild the indices used to sync over the network", + OPT_NONE) { if (args.size() > 0) throw usage(name); @@ -2350,7 +2370,7 @@ } CMD(push, "network", "[ADDRESS[:PORTNUMBER] [COLLECTION]]", - "push COLLECTION to netsync server at ADDRESS",) + "push COLLECTION to netsync server at ADDRESS", OPT_NONE) { utf8 addr; vector collections; @@ -2364,7 +2384,7 @@ } CMD(pull, "network", "[ADDRESS[:PORTNUMBER] [COLLECTION]]", - "pull COLLECTION from netsync server at ADDRESS",) + "pull COLLECTION from netsync server at ADDRESS", OPT_NONE) { utf8 addr; vector collections; @@ -2377,7 +2397,7 @@ } CMD(sync, "network", "[ADDRESS[:PORTNUMBER] [COLLECTION]]", - "sync COLLECTION with netsync server at ADDRESS",) + "sync COLLECTION with netsync server at ADDRESS", OPT_NONE) { utf8 addr; vector collections; @@ -2391,7 +2411,7 @@ } CMD(serve, "network", "ADDRESS[:PORTNUMBER] COLLECTION...", - "listen on ADDRESS and serve COLLECTION to connecting clients",) + "listen on ADDRESS and serve COLLECTION to connecting clients", OPT_NONE) { if (args.size() < 2) throw usage(name); @@ -2423,7 +2443,8 @@ "changesetify\n" "rebuild\n" "set_epoch BRANCH EPOCH\n", - "manipulate database state",) + "manipulate database state", + OPT_NONE) { if (args.size() == 1) { @@ -2472,7 +2493,8 @@ } CMD(attr, "working copy", "set FILE ATTR VALUE\nget FILE [ATTR]\ndrop FILE", - "set, get or drop file attributes",) + "set, get or drop file attributes", + OPT_NONE) { if (args.size() < 2 || args.size() > 4) throw usage(name); @@ -2599,7 +2621,7 @@ CMD(commit, "working copy", "[PATH]...", "commit working copy to database", - % OPT_BRANCH_NAME % OPT_MESSAGE % OPT_DATE % OPT_AUTHOR) + OPT_BRANCH_NAME % OPT_MESSAGE % OPT_DATE % OPT_AUTHOR) { string log_message(""); revision_set rs; @@ -3020,19 +3042,19 @@ CMD(cdiff, "informative", "[--revision=REVISION [--revision=REVISION]] [PATH]...", "show current context diffs on stdout", - % OPT_BRANCH_NAME % OPT_REVISION) + OPT_BRANCH_NAME % OPT_REVISION) { do_diff(name, app, args, context_diff); } CMD(diff, "informative", "[--revision=REVISION [--revision=REVISION]] [PATH]...", "show current unified diffs on stdout", - % OPT_BRANCH_NAME % OPT_REVISION) + OPT_BRANCH_NAME % OPT_REVISION) { do_diff(name, app, args, unified_diff); } -CMD(lca, "debug", "LEFT RIGHT", "print least common ancestor",) +CMD(lca, "debug", "LEFT RIGHT", "print least common ancestor", OPT_NONE) { if (args.size() != 2) throw usage(name); @@ -3049,7 +3071,8 @@ } -CMD(lcad, "debug", "LEFT RIGHT", "print least common ancestor / dominator",) +CMD(lcad, "debug", "LEFT RIGHT", "print least common ancestor / dominator", + OPT_NONE) { if (args.size() != 2) throw usage(name); @@ -3066,7 +3089,8 @@ } -CMD(agraph, "debug", "", "dump ancestry graph to stdout in VCG format",) +CMD(agraph, "debug", "", "dump ancestry graph to stdout in VCG format", + OPT_NONE) { set nodes; multimap branches; @@ -3172,7 +3196,7 @@ // } CMD(update, "working copy", "[REVISION]", "update working copy to be based off another revision", - % OPT_BRANCH_NAME) + OPT_BRANCH_NAME) { manifest_map m_old, m_ancestor, m_working, m_chosen; manifest_id m_ancestor_id, m_chosen_id; @@ -3415,7 +3439,7 @@ CMD(merge, "tree", "", "merge unmerged heads of branch", - % OPT_BRANCH_NAME) + OPT_BRANCH_NAME) { set heads; @@ -3464,7 +3488,8 @@ } CMD(propagate, "tree", "SOURCE-BRANCH DEST-BRANCH", - "merge from one branch to another asymmetrically",) + "merge from one branch to another asymmetrically", + OPT_NONE) { // this is a special merge operator, but very useful for people maintaining // "slightly disparate but related" trees. it does a one-way merge; less @@ -3546,7 +3571,8 @@ } } -CMD(refresh_inodeprints, "tree", "", "refresh the inodeprint cache",) +CMD(refresh_inodeprints, "tree", "", "refresh the inodeprint cache", + OPT_NONE) { enable_inodeprints(); maybe_update_inodeprints(app); @@ -3555,7 +3581,8 @@ CMD(explicit_merge, "tree", "LEFT-REVISION RIGHT-REVISION DEST-BRANCH\n" "LEFT-REVISION RIGHT-REVISION COMMON-ANCESTOR DEST-BRANCH", - "merge two explicitly given revisions, placing result in given branch",) + "merge two explicitly given revisions, placing result in given branch", + OPT_NONE) { revision_id left, right, ancestor; string branch; @@ -3611,7 +3638,8 @@ } CMD(complete, "informative", "(revision|manifest|file) PARTIAL-ID", - "complete partial id",) + "complete partial id", + OPT_NONE) { if (args.size() != 2) throw usage(name); @@ -3652,7 +3680,7 @@ CMD(revert, "working copy", "[PATH]...", - "revert file(s), dir(s) or entire working copy",) + "revert file(s), dir(s) or entire working copy", OPT_NONE) { manifest_map m_old; revision_id old_revision_id; @@ -3714,7 +3742,7 @@ CMD(rcs_import, "debug", "RCSFILE...", "import all versions in RCS files\n" "this command doesn't reconstruct revisions. you probably want cvs_import", - % OPT_BRANCH_NAME) + OPT_BRANCH_NAME) { if (args.size() < 1) throw usage(name); @@ -3730,7 +3758,7 @@ CMD(cvs_import, "rcs", "CVSROOT", "import all versions in CVS repository", - % OPT_BRANCH_NAME) + OPT_BRANCH_NAME) { if (args.size() != 1) throw usage(name); @@ -3760,8 +3788,9 @@ } -CMD(annotate, "informative", "PATH", "print annotated copy of the file from REVISION", - % OPT_REVISION) +CMD(annotate, "informative", "PATH", + "print annotated copy of the file from REVISION", + OPT_REVISION) { revision_id rid; file_path file; @@ -3794,8 +3823,9 @@ do_annotate(app, file, fid, rid); } -CMD(log, "informative", "[ID] [file]", "print history in reverse order starting from 'ID' (filtering by 'file')", - % OPT_DEPTH) +CMD(log, "informative", "[ID] [file]", + "print history in reverse order starting from 'ID' (filtering by 'file')", + OPT_DEPTH) { revision_set rev; revision_id rid; @@ -3944,7 +3974,7 @@ CMD(setup, "tree", "DIRECTORY", "setup a new working copy directory", - % OPT_BRANCH_NAME) + OPT_BRANCH_NAME) { string dir; @@ -3969,7 +3999,8 @@ "toposort [REV1 [REV2 [REV3 [...]]]]\n" "ancestry_difference NEW_REV [OLD_REV1 [OLD_REV2 [...]]]\n" "leaves", - "automation interface",) + "automation interface", + OPT_NONE) { if (args.size() == 0) throw usage(name); @@ -3983,7 +4014,8 @@ } CMD(set, "vars", "DOMAIN NAME VALUE", - "set the database variable NAME to VALUE, in domain DOMAIN",) + "set the database variable NAME to VALUE, in domain DOMAIN", + OPT_NONE) { if (args.size() != 3) throw usage(name); @@ -3998,7 +4030,8 @@ } CMD(unset, "vars", "DOMAIN NAME", - "remove the database variable NAME in domain DOMAIN",) + "remove the database variable NAME in domain DOMAIN", + OPT_NONE) { if (args.size() != 2) throw usage(name);