# # old_revision [386bd5fab3b55635765c1f0bc3beddbe970afc8d] # # add_dir "tests/calculation_of_unidiffs_start_of_file" # # add_file "tests/calculation_of_unidiffs_start_of_file/__driver__.lua" # content [a675e225e338ba2da4d3af809cbca8b9934739d1] # # add_file "tests/calculation_of_unidiffs_start_of_file/firstfile" # content [b556393474ffd1133a0d72c549e5ef4b0346d05f] # # add_file "tests/calculation_of_unidiffs_start_of_file/secondfile" # content [43fbdbec8b75ae97def329110b462353419ad3e2] # # patch "diff_patch.cc" # from [5437f74550a59622f0aca36b00dd43f104b7692a] # to [827f8dbf2c922582e983b2207f7cf2abd45e7d4b] # ============================================================ --- tests/calculation_of_unidiffs_start_of_file/__driver__.lua a675e225e338ba2da4d3af809cbca8b9934739d1 +++ tests/calculation_of_unidiffs_start_of_file/__driver__.lua a675e225e338ba2da4d3af809cbca8b9934739d1 @@ -0,0 +1,26 @@ + +skip_if(not existsonpath("patch")) + +mtn_setup() + +-- get first file and commit to db +check(get("firstfile", "testfile")) +check(mtn("add", "testfile"), 0, false, false) +commit() +rename("testfile", "firstfile") + +-- get second file +check(get("secondfile", "testfile")) + +-- calculate diff to second file using monotone +check(mtn("diff"), 0, true) +canonicalize("stdout") +rename("stdout", "monodiff") +rename("testfile", "secondfile") + +-- see if patch likes that +rename("monodiff", "stdin") +check({"patch", "firstfile"}, 0, false, false, true) + +-- see if the resulting file has been properly patched +check(samefile("firstfile", "secondfile")) ============================================================ --- tests/calculation_of_unidiffs_start_of_file/firstfile b556393474ffd1133a0d72c549e5ef4b0346d05f +++ tests/calculation_of_unidiffs_start_of_file/firstfile b556393474ffd1133a0d72c549e5ef4b0346d05f @@ -0,0 +1,112 @@ +#ifndef __APP_STATE_HH__ +#define __APP_STATE_HH__ + +// Copyright (C) 2002 Graydon Hoare +// +// This program is made available under the GNU GPL version 2.0 or +// greater. See the accompanying file COPYING for details. +// +// This program is distributed WITHOUT ANY WARRANTY; without even the +// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. + +class app_state; +class lua_hooks; + +#include +#include + +#include + +#include "database.hh" +#include "key_store.hh" +#include "lua_hooks.hh" +#include "options.hh" +#include "paths.hh" +#include "project.hh" +#include "vocab.hh" +#include "work.hh" +#include "ssh_agent.hh" + +namespace Botan +{ + class PK_Signer; + class RSA_PrivateKey; + class PK_Verifier; + class RSA_PublicKey; +}; + +// This class is supposed to hold all (or.. well, most) of the state +// of the application, barring some unfortunate static objects like +// the debugging / logging system and the command objects, for the +// time being. The vague intent being to make life easier for anyone +// who wants to embed this program as a library someday. + +class app_state +{ +public: + database db; + lua_hooks lua; + key_store keys; + workspace work; + ssh_agent agent; + + options opts; + + bool found_workspace; + bool branch_is_sticky; + + // These are used to cache signers/verifiers (if the hook allows). + // They can't be function-static variables in key.cc, since they + // must be destroyed before the Botan deinitialize() function is + // called. + + std::map, + boost::shared_ptr > > signers; + std::map, + boost::shared_ptr > > verifiers; + + void allow_workspace(); + void process_options(); + void require_workspace(std::string const & explanation = ""); + void create_workspace(system_path const & dir); + + // Set the branch name. If you only invoke set_branch, the branch + // name is not sticky (and won't be written to the workspace and + // reused by subsequent monotone invocations). Commands which + // switch the working to a different branch should invoke + // make_branch_sticky (before require_workspace because this + // function updates the workspace). + + void make_branch_sticky(); + +private: + project_t project; +public: + //project_t & get_project(string const & name); + project_t & get_project(); // get_project(opts.project) or I() + + void set_database(system_path const & filename); + void set_key_dir(system_path const & filename); + void set_root(system_path const & root); + void set_diff_format(diff_type dtype); + + explicit app_state(); + ~app_state(); + +private: + void load_rcfiles(); + void write_options(); +}; + +// Local Variables: +// mode: C++ +// fill-column: 76 +// c-file-style: "gnu" +// indent-tabs-mode: nil +// End: +// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: + +#endif // __APP_STATE_HH__ ============================================================ --- tests/calculation_of_unidiffs_start_of_file/secondfile 43fbdbec8b75ae97def329110b462353419ad3e2 +++ tests/calculation_of_unidiffs_start_of_file/secondfile 43fbdbec8b75ae97def329110b462353419ad3e2 @@ -0,0 +1,112 @@ +#ifndef __APP_STATE_HH__ +#define __APP_STATE_HH__ + +// Copyright (C) 2002 Graydon Hoare +// +// This program is made available under the GNU GPL version 2.0 or +// +// greater. See the accompanying file COPYING for details. +// +// This program is distributed WITHOUT ANY WARRANTY; without even the +// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. + +class app_state; +class lua_hooks; + +#include +#include + +#include + +#include "database.hh" +#include "key_store.hh" +#include "lua_hooks.hh" +#include "options.hh" +#include "paths.hh" +#include "project.hh" +#include "vocab.hh" +#include "work.hh" +#include "ssh_agent.hh" + +namespace Botan +{ + class PK_Signer; + class RSA_PrivateKey; + class PK_Verifier; + class RSA_PublicKey; +}; + +// This class is supposed to hold all (or.. well, most) of the state +// of the application, barring some unfortunate static objects like +// the debugging / logging system and the command objects, for the +// time being. The vague intent being to make life easier for anyone +// who wants to embed this program as a library someday. + +class app_state +{ +public: + database db; + lua_hooks lua; + key_store keys; + workspace work; + ssh_agent agent; + + options opts; + + bool found_workspace; + bool branch_is_sticky; + + // These are used to cache signers/verifiers (if the hook allows). + // They can't be function-static variables in key.cc, since they + // must be destroyed before the Botan deinitialize() function is + // called. + + std::map, + boost::shared_ptr > > signers; + std::map, + boost::shared_ptr > > verifiers; + + void allow_workspace(); + void process_options(); + void require_workspace(std::string const & explanation = ""); + void create_workspace(system_path const & dir); + + // Set the branch name. If you only invoke set_branch, the branch + // name is not sticky (and won't be written to the workspace and + // reused by subsequent monotone invocations). Commands which + // switch the working to a different branch should invoke + // switch the working to a different branch should invoke + // make_branch_sticky (before require_workspace because this + // function updates the workspace). + +private: + project_t project; +public: + //project_t & get_project(string const & name); + project_t & get_project(); // get_project(opts.project) or I() + + void set_database(system_path const & filename); + void set_key_dir(system_path const & filename); + void set_root(system_path const & root); + void set_diff_format(diff_type dtype); + + explicit app_state(); + ~app_state(); + +private: + void load_rcfiles(); + void write_options(); +}; + +// Local Variables: +// mode: C++ +// fill-column: 76 +// c-file-style: "gnu" +// indent-tabs-mode: nil +// End: +// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: + +#endif // __APP_STATE_HH__ ============================================================ --- diff_patch.cc 5437f74550a59622f0aca36b00dd43f104b7692a +++ diff_patch.cc 827f8dbf2c922582e983b2207f7cf2abd45e7d4b @@ -1012,6 +1012,10 @@ void unidiff_hunk_writer::advance_to(siz } else { + // This affects the very first hunk, maybe: trim off excess context + if (a_begin == 0 && newpos - a_begin > ctx) + a_begin = newpos - ctx; + // pad intermediate context while(a_begin + a_len < newpos) {