#
#
# delete "automate.hh"
#
# patch "ChangeLog"
# from [4d27cfc4d0f993af37e7931e28b23d744bad9826]
# to [34e985d5726e7c0f57e125ac0919b3d940a6a193]
#
# patch "Makefile.am"
# from [4098b391db7d342c7b043719248de79b40b5a1be]
# to [d8df863b2e01eeb1bf82bf4826aefb59ed75de6d]
#
# patch "automate.cc"
# from [8b18ec025d8bd4fe2a1a100de6f4bc8243911933]
# to [a416a0118ff66f167504e583eda3d2f19a2a24c9]
#
# patch "cmd.hh"
# from [7c227eab1cfe03fc9c73ca144270119bb0d69568]
# to [b9f35eeccf525a4bc9dc9253a00989998e8bcb91]
#
# patch "cmd_automate.cc"
# from [4ef7d2e08406ddc3dcfa5adc589285f1a39dddbe]
# to [eca8e2b625e400ec961c9a2c9772097dbff8351c]
#
# patch "cmd_list.cc"
# from [735a51c0fb2d30044075a34c908e639751adcc60]
# to [9f507eccb08b8547c27b4056bedeb47036e5a61f]
#
============================================================
--- ChangeLog 4d27cfc4d0f993af37e7931e28b23d744bad9826
+++ ChangeLog 34e985d5726e7c0f57e125ac0919b3d940a6a193
@@ -1,3 +1,19 @@
+2006-06-17 Timothy Brownawell
+
+ (see bug #15995, asking for a more comprehensive automate command set)
+ Start splitting up automate.cc . There is now an AUTOMATE() macro in
+ cmd.hh , similar to the CMD() macro. Individual automate commands can
+ share a file with similar command-line commands, and many commands can
+ be factored into an implementation with CMD() and AUTOMATE() wrappers
+ to format input/output.
+ * cmd.hh: Add stuff needed to define a new automate command.
+ * cmd_automate.cc: This gets automate infrastructure similar to
+ what commands.cc is for command-line commands. And automate stdio.
+ * cmd_list.cc: "keys" and "certs" automate commands go here
+ * automate.hh: No longer needed.
+ * automate.cc: use AUTOMATE() macro for the automate commands that
+ haven't got a new home yet.
+
2006-06-16 Richard Levitte
* examples/display_branches.lua: Enhanced to display how many
============================================================
--- Makefile.am 4098b391db7d342c7b043719248de79b40b5a1be
+++ Makefile.am d8df863b2e01eeb1bf82bf4826aefb59ed75de6d
@@ -48,7 +48,7 @@
cset.cc cset.hh \
roster.cc roster.hh \
mt_version.cc mt_version.hh \
- automate.cc automate.hh \
+ automate.cc \
database_check.cc database_check.hh \
epoch.cc epoch.hh \
inodeprint.cc inodeprint.hh \
============================================================
--- automate.cc 8b18ec025d8bd4fe2a1a100de6f4bc8243911933
+++ automate.cc a416a0118ff66f167504e583eda3d2f19a2a24c9
@@ -22,6 +22,7 @@
#include "app_state.hh"
#include "basic_io.hh"
#include "cert.hh"
+#include "cmd.hh"
#include "commands.hh"
#include "constants.hh"
#include "keys.hh"
@@ -49,29 +50,7 @@
using std::string;
using std::vector;
-static string const interface_version = "2.1";
-// Name: interface_version
-// Arguments: none
-// Added in: 0.0
-// Purpose: Prints version of automation interface. Major number increments
-// whenever a backwards incompatible change is made; minor number increments
-// whenever any change is made (but is reset when major number increments).
-// Output format: ".\n". Always matches
-// "[0-9]+\.[0-9]+\n".
-// Error conditions: None.
-static void
-automate_interface_version(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
-{
- if (args.size() != 0)
- throw usage(help_name);
-
- output << interface_version << endl;
-}
-
// Name: heads
// Arguments:
// 1: branch name (optional, default branch is used if non-existant)
@@ -81,11 +60,7 @@
// newline. Revision ids are printed in alphabetically sorted order.
// Error conditions: If the branch does not exist, prints nothing. (There are
// no heads.)
-static void
-automate_heads(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(heads)
{
if (args.size() > 1)
throw usage(help_name);
@@ -109,11 +84,7 @@
// 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.
-static void
-automate_ancestors(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(ancestors)
{
if (args.size() == 0)
throw usage(help_name);
@@ -160,11 +131,7 @@
// 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.
-static void
-automate_descendents(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(descendents)
{
if (args.size() == 0)
throw usage(help_name);
@@ -212,11 +179,7 @@
// 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.
-static void
-automate_erase_ancestors(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(erase_ancestors)
{
set revs;
for (vector::const_iterator i = args.begin(); i != args.end(); ++i)
@@ -239,11 +202,7 @@
// Output format: A list of file names in alphabetically sorted order,
// or a list of attributes if a file name provided.
// Error conditions: If the file name has no attributes, prints nothing.
-static void
-automate_attributes(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(attributes)
{
if (args.size() > 1)
throw usage(help_name);
@@ -293,11 +252,7 @@
// 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.
-static void
-automate_toposort(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(toposort)
{
set revs;
for (vector::const_iterator i = args.begin(); i != args.end(); ++i)
@@ -329,11 +284,7 @@
// 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.
-static void
-automate_ancestry_difference(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(ancestry_difference)
{
if (args.size() == 0)
throw usage(help_name);
@@ -372,11 +323,7 @@
// 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.
-static void
-automate_leaves(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(leaves)
{
if (args.size() != 0)
throw usage(help_name);
@@ -404,11 +351,7 @@
// 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.
-static void
-automate_parents(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(parents)
{
if (args.size() != 1)
throw usage(help_name);
@@ -432,11 +375,7 @@
// 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.
-static void
-automate_children(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(children)
{
if (args.size() != 1)
throw usage(help_name);
@@ -470,11 +409,7 @@
// The output as a whole is alphabetically sorted; additionally, the parents
// within each line are alphabetically sorted.
// Error conditions: None.
-static void
-automate_graph(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(graph)
{
if (args.size() != 0)
throw usage(help_name);
@@ -517,11 +452,7 @@
// 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.
-static void
-automate_select(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(select)
{
if (args.size() != 1)
throw usage(help_name);
@@ -703,11 +634,7 @@
// Error conditions: If no workspace book keeping _MTN directory is found,
// prints an error message to stderr, and exits with status 1.
-static void
-automate_inventory(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(inventory)
{
if (args.size() != 0)
throw usage(help_name);
@@ -826,137 +753,6 @@
}
}
-namespace
-{
- namespace syms
- {
- symbol const key("key");
- symbol const signature("signature");
- symbol const name("name");
- symbol const value("value");
- symbol const trust("trust");
-
- symbol const public_hash("public_hash");
- symbol const private_hash("private_hash");
- symbol const public_location("public_location");
- symbol const private_location("private_location");
- }
-};
-
-// Name: certs
-// Arguments:
-// 1: a revision id
-// Added in: 1.0
-// Purpose: Prints all certificates associated with the given revision
-// ID. Each certificate is contained in a basic IO stanza. For each
-// certificate, the following values are provided:
-//
-// 'key' : a string indicating the key used to sign this certificate.
-// 'signature': a string indicating the status of the signature.
-// Possible values of this string are:
-// 'ok' : the signature is correct
-// 'bad' : the signature is invalid
-// 'unknown' : signature was made with an unknown key
-// 'name' : the name of this certificate
-// 'value' : the value of this certificate
-// 'trust' : is this certificate trusted by the defined trust metric
-// Possible values of this string are:
-// 'trusted' : this certificate is trusted
-// 'untrusted' : this certificate is not trusted
-//
-// Output format: All stanzas are formatted by basic_io. Stanzas are
-// seperated by a blank line. Values will be escaped, '\' -> '\\' and
-// '"' -> '\"'.
-//
-// Error conditions: If a certificate is signed with an unknown public
-// 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.
-static void
-automate_certs(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
-{
- if (args.size() != 1)
- throw usage(help_name);
-
- vector certs;
-
- transaction_guard guard(app.db, false);
-
- revision_id rid(idx(args, 0)());
- N(app.db.revision_exists(rid), F("No such revision %s") % rid);
- hexenc ident(rid.inner());
-
- vector< revision > ts;
- app.db.get_revision_certs(rid, ts);
- for (size_t i = 0; i < ts.size(); ++i)
- certs.push_back(idx(ts, i).inner());
-
- {
- set checked;
- 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))
- W(F("no public key '%s' found in database")
- % idx(certs, i).key);
- checked.insert(idx(certs, i).key);
- }
- }
-
- // Make the output deterministic; this is useful for the test suite,
- // in particular.
- sort(certs.begin(), certs.end());
-
- basic_io::printer pr;
-
- for (size_t i = 0; i < certs.size(); ++i)
- {
- basic_io::stanza st;
- cert_status status = check_cert(app, idx(certs, i));
- cert_value tv;
- cert_name name = idx(certs, i).name();
- set signers;
-
- decode_base64(idx(certs, i).value, tv);
-
- rsa_keypair_id keyid = idx(certs, i).key();
- signers.insert(keyid);
-
- bool trusted =
- app.lua.hook_get_revision_cert_trust(signers, ident,
- name, tv);
-
- st.push_str_pair(syms::key, keyid());
-
- string stat;
- switch (status)
- {
- case cert_ok:
- stat = "ok";
- break;
- case cert_bad:
- stat = "bad";
- break;
- case cert_unknown:
- stat = "unknown";
- break;
- }
- st.push_str_pair(syms::signature, stat);
-
- st.push_str_pair(syms::name, name());
- st.push_str_pair(syms::value, tv());
- st.push_str_pair(syms::trust, (trusted ? "trusted" : "untrusted"));
-
- pr.print_stanza(st);
- }
- output.write(pr.buf.data(), pr.buf.size());
-
- guard.commit();
-}
-
// Name: get_revision
// Arguments:
// 1: a revision id (optional, determined from the workspace if
@@ -1020,11 +816,7 @@
// 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.
-static void
-automate_get_revision(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(get_revision)
{
if (args.size() > 1)
throw usage(help_name);
@@ -1068,11 +860,7 @@
// 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.
-static void
-automate_get_base_revision_id(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(get_base_revision_id)
{
if (args.size() > 0)
throw usage(help_name);
@@ -1093,11 +881,7 @@
// 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.
-static void
-automate_get_current_revision_id(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(get_current_revision_id)
{
if (args.size() > 0)
throw usage(help_name);
@@ -1162,11 +946,7 @@
//
// Error conditions: If the revision ID specified is unknown or
// invalid prints an error message to stderr and exits with status 1.
-static void
-automate_get_manifest_of(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(get_manifest_of)
{
if (args.size() > 1)
throw usage(help_name);
@@ -1209,11 +989,7 @@
//
// Error conditions: If the file id specified is unknown or invalid prints
// an error message to stderr and exits with status 1.
-static void
-automate_get_file(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(get_file)
{
if (args.size() != 1)
throw usage(help_name);
@@ -1239,11 +1015,7 @@
//
// Error conditions: If the revision id specified is unknown or
// invalid prints an error message to stderr and exits with status 1.
-static void
-automate_packet_for_rdata(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(packet_for_rdata)
{
if (args.size() != 1)
throw usage(help_name);
@@ -1269,11 +1041,7 @@
//
// Error conditions: If the revision id specified is unknown or
// invalid prints an error message to stderr and exits with status 1.
-static void
-automate_packets_for_certs(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(packets_for_certs)
{
if (args.size() != 1)
throw usage(help_name);
@@ -1300,11 +1068,7 @@
//
// Error conditions: If the file id specified is unknown or invalid
// prints an error message to stderr and exits with status 1.
-static void
-automate_packet_for_fdata(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(packet_for_fdata)
{
if (args.size() != 1)
throw usage(help_name);
@@ -1331,11 +1095,7 @@
//
// Error conditions: If any of the file ids specified are unknown or
// invalid prints an error message to stderr and exits with status 1.
-static void
-automate_packet_for_fdelta(vector args,
- string const & help_name,
- app_state & app,
- ostream & output)
+AUTOMATE(packet_for_fdelta)
{
if (args.size() != 2)
throw usage(help_name);
@@ -1357,328 +1117,6 @@
pw.consume_file_delta(f_old_id, f_new_id, file_delta(del));
}
-void
-automate_command(utf8 cmd, vector args,
- string const & root_cmd_name,
- app_state & app,
- ostream & output);
-
-// Name: stdio
-// Arguments: none
-// Added in: 1.0
-// Purpose: Allow multiple automate commands to be run from one instance
-// of monotone.
-//
-// Input format: The input is a series of lines of the form
-// 'l'':'[':'...]'e', with characters
-// after the 'e' of one command, but before the 'l' of the next ignored.
-// This space is reserved, and should not contain characters other
-// than '\n'.
-// Example:
-// l6:leavese
-// l7:parents40:0e3171212f34839c2e3263e7282cdeea22fc5378e
-//
-// Output format: ::::