# # add_file "tests/t_drop_execute.at" # # add_file "tests/t_rename_execute.at" # # patch "ChangeLog" # from [83cc788edad935eaf345c3d194eed69775b99aaf] # to [aad447c995e95bee91c333e72749c2205c1cb063] # # patch "app_state.cc" # from [1352a5df1824518d6d38a3267746a6afa57cb239] # to [4c2f680a945aff091b34bacadff9f864ffb4d427] # # patch "app_state.hh" # from [ca251afc3129d7d5d530a4f96a97abe925fa3841] # to [307bc018301bef3af34b37861a9ac3ffc136061b] # # patch "commands.cc" # from [0f5035f5040dd32e3d297d1f4cbb8e76d08f3b52] # to [c3e1ed8b34967ac9d8e47b00193df64ff6501f80] # # patch "monotone.cc" # from [622baf2c20a7e9fc1304b3078560e90f9bb58e11] # to [bae1632d01014f7bb3bf2490a211476402721b6f] # # patch "options.hh" # from [60f0ccc51cf1a34aff43215840ec24e42cae6374] # to [e3f8114ba090e819215b0b8b370181b273bf16cc] # # patch "tests/t_drop_execute.at" # from [] # to [d9a492fa85d4765c1e62a4bf40806cb22f20816e] # # patch "tests/t_rename_execute.at" # from [] # to [691eb8c88e9c604222199bd7d229fd916cafde3d] # # patch "testsuite.at" # from [a3e066be498cff6ba295c3be4a9877c007e19aa3] # to [741ef98aae7baf028209c07c9ea530a35c34b919] # # patch "work.cc" # from [282514ca3b0a5d94909e209a085e068c2bf985bf] # to [da55f132948c37b84d513337f02ac49f744dcb10] # # patch "work.hh" # from [b632c7b9bda8e2df8b392b3606d554398e6ddb97] # to [882336a3175968ae6faa0e4551e89a5a2769fbaf] # ======================================================================== --- ChangeLog 83cc788edad935eaf345c3d194eed69775b99aaf +++ ChangeLog aad447c995e95bee91c333e72749c2205c1cb063 @@ -1,3 +1,20 @@ +2005-08-26 Richard Levitte + + * options.hh, monotone.cc: Add the '--execute' command-specific + option. + * monotone.cc (cpp_main): ... and process it. + * app_state.hh (class app_state): Add the 'execute' boolean. + * app_state.cc (app_state): Initialise it. + * commands.cc (CMD(drop)): Add '--execute' capability. + * commands.cc (CMD(rename)): Add '--execute' capability. Pass + 'app' to build_rename. + * work.hh, work.cc (build_deletions, build_rename): Do the actual + work. This required the addition of an app_state parameter to + build_rename. + + * tests/t_drop_execute.at, tests/t_rename_execute.at: New tests. + * testsuite.at: Add them. + 2005-08-26 Benoît Dejean * mt_version.cc (print_full_version): Merged strings. ======================================================================== --- app_state.cc 1352a5df1824518d6d38a3267746a6afa57cb239 +++ app_state.cc 4c2f680a945aff091b34bacadff9f864ffb4d427 @@ -35,7 +35,7 @@ : branch_name(""), db(""), stdhooks(true), rcfiles(true), diffs(false), no_merges(false), set_default(false), verbose(false), search_root("/"), depth(-1), last(-1), diff_format(unified_diff), diff_args_provided(false), - use_lca(false) + use_lca(false), execute(false) { db.set_app(this); } ======================================================================== --- app_state.hh ca251afc3129d7d5d530a4f96a97abe925fa3841 +++ app_state.hh 307bc018301bef3af34b37861a9ac3ffc136061b @@ -58,6 +58,7 @@ bool diff_args_provided; utf8 diff_args; bool use_lca; + bool execute; ======================================================================== --- commands.cc 0f5035f5040dd32e3d297d1f4cbb8e76d08f3b52 +++ commands.cc c3e1ed8b34967ac9d8e47b00193df64ff6501f80 @@ -1115,7 +1115,7 @@ } CMD(drop, N_("working copy"), N_("PATH..."), - N_("drop files from working copy"), OPT_NONE) + N_("drop files from working copy"), OPT_EXECUTE) { if (args.size() < 1) throw usage(name); @@ -1143,7 +1143,7 @@ CMD(rename, N_("working copy"), N_("SRC DST"), N_("rename entries in the working copy"), - OPT_NONE) + OPT_EXECUTE) { if (args.size() != 2) throw usage(name); @@ -1156,7 +1156,8 @@ change_set::path_rearrangement work; get_path_rearrangement(work); - build_rename(app.prefix(idx(args, 0)()), app.prefix(idx(args, 1)()), m_old, work); + build_rename(app.prefix(idx(args, 0)()), app.prefix(idx(args, 1)()), m_old, + app, work); put_path_rearrangement(work); ======================================================================== --- monotone.cc 622baf2c20a7e9fc1304b3078560e90f9bb58e11 +++ monotone.cc bae1632d01014f7bb3bf2490a211476402721b6f @@ -66,6 +66,7 @@ {"external", 0, POPT_ARG_NONE, NULL, OPT_EXTERNAL_DIFF, gettext_noop("Use external diff hook for generating diffs"), NULL}, {"diff-args", 0, POPT_ARG_STRING, &argstr, OPT_EXTERNAL_DIFF_ARGS, gettext_noop("Argument to pass external diff hook"), NULL}, {"lca", 0, POPT_ARG_NONE, NULL, OPT_LCA, gettext_noop("Use least common ancestor as ancestor for merge"), NULL}, + {"execute", 'e', POPT_ARG_NONE, NULL, OPT_EXECUTE, gettext_noop("Perform the associated file operation"), NULL}, { NULL, 0, 0, NULL, 0, NULL, NULL } }; @@ -437,6 +438,10 @@ app.use_lca = true; break; + case OPT_EXECUTE: + app.execute = true; + break; + case OPT_HELP: default: requested_help = true; ======================================================================== --- options.hh 60f0ccc51cf1a34aff43215840ec24e42cae6374 +++ options.hh e3f8114ba090e819215b0b8b370181b273bf16cc @@ -42,3 +42,4 @@ #define OPT_EXTERNAL_DIFF 33 #define OPT_EXTERNAL_DIFF_ARGS 34 #define OPT_LCA 35 +#define OPT_EXECUTE 36 ======================================================================== --- tests/t_drop_execute.at +++ tests/t_drop_execute.at d9a492fa85d4765c1e62a4bf40806cb22f20816e @@ -0,0 +1,22 @@ +# -*- Autoconf -*- + +AT_SETUP([drop with actual removal]) + +MONOTONE_SETUP + +ADD_FILE(file0, [file 0 +]) +ADD_FILE(file1, [file 1 +]) +ADD_FILE(file2, [file 2 +]) + +AT_CHECK(MONOTONE drop file0, [], [ignore], [ignore]) +AT_CHECK(MONOTONE drop --execute file1, [], [ignore], [ignore]) +AT_CHECK(MONOTONE drop -e file2, [], [ignore], [ignore]) + +AT_CHECK(test -f file0, [], [ignore], [ignore]) +AT_CHECK(test -f file1, [1], [ignore], [ignore]) +AT_CHECK(test -f file2, [1], [ignore], [ignore]) + +AT_CLEANUP ======================================================================== --- tests/t_rename_execute.at +++ tests/t_rename_execute.at 691eb8c88e9c604222199bd7d229fd916cafde3d @@ -0,0 +1,25 @@ +# -*- Autoconf -*- + +AT_SETUP([rename with actual file rename]) + +MONOTONE_SETUP + +ADD_FILE(file0, [file 0 +]) +ADD_FILE(file1, [file 1 +]) +ADD_FILE(file2, [file 2 +]) + +AT_CHECK(MONOTONE rename file0 newfile0, [], [ignore], [ignore]) +AT_CHECK(MONOTONE rename --execute file1 newfile1, [], [ignore], [ignore]) +AT_CHECK(MONOTONE rename -e file2 newfile2, [], [ignore], [ignore]) + +AT_CHECK(test -f file0, [], [ignore], [ignore]) +AT_CHECK(test -f file1, [1], [ignore], [ignore]) +AT_CHECK(test -f file2, [1], [ignore], [ignore]) +AT_CHECK(test -f newfile0, [1], [ignore], [ignore]) +AT_CHECK(test -f newfile1, [], [ignore], [ignore]) +AT_CHECK(test -f newfile2, [], [ignore], [ignore]) + +AT_CLEANUP ======================================================================== --- testsuite.at a3e066be498cff6ba295c3be4a9877c007e19aa3 +++ testsuite.at 741ef98aae7baf028209c07c9ea530a35c34b919 @@ -694,3 +694,5 @@ m4_include(tests/t_commit_log_writeback.at) m4_include(tests/t_log_brief.at) m4_include(tests/t_explicit_merge_with_anc.at) +m4_include(tests/t_drop_execute.at) +m4_include(tests/t_rename_execute.at) ======================================================================== --- work.cc 282514ca3b0a5d94909e209a085e068c2bf985bf +++ work.cc da55f132948c37b84d513337f02ac49f744dcb10 @@ -1,9 +1,13 @@ +// -*- mode: C++; c-file-style: "gnu"; indent-tabs-mode: nil -*- // copyright (C) 2002, 2003 graydon hoare // all rights reserved. // licensed to the public under the terms of the GNU GPL (>= 2) // see the file COPYING for details #include +#include +#include +#include #include "app_state.hh" #include "basic_io.hh" @@ -227,6 +231,11 @@ updated_attr_map = true; P(F("dropped attributes for file %s from %s\n") % (*i) % attr_file_name); } + if (app.execute) + { + N(unlink((*i)().c_str()) == 0, + F("Can't remove %s: %s\n") % (*i) % strerror(errno)); + } } } @@ -246,6 +255,7 @@ build_rename(file_path const & src, file_path const & dst, manifest_map const & man, + app_state & app, change_set::path_rearrangement & pr) { N(src() != "", F("invalid source path ''")); @@ -271,6 +281,12 @@ else pr_new.renamed_files.insert(std::make_pair(src, dst)); + if (app.execute) + { + N(rename(src().c_str(), dst().c_str()) == 0, + F("Can't rename %s to %s: %s\n") % src % dst % strerror(errno)); + } + // read attribute map if available file_path attr_path; get_attr_path(attr_path); ======================================================================== --- work.hh b632c7b9bda8e2df8b392b3606d554398e6ddb97 +++ work.hh 882336a3175968ae6faa0e4551e89a5a2769fbaf @@ -1,3 +1,4 @@ +// -*- mode: C++; c-file-style: "gnu"; indent-tabs-mode: nil -*- #ifndef __WORK_HH__ #define __WORK_HH__ @@ -73,6 +74,7 @@ build_rename(file_path const & src, file_path const & dst, manifest_map const & m_old, + app_state & app, change_set::path_rearrangement & pr);