# # # patch "automate.cc" # from [267419c83457db95e512cf5288ef4983759884cf] # to [3ab56b97e7049bacfa3ddff20cc986b104a63645] # # patch "cmd.hh" # from [a8110165eb56760ccba3f7d90c96f9b51d1129bd] # to [7b2a9f416ee7dca1ced110f21bef4fc822d5debf] # # patch "cmd_automate.cc" # from [69aefb502195a4d228f1cc39045ee72d42958b84] # to [b6c7274b9d61b785e6983ab799759ce695d24b48] # # patch "cmd_diff_log.cc" # from [f4ac10d6cef7225e8977e1a3a75cfd811709d4c2] # to [31d37e232b96d8d5e4f349ab4aac578e478cd0cc] # # patch "cmd_files.cc" # from [af49f7e6f0d8ccc50a5ff9717d7bb9f1b329587b] # to [50c18877e69353b9501b675a6c52edc87c236013] # # patch "cmd_list.cc" # from [744b63656850bc2337d009044053fc80872c3849] # to [b919b1e05461d43248a3ecebb44eb366244eaa7f] # # patch "database.hh" # from [30245ff17a9001e4a57e5a8100d5cb1238dbd26f] # to [22248ce4347898cba7850b50785602eeff2e37d4] # ============================================================ --- automate.cc 267419c83457db95e512cf5288ef4983759884cf +++ automate.cc 3ab56b97e7049bacfa3ddff20cc986b104a63645 @@ -61,17 +61,17 @@ using std::vector; // newline. Revision ids are printed in alphabetically sorted order. // Error conditions: If the branch does not exist, prints nothing. (There are // no heads.) -AUTOMATE(heads, N_("[BRANCH]"), options::opts::none) +AUTOMATE_WITH_DATABASE(heads, N_("[BRANCH]"), options::opts::none) { N(args.size() < 2, F("wrong argument count")); if (args.size() ==1 ) { // branchname was explicitly given, use that - app.opts.branchname = branch_name(idx(args, 0)()); + db.set_opt_branchname(branch_name(idx(args, 0)())); } set heads; - app.db.get_project().get_branch_heads(app.opts.branchname, heads); + db.get_project().get_branch_heads(db.get_opt_branchname(), heads); for (set::const_iterator i = heads.begin(); i != heads.end(); ++i) output << (*i).inner()() << '\n'; } @@ -85,7 +85,8 @@ AUTOMATE(heads, N_("[BRANCH]"), options: // newline. Revision ids are printed in alphabetically sorted order. // Error conditions: If any of the revisions do not exist, prints nothing to // stdout, prints an error message to stderr, and exits with status 1. -AUTOMATE(ancestors, N_("REV1 [REV2 [REV3 [...]]]"), options::opts::none) +AUTOMATE_WITH_DATABASE(ancestors, N_("REV1 [REV2 [REV3 [...]]]"), + options::opts::none) { N(args.size() > 0, F("wrong argument count")); @@ -95,7 +96,7 @@ AUTOMATE(ancestors, N_("REV1 [REV2 [REV3 for (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); + N(db.revision_exists(rid), F("No such revision %s") % rid); frontier.push_back(rid); } while (!frontier.empty()) @@ -104,7 +105,7 @@ AUTOMATE(ancestors, N_("REV1 [REV2 [REV3 frontier.pop_back(); if(!null_id(rid)) { set parents; - app.db.get_revision_parents(rid, parents); + db.get_revision_parents(rid, parents); for (set::const_iterator i = parents.begin(); i != parents.end(); ++i) { @@ -132,7 +133,8 @@ AUTOMATE(ancestors, N_("REV1 [REV2 [REV3 // newline. Revision ids are printed in alphabetically sorted order. // Error conditions: If any of the revisions do not exist, prints nothing to // stdout, prints an error message to stderr, and exits with status 1. -AUTOMATE(descendents, N_("REV1 [REV2 [REV3 [...]]]"), options::opts::none) +AUTOMATE_WITH_DATABASE(descendents, N_("REV1 [REV2 [REV3 [...]]]"), + options::opts::none) { N(args.size() > 0, F("wrong argument count")); @@ -142,7 +144,7 @@ AUTOMATE(descendents, N_("REV1 [REV2 [RE for (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); + N(db.revision_exists(rid), F("No such revision %s") % rid); frontier.push_back(rid); } while (!frontier.empty()) @@ -150,7 +152,7 @@ AUTOMATE(descendents, N_("REV1 [REV2 [RE revision_id rid = frontier.back(); frontier.pop_back(); set children; - app.db.get_revision_children(rid, children); + db.get_revision_children(rid, children); for (set::const_iterator i = children.begin(); i != children.end(); ++i) { @@ -180,16 +182,17 @@ AUTOMATE(descendents, N_("REV1 [REV2 [RE // newline. Revision ids are printed in alphabetically sorted order. // Error conditions: If any of the revisions do not exist, prints nothing to // stdout, prints an error message to stderr, and exits with status 1. -AUTOMATE(erase_ancestors, N_("[REV1 [REV2 [REV3 [...]]]]"), options::opts::none) +AUTOMATE_WITH_DATABASE(erase_ancestors, N_("[REV1 [REV2 [REV3 [...]]]]"), + options::opts::none) { set revs; for (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); + N(db.revision_exists(rid), F("No such revision %s") % rid); revs.insert(rid); } - erase_ancestors(revs, app.db); + erase_ancestors(revs, db); for (set::const_iterator i = revs.begin(); i != revs.end(); ++i) output << (*i).inner()() << '\n'; } @@ -212,7 +215,7 @@ AUTOMATE(erase_ancestors, N_("[REV1 [REV // // Error conditions: If the file name has no attributes, prints only the // format version, if the file is unknown, escalates -AUTOMATE(attributes, N_("FILE"), options::opts::none) +AUTOMATE_WITH_EVERYTHING(attributes, N_("FILE"), options::opts::none) { N(args.size() > 0, F("wrong argument count")); @@ -326,17 +329,18 @@ AUTOMATE(attributes, N_("FILE"), options // newline. Revisions are printed in topologically sorted order. // Error conditions: If any of the revisions do not exist, prints nothing to // stdout, prints an error message to stderr, and exits with status 1. -AUTOMATE(toposort, N_("[REV1 [REV2 [REV3 [...]]]]"), options::opts::none) +AUTOMATE_WITH_DATABASE(toposort, N_("[REV1 [REV2 [REV3 [...]]]]"), + options::opts::none) { set revs; for (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); + N(db.revision_exists(rid), F("No such revision %s") % rid); revs.insert(rid); } vector sorted; - toposort(revs, sorted, app.db); + toposort(revs, sorted, db); for (vector::const_iterator i = sorted.begin(); i != sorted.end(); ++i) output << (*i).inner()() << '\n'; @@ -358,27 +362,27 @@ AUTOMATE(toposort, N_("[REV1 [REV2 [REV3 // newline. Revisions are printed in topologically sorted order. // Error conditions: If any of the revisions do not exist, prints nothing to // stdout, prints an error message to stderr, and exits with status 1. -AUTOMATE(ancestry_difference, N_("NEW_REV [OLD_REV1 [OLD_REV2 [...]]]"), options::opts::none) +AUTOMATE_WITH_DATABASE(ancestry_difference, N_("NEW_REV [OLD_REV1 [OLD_REV2 [...]]]"), options::opts::none) { N(args.size() > 0, F("wrong argument count")); - + revision_id a; set bs; vector::const_iterator i = args.begin(); a = revision_id((*i)()); - N(app.db.revision_exists(a), F("No such revision %s") % a); + N(db.revision_exists(a), F("No such revision %s") % a); for (++i; i != args.end(); ++i) { revision_id b((*i)()); - N(app.db.revision_exists(b), F("No such revision %s") % b); + N(db.revision_exists(b), F("No such revision %s") % b); bs.insert(b); } set ancestors; - ancestry_difference(a, bs, ancestors, app.db); + ancestry_difference(a, bs, ancestors, db); vector sorted; - toposort(ancestors, sorted, app.db); + toposort(ancestors, sorted, db); for (vector::const_iterator i = sorted.begin(); i != sorted.end(); ++i) output << (*i).inner()() << '\n'; @@ -397,16 +401,16 @@ AUTOMATE(ancestry_difference, N_("NEW_RE // Output format: A list of revision ids, in hexadecimal, each followed by a // newline. Revision ids are printed in alphabetically sorted order. // Error conditions: None. -AUTOMATE(leaves, "", options::opts::none) +AUTOMATE_WITH_DATABASE(leaves, "", options::opts::none) { N(args.size() == 0, F("no arguments needed")); // this might be more efficient in SQL, but for now who cares. set leaves; - app.db.get_revision_ids(leaves); + db.get_revision_ids(leaves); multimap graph; - app.db.get_revision_ancestry(graph); + db.get_revision_ancestry(graph); for (multimap::const_iterator i = graph.begin(); i != graph.end(); ++i) leaves.erase(i->first); @@ -425,15 +429,15 @@ AUTOMATE(leaves, "", options::opts::none // newline. Revision ids are printed in alphabetically sorted order. // Error conditions: If the revision does not exist, prints nothing to stdout, // prints an error message to stderr, and exits with status 1. -AUTOMATE(parents, N_("REV"), options::opts::none) +AUTOMATE_WITH_DATABASE(parents, N_("REV"), options::opts::none) { N(args.size() == 1, F("wrong argument count")); revision_id rid(idx(args, 0)()); - N(app.db.revision_exists(rid), F("No such revision %s") % rid); + N(db.revision_exists(rid), F("No such revision %s") % rid); set parents; - app.db.get_revision_parents(rid, parents); + db.get_revision_parents(rid, parents); for (set::const_iterator i = parents.begin(); i != parents.end(); ++i) if (!null_id(*i)) @@ -450,15 +454,15 @@ AUTOMATE(parents, N_("REV"), options::op // newline. Revision ids are printed in alphabetically sorted order. // Error conditions: If the revision does not exist, prints nothing to stdout, // prints an error message to stderr, and exits with status 1. -AUTOMATE(children, N_("REV"), options::opts::none) +AUTOMATE_WITH_DATABASE(children, N_("REV"), options::opts::none) { N(args.size() == 1, F("wrong argument count")); revision_id rid(idx(args, 0)()); - N(app.db.revision_exists(rid), F("No such revision %s") % rid); + N(db.revision_exists(rid), F("No such revision %s") % rid); set children; - app.db.get_revision_children(rid, children); + db.get_revision_children(rid, children); for (set::const_iterator i = children.begin(); i != children.end(); ++i) if (!null_id(*i)) @@ -485,7 +489,7 @@ AUTOMATE(children, N_("REV"), options::o // The output as a whole is alphabetically sorted; additionally, the parents // within each line are alphabetically sorted. // Error conditions: None. -AUTOMATE(graph, "", options::opts::none) +AUTOMATE_WITH_DATABASE(graph, "", options::opts::none) { N(args.size() == 0, F("no arguments needed")); @@ -493,7 +497,7 @@ AUTOMATE(graph, "", options::opts::none) multimap edges_mmap; map > child_to_parents; - app.db.get_revision_ancestry(edges_mmap); + db.get_revision_ancestry(edges_mmap); for (multimap::const_iterator i = edges_mmap.begin(); i != edges_mmap.end(); ++i) @@ -528,18 +532,18 @@ AUTOMATE(graph, "", options::opts::none) // Output format: A list of revision ids, in hexadecimal, each followed by a // newline. Revision ids are printed in alphabetically sorted order. // Error conditions: None. -AUTOMATE(select, N_("SELECTOR"), options::opts::none) +AUTOMATE_WITH_DATABASE(select, N_("SELECTOR"), options::opts::none) { N(args.size() == 1, F("wrong argument count")); vector > - sels(selectors::parse_selector(args[0](), app.db)); + sels(selectors::parse_selector(args[0](), db)); // we jam through an "empty" selection on sel_ident type set completions; selectors::selector_type ty = selectors::sel_ident; - selectors::complete_selector("", sels, ty, completions, app.db); + selectors::complete_selector("", sels, ty, completions, db); for (set::const_iterator i = completions.begin(); i != completions.end(); ++i) @@ -710,7 +714,7 @@ extract_added_file_paths(addition_map co // Error conditions: If no workspace book keeping _MTN directory is found, // prints an error message to stderr, and exits with status 1. -AUTOMATE(inventory, "", options::opts::none) +AUTOMATE_WITH_EVERYTHING(inventory, "", options::opts::none) { N(args.size() == 0, F("no arguments needed")); @@ -910,7 +914,7 @@ AUTOMATE(inventory, "", options::opts::n // the same type will be sorted by the filename they refer to. // Error conditions: If the revision specified is unknown or invalid // prints an error message to stderr and exits with status 1. -AUTOMATE(get_revision, N_("[REVID]"), options::opts::none) +AUTOMATE_WITH_EVERYTHING(get_revision, N_("[REVID]"), options::opts::none) { N(args.size() < 2, F("wrong argument count")); @@ -953,7 +957,7 @@ AUTOMATE(get_revision, N_("[REVID]"), op // on. This is the value stored in _MTN/revision // Error conditions: If no workspace book keeping _MTN directory is found, // prints an error message to stderr, and exits with status 1. -AUTOMATE(get_base_revision_id, "", options::opts::none) +AUTOMATE_WITH_EVERYTHING(get_base_revision_id, "", options::opts::none) { N(args.size() == 0, F("no arguments needed")); @@ -977,7 +981,7 @@ AUTOMATE(get_base_revision_id, "", optio // files in the workspace. // Error conditions: If no workspace book keeping _MTN directory is found, // prints an error message to stderr, and exits with status 1. -AUTOMATE(get_current_revision_id, "", options::opts::none) +AUTOMATE_WITH_EVERYTHING(get_current_revision_id, "", options::opts::none) { N(args.size() == 0, F("no arguments needed")); @@ -1043,7 +1047,7 @@ AUTOMATE(get_current_revision_id, "", op // // Error conditions: If the revision ID specified is unknown or // invalid prints an error message to stderr and exits with status 1. -AUTOMATE(get_manifest_of, N_("[REVID]"), options::opts::none) +AUTOMATE_WITH_EVERYTHING(get_manifest_of, N_("[REVID]"), options::opts::none) { N(args.size() < 2, F("wrong argument count")); @@ -1086,7 +1090,7 @@ AUTOMATE(get_manifest_of, N_("[REVID]"), // // Error conditions: If the revision id specified is unknown or // invalid prints an error message to stderr and exits with status 1. -AUTOMATE(packet_for_rdata, N_("REVID"), options::opts::none) +AUTOMATE_WITH_DATABASE(packet_for_rdata, N_("REVID"), options::opts::none) { N(args.size() == 1, F("wrong argument count")); @@ -1096,9 +1100,9 @@ AUTOMATE(packet_for_rdata, N_("REVID"), revision_id r_id(idx(args, 0)()); revision_data r_data; - N(app.db.revision_exists(r_id), + N(db.revision_exists(r_id), F("no such revision '%s'") % r_id); - app.db.get_revision(r_id, r_data); + db.get_revision(r_id, r_data); pw.consume_revision_data(r_id,r_data); } @@ -1112,7 +1116,7 @@ AUTOMATE(packet_for_rdata, N_("REVID"), // // Error conditions: If the revision id specified is unknown or // invalid prints an error message to stderr and exits with status 1. -AUTOMATE(packets_for_certs, N_("REVID"), options::opts::none) +AUTOMATE_WITH_DATABASE(packets_for_certs, N_("REVID"), options::opts::none) { N(args.size() == 1, F("wrong argument count")); @@ -1122,9 +1126,9 @@ AUTOMATE(packets_for_certs, N_("REVID"), revision_id r_id(idx(args, 0)()); vector< revision > certs; - N(app.db.revision_exists(r_id), + N(db.revision_exists(r_id), F("no such revision '%s'") % r_id); - app.db.get_project().get_revision_certs(r_id, certs); + db.get_project().get_revision_certs(r_id, certs); for (size_t i = 0; i < certs.size(); ++i) pw.consume_revision_cert(idx(certs,i)); } @@ -1139,7 +1143,7 @@ AUTOMATE(packets_for_certs, N_("REVID"), // // Error conditions: If the file id specified is unknown or invalid // prints an error message to stderr and exits with status 1. -AUTOMATE(packet_for_fdata, N_("FILEID"), options::opts::none) +AUTOMATE_WITH_DATABASE(packet_for_fdata, N_("FILEID"), options::opts::none) { N(args.size() == 1, F("wrong argument count")); @@ -1149,9 +1153,9 @@ AUTOMATE(packet_for_fdata, N_("FILEID"), file_id f_id(idx(args, 0)()); file_data f_data; - N(app.db.file_version_exists(f_id), + N(db.file_version_exists(f_id), F("no such file '%s'") % f_id); - app.db.get_file_version(f_id, f_data); + db.get_file_version(f_id, f_data); pw.consume_file_data(f_id,f_data); } @@ -1166,7 +1170,7 @@ AUTOMATE(packet_for_fdata, N_("FILEID"), // // Error conditions: If any of the file ids specified are unknown or // invalid prints an error message to stderr and exits with status 1. -AUTOMATE(packet_for_fdelta, N_("OLD_FILE NEW_FILE"), options::opts::none) +AUTOMATE_WITH_DATABASE(packet_for_fdelta, N_("OLD_FILE NEW_FILE"), options::opts::none) { N(args.size() == 2, F("wrong argument count")); @@ -1177,12 +1181,12 @@ AUTOMATE(packet_for_fdelta, N_("OLD_FILE file_id f_new_id(idx(args, 1)()); file_data f_old_data, f_new_data; - N(app.db.file_version_exists(f_old_id), + N(db.file_version_exists(f_old_id), F("no such revision '%s'") % f_old_id); - N(app.db.file_version_exists(f_new_id), + N(db.file_version_exists(f_new_id), F("no such revision '%s'") % f_new_id); - app.db.get_file_version(f_old_id, f_old_data); - app.db.get_file_version(f_new_id, f_new_data); + db.get_file_version(f_old_id, f_old_data); + db.get_file_version(f_new_id, f_new_data); delta del; diff(f_old_data.inner(), f_new_data.inner(), del); pw.consume_file_delta(f_old_id, f_new_id, file_delta(del)); @@ -1200,7 +1204,7 @@ AUTOMATE(packet_for_fdelta, N_("OLD_FILE // Error conditions: If any of the revisions do not exist, prints // nothing to stdout, prints an error message to stderr, and exits // with status 1. -AUTOMATE(common_ancestors, N_("REV1 [REV2 [REV3 [...]]]"), options::opts::none) +AUTOMATE_WITH_DATABASE(common_ancestors, N_("REV1 [REV2 [REV3 [...]]]"), options::opts::none) { N(args.size() > 0, F("wrong argument count")); @@ -1210,7 +1214,7 @@ AUTOMATE(common_ancestors, N_("REV1 [REV for (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); + N(db.revision_exists(rid), F("No such revision %s") % rid); ancestors.clear(); ancestors.insert(rid); frontier.push_back(rid); @@ -1221,7 +1225,7 @@ AUTOMATE(common_ancestors, N_("REV1 [REV if(!null_id(rid)) { set parents; - app.db.get_revision_parents(rid, parents); + db.get_revision_parents(rid, parents); for (set::const_iterator i = parents.begin(); i != parents.end(); ++i) { @@ -1263,7 +1267,7 @@ AUTOMATE(common_ancestors, N_("REV1 [REV // in alphabetically sorted order. // Error conditions: // None. -AUTOMATE(branches, "", options::opts::none) +AUTOMATE_WITH_EVERYTHING(branches, "", options::opts::none) { N(args.size() == 0, F("no arguments needed")); @@ -1312,7 +1316,7 @@ AUTOMATE(branches, "", options::opts::no // Stanzas are printed in arbitrary order. // Error conditions: // A run-time exception is thrown for illegal patterns. -AUTOMATE(tags, N_("[BRANCH_PATTERN]"), options::opts::none) +AUTOMATE_WITH_EVERYTHING(tags, N_("[BRANCH_PATTERN]"), options::opts::none) { N(args.size() < 2, F("wrong argument count")); @@ -1402,7 +1406,7 @@ namespace // // Error conditions: If the passphrase is empty or the key already exists, // prints an error message to stderr and exits with status 1. -AUTOMATE(genkey, N_("KEYID PASSPHRASE"), options::opts::none) +AUTOMATE_WITH_DATABASE(genkey, N_("KEYID PASSPHRASE"), options::opts::none) { N(args.size() == 2, F("wrong argument count")); @@ -1412,11 +1416,12 @@ AUTOMATE(genkey, N_("KEYID PASSPHRASE"), utf8 passphrase = idx(args, 1); - bool exists = app.keys.key_pair_exists(ident); - if (app.db.database_specified()) + key_store & keys = db.get_key_store(); + bool exists = keys.key_pair_exists(ident); + if (db.database_specified()) { - transaction_guard guard(app.db); - exists = exists || app.db.public_key_exists(ident); + transaction_guard guard(db); + exists = exists || db.public_key_exists(ident); guard.commit(); } @@ -1426,8 +1431,8 @@ AUTOMATE(genkey, N_("KEYID PASSPHRASE"), P(F("generating key-pair '%s'") % ident); generate_key_pair(kp, passphrase); P(F("storing key-pair '%s' in %s/") - % ident % app.keys.get_key_dir()); - app.keys.put_key_pair(ident, kp); + % ident % keys.get_key_dir()); + keys.put_key_pair(ident, kp); basic_io::printer prt; basic_io::stanza stz; @@ -1461,7 +1466,7 @@ AUTOMATE(genkey, N_("KEYID PASSPHRASE"), // Sample output (for 'mtn automate get_option branch: // net.venge.monotone // -AUTOMATE(get_option, N_("OPTION"), options::opts::none) +AUTOMATE_WITH_EVERYTHING(get_option, N_("OPTION"), options::opts::none) { N(args.size() == 1, F("wrong argument count")); @@ -1510,7 +1515,7 @@ AUTOMATE(get_option, N_("OPTION"), optio // Sample output (for 'mtn automate get_content_changed 3bccff99d08421df72519b61a4dded16d1139c33 ChangeLog): // content_mark [276264b0b3f1e70fc1835a700e6e61bdbe4c3f2f] // -AUTOMATE(get_content_changed, N_("REV FILE"), options::opts::none) +AUTOMATE_WITH_DATABASE(get_content_changed, N_("REV FILE"), options::opts::none) { N(args.size() == 2, F("wrong argument count")); @@ -1520,9 +1525,9 @@ AUTOMATE(get_content_changed, N_("REV FI marking_map mm; ident = revision_id(idx(args, 0)()); - N(app.db.revision_exists(ident), + N(db.revision_exists(ident), F("no revision %s found in database") % ident); - app.db.get_roster(ident, new_roster, mm); + db.get_roster(ident, new_roster, mm); split_path path; file_path_external(idx(args,1)).split(path); @@ -1569,7 +1574,7 @@ AUTOMATE(get_content_changed, N_("REV FI // // Sample output (for automate get_corresponding_path 91f25c8ee830b11b52dd356c925161848d4274d0 foo2 dae0d8e3f944c82a9688bcd6af99f5b837b41968; see automate_get_corresponding_path test) // file "foo" -AUTOMATE(get_corresponding_path, N_("REV1 FILE REV2"), options::opts::none) +AUTOMATE_WITH_DATABASE(get_corresponding_path, N_("REV1 FILE REV2"), options::opts::none) { N(args.size() == 3, F("wrong argument count")); @@ -1578,14 +1583,14 @@ AUTOMATE(get_corresponding_path, N_("REV revision_id ident, old_ident; ident = revision_id(idx(args, 0)()); - N(app.db.revision_exists(ident), + N(db.revision_exists(ident), F("no revision %s found in database") % ident); - app.db.get_roster(ident, new_roster); + db.get_roster(ident, new_roster); old_ident = revision_id(idx(args, 2)()); - N(app.db.revision_exists(old_ident), + N(db.revision_exists(old_ident), F("no revision %s found in database") % old_ident); - app.db.get_roster(old_ident, old_roster); + db.get_roster(old_ident, old_roster); split_path path; file_path_external(idx(args,1)).split(path); @@ -1618,38 +1623,38 @@ AUTOMATE(get_corresponding_path, N_("REV // The ID of the new file (40 digit hex string) // Error conditions: // a runtime exception is thrown if base revision is not available -AUTOMATE(put_file, N_("[FILEID] CONTENTS"), options::opts::none) +AUTOMATE_WITH_DATABASE(put_file, N_("[FILEID] CONTENTS"), options::opts::none) { N(args.size() == 1 || args.size() == 2, F("wrong argument count")); file_id sha1sum; - transaction_guard tr(app.db); + transaction_guard tr(db); if (args.size() == 1) { file_data dat(idx(args, 0)()); calculate_ident(dat, sha1sum); - app.db.put_file(sha1sum, dat); + db.put_file(sha1sum, dat); } else if (args.size() == 2) { file_data dat(idx(args, 1)()); calculate_ident(dat, sha1sum); file_id base_id(idx(args, 0)()); - N(app.db.file_version_exists(base_id), + N(db.file_version_exists(base_id), F("no file version %s found in database") % base_id); // put_file_version won't do anything if the target ID already exists, // but we can save the delta calculation by checking here too - if (!app.db.file_version_exists(sha1sum)) + if (!db.file_version_exists(sha1sum)) { file_data olddat; - app.db.get_file_version(base_id, olddat); + db.get_file_version(base_id, olddat); delta del; diff(olddat.inner(), dat.inner(), del); - app.db.put_file_version(base_id, sha1sum, file_delta(del)); + db.put_file_version(base_id, sha1sum, file_delta(del)); } } else I(false); @@ -1668,7 +1673,7 @@ AUTOMATE(put_file, N_("[FILEID] CONTENTS // The ID of the new revision // Error conditions: // none -AUTOMATE(put_revision, N_("REVISION-DATA"), options::opts::none) +AUTOMATE_WITH_DATABASE(put_revision, N_("REVISION-DATA"), options::opts::none) { N(args.size() == 1, F("wrong argument count")); @@ -1683,7 +1688,7 @@ AUTOMATE(put_revision, N_("REVISION-DATA { // calculate new manifest roster_t old_roster; - if (!null_id(e->first)) app.db.get_roster(e->first, old_roster); + if (!null_id(e->first)) db.get_roster(e->first, old_roster); roster_t new_roster = old_roster; editable_roster_base eros(new_roster, nis); e->second->apply_to(eros); @@ -1704,7 +1709,7 @@ AUTOMATE(put_revision, N_("REVISION-DATA // If the database refuses the revision, make sure this is because it's // already there. - E(app.db.put_revision(id, rev) || app.db.revision_exists(id), + E(db.put_revision(id, rev) || db.revision_exists(id), F("missing prerequisite for revision %s") % id); output << id << '\n'; @@ -1722,7 +1727,7 @@ AUTOMATE(put_revision, N_("REVISION-DATA // nothing // Error conditions: // none -AUTOMATE(cert, N_("REVISION-ID NAME VALUE"), options::opts::none) +AUTOMATE_WITH_DATABASE(cert, N_("REVISION-ID NAME VALUE"), options::opts::none) { N(args.size() == 3, F("wrong argument count")); @@ -1730,13 +1735,13 @@ AUTOMATE(cert, N_("REVISION-ID NAME VALU cert c; revision_id rid(idx(args, 0)()); - transaction_guard guard(app.db); - N(app.db.revision_exists(rid), + transaction_guard guard(db); + N(db.revision_exists(rid), F("no such revision '%s'") % rid); make_simple_cert(rid.inner(), cert_name(idx(args, 1)()), - cert_value(idx(args, 2)()), app.db, c); + cert_value(idx(args, 2)()), db, c); revision rc(c); - app.db.put_revision_cert(rc); + db.put_revision_cert(rc); guard.commit(); } @@ -1752,7 +1757,7 @@ AUTOMATE(cert, N_("REVISION-ID NAME VALU // nothing // Error conditions: // none -AUTOMATE(db_set, N_("DOMAIN NAME VALUE"), options::opts::none) +AUTOMATE_WITH_DATABASE(db_set, N_("DOMAIN NAME VALUE"), options::opts::none) { N(args.size() == 3, F("wrong argument count")); @@ -1761,7 +1766,7 @@ AUTOMATE(db_set, N_("DOMAIN NAME VALUE") utf8 name = idx(args, 1); utf8 value = idx(args, 2); var_key key(domain, var_name(name())); - app.db.set_var(key, var_value(value())); + db.set_var(key, var_value(value())); } // Name: db_get @@ -1775,7 +1780,7 @@ AUTOMATE(db_set, N_("DOMAIN NAME VALUE") // variable value // Error conditions: // a runtime exception is thrown if the variable is not set -AUTOMATE(db_get, N_("DOMAIN NAME"), options::opts::none) +AUTOMATE_WITH_DATABASE(db_get, N_("DOMAIN NAME"), options::opts::none) { N(args.size() == 2, F("wrong argument count")); @@ -1786,7 +1791,7 @@ AUTOMATE(db_get, N_("DOMAIN NAME"), opti var_value value; try { - app.db.get_var(key, value); + db.get_var(key, value); } catch (std::logic_error) { ============================================================ --- cmd.hh a8110165eb56760ccba3f7d90c96f9b51d1129bd +++ cmd.hh 7b2a9f416ee7dca1ced110f21bef4fc822d5debf @@ -16,6 +16,7 @@ class database; class app_state; class database; +struct workspace; namespace commands { @@ -182,15 +183,71 @@ namespace automation { options::options_type opts; automate(std::string const & n, std::string const & p, options::options_type const & o); + public: virtual void run(std::vector args, std::string const & help_name, app_state & app, std::ostream & output) const = 0; + virtual ~automate(); }; + + struct automate_with_database + : public automate + { + automate_with_database(std::string const & n, std::string const & p, + options::options_type const & o); + + public: + virtual void run(std::vector args, + std::string const & help_name, + database & db, + std::ostream & output) const = 0; + + virtual void run(std::vector args, + std::string const & help_name, + app_state & app, + std::ostream & output) const; + }; + + struct automate_with_workspace + : public automate + { + automate_with_workspace(std::string const & n, std::string const & p, + options::options_type const & o); + + public: + virtual void run(std::vector args, + std::string const & help_name, + workspace & work, + std::ostream & output) const = 0; + + virtual void run(std::vector args, + std::string const & help_name, + app_state & app, + std::ostream & output) const; + }; + + struct automate_with_nothing + : public automate + { + automate_with_nothing(std::string const & n, std::string const & p, + options::options_type const & o); + + public: + virtual void run(std::vector args, + std::string const & help_name, + std::ostream & output) const = 0; + + virtual void run(std::vector args, + std::string const & help_name, + app_state & app, + std::ostream & output) const; + }; + } -#define AUTOMATE(NAME, PARAMS, OPTIONS) \ +#define AUTOMATE_WITH_EVERYTHING(NAME, PARAMS, OPTIONS) \ namespace automation { \ struct auto_ ## NAME : public automate \ { \ @@ -208,9 +265,64 @@ void automation::auto_ ## NAME :: run(st app_state & app, \ std::ostream & output) const +#define AUTOMATE_WITH_DATABASE(NAME, PARAMS, OPTIONS) \ +namespace automation { \ + struct auto_ ## NAME : public automate_with_database \ + { \ + auto_ ## NAME () \ + : automate_with_database(#NAME, PARAMS, \ + options::options_type() | OPTIONS) \ + {} \ + void run(std::vector args, std::string const & help_name, \ + database & db, std::ostream & output) const; \ + virtual ~auto_ ## NAME() {} \ + }; \ + static auto_ ## NAME NAME ## _auto; \ +} \ +void automation::auto_ ## NAME :: run(std::vector args, \ + std::string const & help_name,\ + database & db, \ + std::ostream & output) const +#define AUTOMATE_WITH_WORKSPACE(NAME, PARAMS, OPTIONS) \ +namespace automation { \ + struct auto_ ## NAME : public automate_with_workspace \ + { \ + auto_ ## NAME () \ + : automate_with_workspace(#NAME, PARAMS, \ + options::options_type() | OPTIONS) \ + {} \ + void run(std::vector args, std::string const & help_name, \ + workspace & work, std::ostream & output) const; \ + virtual ~auto_ ## NAME() {} \ + }; \ + static auto_ ## NAME NAME ## _auto; \ +} \ +void automation::auto_ ## NAME :: run(std::vector args, \ + std::string const & help_name,\ + workspace & work, \ + std::ostream & output) const +#define AUTOMATE_WITH_NOTHING(NAME, PARAMS, OPTIONS) \ +namespace automation { \ + struct auto_ ## NAME : public automate_with_nothing \ + { \ + auto_ ## NAME () \ + : automate_with_nothing(#NAME, PARAMS, \ + options::options_type() | OPTIONS) \ + {} \ + void run(std::vector args, std::string const & help_name, \ + std::ostream & output) const; \ + virtual ~auto_ ## NAME() {} \ + }; \ + static auto_ ## NAME NAME ## _auto; \ +} \ +void automation::auto_ ## NAME :: run(std::vector args, \ + std::string const & help_name,\ + std::ostream & output) const + + // Local Variables: // mode: C++ // fill-column: 76 ============================================================ --- cmd_automate.cc 69aefb502195a4d228f1cc39045ee72d42958b84 +++ cmd_automate.cc b6c7274b9d61b785e6983ab799759ce695d24b48 @@ -39,6 +39,46 @@ namespace automation { automations->insert(make_pair(name, this)); } automate::~automate() {} + + automate_with_database::automate_with_database(string const &n, + string const &p, options::options_type const & o) + : automate(n, p, o) + { } + + void automate_with_database::run(std::vector args, + string const & help_name, + app_state & app, + std::ostream & output) const + { + run(args, help_name, app.db, output); + } + + + automate_with_workspace::automate_with_workspace(string const &n, + string const &p, options::options_type const & o) + : automate(n, p, o) + { } + void automate_with_workspace::run(std::vector args, + string const & help_name, + app_state & app, + std::ostream & output) const + { + run(args, help_name, app.work, output); + } + + + automate_with_nothing::automate_with_nothing(string const &n, + string const &p, options::options_type const & o) + : automate(n, p, o) + { } + + void automate_with_nothing::run(std::vector args, + string const & help_name, + app_state & app, + std::ostream & output) const + { + run(args, help_name, output); + } } automation::automate & @@ -72,7 +112,7 @@ static string const interface_version = // Output format: ".\n". Always matches // "[0-9]+\.[0-9]+\n". // Error conditions: None. -AUTOMATE(interface_version, "", options::opts::none) +AUTOMATE_WITH_NOTHING(interface_version, "", options::opts::none) { N(args.size() == 0, F("no arguments needed")); @@ -326,7 +366,7 @@ struct automate_ostream : public std::os }; -AUTOMATE(stdio, "", options::opts::automate_stdio_size) +AUTOMATE_WITH_EVERYTHING(stdio, "", options::opts::automate_stdio_size) { N(args.size() == 0, F("no arguments needed")); ============================================================ --- cmd_diff_log.cc f4ac10d6cef7225e8977e1a3a75cfd811709d4c2 +++ cmd_diff_log.cc 31d37e232b96d8d5e4f349ab4aac578e478cd0cc @@ -523,7 +523,7 @@ CMD(diff, N_("informative"), N_("[PATH]. // doubles the output of automate get_revision). If no content changes happened, // the output is empty. All file operations beside mtn add are omitted, // as they don't change the content of the file. -AUTOMATE(content_diff, N_("[FILE [...]]"), +AUTOMATE_WITH_EVERYTHING(content_diff, N_("[FILE [...]]"), options::opts::revision | options::opts::depth | options::opts::exclude) { cset included; ============================================================ --- cmd_files.cc af49f7e6f0d8ccc50a5ff9717d7bb9f1b329587b +++ cmd_files.cc 50c18877e69353b9501b675a6c52edc87c236013 @@ -279,7 +279,7 @@ CMD(cat, N_("informative"), // // Error conditions: If the file id specified is unknown or invalid prints // an error message to stderr and exits with status 1. -AUTOMATE(get_file, N_("FILEID"), options::opts::none) +AUTOMATE_WITH_EVERYTHING(get_file, N_("FILEID"), options::opts::none) { N(args.size() == 1, F("wrong argument count")); @@ -302,7 +302,7 @@ AUTOMATE(get_file, N_("FILEID"), options // // Error conditions: If the file id specified is unknown or invalid prints // an error message to stderr and exits with status 1. -AUTOMATE(get_file_of, N_("FILENAME"), options::opts::revision) +AUTOMATE_WITH_EVERYTHING(get_file_of, N_("FILENAME"), options::opts::revision) { N(args.size() == 1, F("wrong argument count")); ============================================================ --- cmd_list.cc 744b63656850bc2337d009044053fc80872c3849 +++ cmd_list.cc b919b1e05461d43248a3ecebb44eb366244eaa7f @@ -580,7 +580,7 @@ namespace // private_location "keystore" // // Error conditions: None. -AUTOMATE(keys, "", options::opts::none) +AUTOMATE_WITH_DATABASE(keys, "", options::opts::none) { N(args.size() == 0, F("no arguments needed")); @@ -591,13 +591,14 @@ AUTOMATE(keys, "", options::opts::none) map, hexenc, vector, vector > > items; - if (app.db.database_specified()) + if (db.database_specified()) { - transaction_guard guard(app.db, false); - app.db.get_key_ids("", dbkeys); + transaction_guard guard(db, false); + db.get_key_ids("", dbkeys); guard.commit(); } - app.keys.get_key_ids("", kskeys); + key_store & keys = db.get_key_store(); + keys.get_key_ids("", kskeys); for (vector::iterator i = dbkeys.begin(); i != dbkeys.end(); i++) @@ -605,7 +606,7 @@ AUTOMATE(keys, "", options::opts::none) base64 pub_encoded; hexenc hash_code; - app.db.get_key(*i, pub_encoded); + db.get_key(*i, pub_encoded); key_hash_code(*i, pub_encoded, hash_code); items[(*i)()].get<0>() = hash_code; items[(*i)()].get<2>().push_back("database"); @@ -616,7 +617,7 @@ AUTOMATE(keys, "", options::opts::none) { keypair kp; hexenc privhash, pubhash; - app.keys.get_key_pair(*i, kp); + keys.get_key_pair(*i, kp); key_hash_code(*i, kp.pub, pubhash); key_hash_code(*i, kp.priv, privhash); items[(*i)()].get<0>() = pubhash; @@ -672,23 +673,23 @@ AUTOMATE(keys, "", options::opts::none) // key, a warning message is printed to stderr. If the revision // specified is unknown or invalid prints an error message to stderr // and exits with status 1. -AUTOMATE(certs, N_("REV"), options::opts::none) +AUTOMATE_WITH_DATABASE(certs, N_("REV"), options::opts::none) { N(args.size() == 1, F("wrong argument count")); vector certs; - transaction_guard guard(app.db, false); + transaction_guard guard(db, false); revision_id rid(idx(args, 0)()); - N(app.db.revision_exists(rid), F("No such revision %s") % rid); + N(db.revision_exists(rid), F("No such revision %s") % rid); hexenc ident(rid.inner()); vector< revision > ts; // FIXME_PROJECTS: after projects are implemented, - // use the app.db version instead if no project is specified. - app.get_project().get_revision_certs(rid, ts); + // use the db version instead if no project is specified. + db.get_project().get_revision_certs(rid, ts); for (size_t i = 0; i < ts.size(); ++i) certs.push_back(idx(ts, i).inner()); @@ -698,7 +699,7 @@ AUTOMATE(certs, N_("REV"), options::opts for (size_t i = 0; i < certs.size(); ++i) { if (checked.find(idx(certs, i).key) == checked.end() && - !app.db.public_key_exists(idx(certs, i).key)) + !db.public_key_exists(idx(certs, i).key)) W(F("no public key '%s' found in database") % idx(certs, i).key); checked.insert(idx(certs, i).key); @@ -714,7 +715,7 @@ AUTOMATE(certs, N_("REV"), options::opts for (size_t i = 0; i < certs.size(); ++i) { basic_io::stanza st; - cert_status status = check_cert(app.db, idx(certs, i)); + cert_status status = check_cert(db, idx(certs, i)); cert_value tv; cert_name name = idx(certs, i).name; set signers; @@ -725,8 +726,8 @@ AUTOMATE(certs, N_("REV"), options::opts signers.insert(keyid); bool trusted = - app.lua.hook_get_revision_cert_trust(signers, ident, - name, tv); + db.hook_get_revision_cert_trust(signers, ident, + name, tv); st.push_str_pair(syms::key, keyid()); ============================================================ --- database.hh 30245ff17a9001e4a57e5a8100d5cb1238dbd26f +++ database.hh 22248ce4347898cba7850b50785602eeff2e37d4 @@ -607,6 +607,7 @@ public: date_t const get_opt_date_or_cur_date(); bool has_opt_branch(); branch_name const & get_opt_branchname(); + bool const get_opt_set_default(); void set_opt_branchname(branch_name const & branchname); key_store & get_key_store();