# # # patch "ChangeLog" # from [5f8f3954c40358b385b7ea0817cb9342367bc854] # to [c350cf87b3ddd00d291aa2d7a348af2197944ffc] # # patch "automate.cc" # from [a6332c5bb3ceb42b9829830ae0935794086e3f2a] # to [a25464bad18217cff5bf90efd6fe3371f6dd2f6c] # # patch "cmd_files.cc" # from [12243e3b47340b2aa81cd8e26f40559fad0ab51d] # to [0a5292106bbf14f1457573bc976fbf74d4bd60fe] # ============================================================ --- ChangeLog 5f8f3954c40358b385b7ea0817cb9342367bc854 +++ ChangeLog c350cf87b3ddd00d291aa2d7a348af2197944ffc @@ -1,3 +1,10 @@ +2006-11-20 Thomas Keller + + * moved automate get_file into cmd_files.cc + * new automate command get_file_of which is basically mtn cat + * replaced exception by user error for get_file and get_file_of + if no arguments are given + 2006-11-18 Richard Levitte * debian/monotone-server.monotone.init (d_start): Remove the ============================================================ --- automate.cc a6332c5bb3ceb42b9829830ae0935794086e3f2a +++ automate.cc a25464bad18217cff5bf90efd6fe3371f6dd2f6c @@ -1053,31 +1053,6 @@ AUTOMATE(get_manifest_of, N_("[REVID]"), } -// Name: get_file -// Arguments: -// 1: a file id -// Added in: 1.0 -// Purpose: Prints the contents of the specified file. -// -// Output format: The file contents are output without modification. -// -// 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) -{ - if (args.size() != 1) - throw usage(help_name); - - file_id ident(idx(args, 0)()); - N(app.db.file_version_exists(ident), - F("no file version %s found in database") % ident); - - file_data dat; - L(FL("dumping file %s") % ident); - app.db.get_file_version(ident, dat); - output.write(dat.inner()().data(), dat.inner()().size()); -} - // Name: packet_for_rdata // Arguments: // 1: a revision id ============================================================ --- cmd_files.cc 12243e3b47340b2aa81cd8e26f40559fad0ab51d +++ cmd_files.cc 0a5292106bbf14f1457573bc976fbf74d4bd60fe @@ -178,24 +178,21 @@ CMD(identify, N_("debug"), N_("[PATH]"), cout << ident << "\n"; } -CMD(cat, N_("informative"), - N_("FILENAME"), - N_("write file from database to stdout"), - options::opts::revision) +static void +dump_file(std::ostream & output, app_state & app, file_id & ident) { - if (args.size() != 1) - throw usage(name); + N(app.db.file_version_exists(ident), + F("no file version %s found in database") % ident); - if (app.opts.revision_selectors.size() == 0) - app.require_workspace(); + file_data dat; + L(FL("dumping file %s") % ident); + app.db.get_file_version(ident, dat); + output.write(dat.inner()().data(), dat.inner()().size()); +} - transaction_guard guard(app.db, false); - - revision_id rid; - if (app.opts.revision_selectors.size() == 0) - app.work.get_revision_id(rid); - else - complete(app, idx(app.opts.revision_selectors, 0)(), rid); +static void +dump_file(std::ostream & output, app_state & app, revision_id rid, utf8 filename) +{ N(app.db.revision_exists(rid), F("no such revision '%s'") % rid); @@ -203,26 +200,93 @@ CMD(cat, N_("informative"), // workspace, but as project-rooted external ones otherwise. file_path fp; split_path sp; - fp = file_path_external(idx(args, 0)); + fp = file_path_external(filename); fp.split(sp); roster_t roster; marking_map marks; app.db.get_roster(rid, roster, marks); - N(roster.has_node(sp), F("no file '%s' found in revision '%s'") % fp % rid); + N(roster.has_node(sp), + F("no file '%s' found in revision '%s'") % fp % rid); + node_t node = roster.get_node(sp); - N((!null_node(node->self) && is_file_t(node)), F("no file '%s' found in revision '%s'") % fp % rid); + N((!null_node(node->self) && is_file_t(node)), + F("no file '%s' found in revision '%s'") % fp % rid); file_t file_node = downcast_to_file_t(node); - file_id ident = file_node->content; - file_data dat; - L(FL("dumping file '%s'") % ident); - app.db.get_file_version(ident, dat); - cout.write(dat.inner()().data(), dat.inner()().size()); + dump_file(output, app, file_node->content); +} - guard.commit(); +CMD(cat, N_("informative"), + N_("FILENAME"), + N_("write file from database to stdout"), + options::opts::revision) +{ + if (args.size() != 1) + throw usage(name); + + revision_id rid; + if (app.opts.revision_selectors.size() == 0) + { + app.require_workspace(); + app.work.get_revision_id(rid); + } + else + complete(app, idx(app.opts.revision_selectors, 0)(), rid); + + dump_file(cout, app, rid, idx(args, 0)); } +// Name: get_file +// Arguments: +// 1: a file id +// Added in: 1.0 +// Purpose: Prints the contents of the specified file. +// +// Output format: The file contents are output without modification. +// +// 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) +{ + N(args.size() == 1, + F("no argument given")); + + file_id ident(idx(args, 0)()); + dump_file(output, app, ident); +} + +// Name: get_fileof +// Arguments: +// 1: a filename +// +// Options: +// r: a revision id +// +// Added in: 4.0 +// Purpose: Prints the contents of the specified file. +// +// Output format: The file contents are output without modification. +// +// 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) +{ + N(args.size() == 1, + F("no argument given")); + + revision_id rid; + if (app.opts.revision_selectors.size() == 0) + { + app.require_workspace(); + app.work.get_revision_id(rid); + } + else + complete(app, idx(app.opts.revision_selectors, 0)(), rid); + + dump_file(output, app, rid, idx(args, 0)); +} + // Local Variables: // mode: C++ // fill-column: 76