# # # patch "cmd_ws_commit.cc" # from [7c6997b990823c878080f41b0428b2543fa0c896] # to [ce019f49e97a8c71d3d9d19d0afc33bd46817c57] # # patch "lua_hooks.cc" # from [2ba09f87d8dc16a1957cad5abc98565a7c87cc7c] # to [dc0d5dceb92785510424748bc47f9859b501e7e0] # # patch "lua_hooks.hh" # from [7442504bf6a1fff7e6afe120d6883198f5303842] # to [d7a51b560d2270dd6b1feee7ff0947a3e7286f73] # # patch "std_hooks.lua" # from [7d02599c61fce706fbf058f315265bd59fbb8b25] # to [71b3a2c236cff5b4de789fe14ad6371621d8c38b] # ============================================================ --- cmd_ws_commit.cc 7c6997b990823c878080f41b0428b2543fa0c896 +++ cmd_ws_commit.cc ce019f49e97a8c71d3d9d19d0afc33bd46817c57 @@ -718,8 +718,25 @@ CMD(attr, N_("workspace"), N_("set PATH throw usage(name); } +CMD(patch, N_("workspace"), N_("[DIFF FILE]"), + N_("apply a diff/patch file to a workspace and record" + "added or removed files"), + options::opts::none) +{ + N((args.size() == 1), + F("Please supply _one_ diff file to patch with")); + system_path patch_file(idx(args,0)); + require_path_is_file(patch_file, + F("patch file %s doesn't exist") % patch_file, + F("patch file %s is a directory") % patch_file); + + app.require_workspace(); + + app.lua.hook_patch_workspace(patch_file); +} + CMD(commit, N_("workspace"), N_("[PATH]..."), N_("commit workspace to database"), options::opts::branch | options::opts::message | options::opts::msgfile | options::opts::date ============================================================ --- lua_hooks.cc 2ba09f87d8dc16a1957cad5abc98565a7c87cc7c +++ lua_hooks.cc dc0d5dceb92785510424748bc47f9859b501e7e0 @@ -281,6 +281,17 @@ bool } bool +lua_hooks::hook_patch_workspace(system_path const & patch_file) +{ + bool exec_ok = Lua(st) + .func("patch_workspace") + .push_str(patch_file.as_external()) + .call(1,0) + .ok(); + return exec_ok; +} + +bool lua_hooks::hook_edit_comment(external const & commentary, external const & user_log_message, external & result) ============================================================ --- lua_hooks.hh 7442504bf6a1fff7e6afe120d6883198f5303842 +++ lua_hooks.hh d7a51b560d2270dd6b1feee7ff0947a3e7286f73 @@ -47,6 +47,7 @@ public: bool hook_get_branch_key(cert_value const & branchname, rsa_keypair_id & k); bool hook_get_passphrase(rsa_keypair_id const & k, std::string & phrase); bool hook_get_author(cert_value const & branchname, std::string & author); + bool hook_patch_workspace(system_path const & patch_file); bool hook_edit_comment(external const & commentary, external const & user_log_message, external & result); ============================================================ --- std_hooks.lua 7d02599c61fce706fbf058f315265bd59fbb8b25 +++ std_hooks.lua 71b3a2c236cff5b4de789fe14ad6371621d8c38b @@ -233,6 +233,24 @@ end return "^[[:alnum:]$_]" end +function patch_workspace(patch_file) + local exe = nil + if (program_exists_in_path("patch")) then exe = "patch" end + + if (exe == nil) then + io.write(string.format(gettext("couldn't find a suitable patch tool"))) + end + + io.write("using patch file: " .. patch_file) + + if (execute(exe, "-p0", "-i", patch_file) ~= 0) then + io.write(string.format(gettext("Error running patch tool '%s'\n"), exe)) + return false + end + + return true +end + function edit_comment(basetext, user_log_message) local exe = nil if (program_exists_in_path("vi")) then exe = "vi" end