# # # patch "cmd_db.cc" # from [bc7f46a061d987e96a55928be3126023ed822e97] # to [f61dfeb6fd035dd3a468fd5fff35d42407b6575a] # # patch "commands.cc" # from [4f44d6e25ecf86d1dff7d847fc9f168eea639555] # to [0c6893af4d16629b742caa05f541bc5c71977895] # ============================================================ --- cmd_db.cc bc7f46a061d987e96a55928be3126023ed822e97 +++ cmd_db.cc f61dfeb6fd035dd3a468fd5fff35d42407b6575a @@ -45,84 +45,192 @@ kill_rev_locally(app_state& app, string app.db.delete_existing_rev_and_certs(ident); } -CMD(db, "", CMD_REF(database), - N_("init\n" - "info\n" - "version\n" - "dump\n" - "load\n" - "migrate\n" - "execute\n" - "kill_rev_locally ID\n" - "kill_branch_certs_locally BRANCH\n" - "kill_tag_locally TAG\n" - "check\n" - "changesetify\n" - "rosterify\n" - "regenerate_caches\n" - "set_epoch BRANCH EPOCH\n"), - N_("Manipulates database state"), - N_("This set of commands are used to create and maintain the database " - "that monotone uses to maintain the certificates' data."), +CMD(init, "", CMD_REF(database), "", + N_("Initializes a database"), + N_("Creates a new database file and initializes it."), + options::opts::none) +{ + N(args.size() == 0, + F("no arguments needed")); + + app.db.initialize(); +} + +CMD(info, "", CMD_REF(database), "", + N_("Shows information about the database"), + N_(""), + options::opts::none) +{ + N(args.size() == 0, + F("no arguments needed")); + + app.db.info(cout); +} + +CMD(version, "", CMD_REF(database), "", + N_("Shows the database's version"), + N_(""), + options::opts::none) +{ + N(args.size() == 0, + F("no arguments needed")); + + app.db.version(cout); +} + +CMD(dump, "", CMD_REF(database), "", + N_("Dumps the contents of the database"), + N_("Generates a list of SQL instructions that represent the whole " + "contents of the database. The resulting output is useful to later " + "restore the database from a text file that serves as a backup."), + options::opts::none) +{ + N(args.size() == 0, + F("no arguments needed")); + + app.db.dump(cout); +} + +CMD(load, "", CMD_REF(database), "", + N_("Loads the contents of the database"), + N_("Reads a list of SQL instructions that regenerate the contents of " + "the database. This is supposed to be used in conjunction with the " + "output generated by the 'dump' command."), + options::opts::none) +{ + N(args.size() == 0, + F("no arguments needed")); + + app.db.load(cin); +} + +CMD(migrate, "", CMD_REF(database), "", + N_("Migrates the database to a newer schema"), + N_("Updates the database's internal schema to the most recent one. " + "Needed to automatically resolve incompatibilities that may be " + "introduced in newer versions of monotone."), + options::opts::none) +{ + N(args.size() == 0, + F("no arguments needed")); + + app.db.migrate(); +} + +CMD(execute, "", CMD_REF(database), "", + N_("Executes an SQL command on the database"), + N_("Directly executes the given SQL command on the database"), + options::opts::none) +{ + if (args.size() != 1) + throw usage(execid); + + app.db.debug(idx(args, 0)(), cout); +} + +CMD(kill_rev_locally, "", CMD_REF(database), "ID", + N_("Kills a revision from the local database"), + N_(""), + options::opts::none) +{ + if (args.size() != 1) + throw usage(execid); + + kill_rev_locally(app,idx(args, 0)()); +} + +CMD(kill_branch_certs_locally, "", CMD_REF(database), "BRANCH", + N_("Kills branch certificates from the local database"), + N_(""), + options::opts::none) +{ + if (args.size() != 1) + throw usage(execid); + + app.db.delete_branch_named(cert_value(idx(args, 0)())); +} + +CMD(kill_tag_locally, "", CMD_REF(database), "TAG", + N_("Kills a tag from the local database"), + N_(""), + options::opts::none) +{ + if (args.size() != 1) + throw usage(execid); + + app.db.delete_tag_named(cert_value(idx(args, 0)())); +} + +CMD(check, "", CMD_REF(database), "", + N_("Does some sanity checks on the database"), + N_("Ensures that the database is consistent by issuing multiple " + "checks."), + options::opts::none) +{ + N(args.size() == 0, + F("no arguments needed")); + + check_db(app); +} + +CMD(changesetify, "", CMD_REF(database), "", + N_("Converts the database to the changeset format"), + N_(""), + options::opts::none) +{ + N(args.size() == 0, + F("no arguments needed")); + + build_changesets_from_manifest_ancestry(app); +} + +CMD(rosterify, "", CMD_REF(database), "", + N_("Converst the database to the rosters format"), + N_(""), options::opts::drop_attr) { - if (args.size() == 1) - { - if (idx(args, 0)() == "init") - app.db.initialize(); - else if (idx(args, 0)() == "info") - app.db.info(cout); - else if (idx(args, 0)() == "version") - app.db.version(cout); - else if (idx(args, 0)() == "dump") - app.db.dump(cout); - else if (idx(args, 0)() == "load") - app.db.load(cin); - else if (idx(args, 0)() == "migrate") - app.db.migrate(); - else if (idx(args, 0)() == "check") - check_db(app); - else if (idx(args, 0)() == "changesetify") - build_changesets_from_manifest_ancestry(app); - else if (idx(args, 0)() == "rosterify") - build_roster_style_revs_from_manifest_style_revs(app); - else if (idx(args, 0)() == "regenerate_caches") - regenerate_caches(app); - else - throw usage(execid); - } - else if (args.size() == 2) - { - if (idx(args, 0)() == "execute") - app.db.debug(idx(args, 1)(), cout); - else if (idx(args, 0)() == "kill_rev_locally") - kill_rev_locally(app,idx(args, 1)()); - else if (idx(args, 0)() == "clear_epoch") - app.db.clear_epoch(branch_name(idx(args, 1)())); - else if (idx(args, 0)() == "kill_branch_certs_locally") - app.db.delete_branch_named(cert_value(idx(args, 1)())); - else if (idx(args, 0)() == "kill_tag_locally") - app.db.delete_tag_named(cert_value(idx(args, 1)())); - else - throw usage(execid); - } - else if (args.size() == 3) - { - if (idx(args, 0)() == "set_epoch") - { - epoch_data ed(idx(args,2)()); - N(ed.inner()().size() == constants::epochlen, - F("The epoch must be %s characters") - % constants::epochlen); - app.db.set_epoch(branch_name(idx(args, 1)()), ed); - } - else - throw usage(execid); - } - else + N(args.size() == 0, + F("no arguments needed")); + + build_roster_style_revs_from_manifest_style_revs(app); +} + +CMD(regenerate_caches, "", CMD_REF(database), "", + N_("Regenerates the caches stored in the database"), + N_(""), + options::opts::none) +{ + N(args.size() == 0, + F("no arguments needed")); + + regenerate_caches(app); +} + +CMD_HIDDEN(clear_epoch, "", CMD_REF(database), "BRANCH", + N_("Clears the database's epoch"), + N_(""), + options::opts::none) +{ + if (args.size() != 1) throw usage(execid); + + app.db.clear_epoch(branch_name(idx(args, 0)())); } +CMD(set_epoch, "", CMD_REF(database), "BRANCH EPOCH", + N_("Sets the database's epoch"), + N_(""), + options::opts::none) +{ + if (args.size() != 2) + throw usage(execid); + + epoch_data ed(idx(args, 1)()); + N(ed.inner()().size() == constants::epochlen, + F("The epoch must be %s characters") % constants::epochlen); + app.db.set_epoch(branch_name(idx(args, 0)()), ed); +} + CMD(set, "", CMD_REF(variables), N_("DOMAIN NAME VALUE"), N_("Sets a database variable"), N_("This command modifies (or adds if it did not exist before) the " ============================================================ --- commands.cc 4f44d6e25ecf86d1dff7d847fc9f168eea639555 +++ commands.cc 0c6893af4d16629b742caa05f541bc5c71977895 @@ -49,7 +49,7 @@ CMD_GROUP(automation, "", CMD_REF(__root N_("Commands that aid in scripted execution"), N_(""), options::opts::none); -CMD_GROUP(database, "", CMD_REF(__root__), +CMD_GROUP(database, "db", CMD_REF(__root__), N_("Commands that manipulate the database"), N_(""), options::opts::none);