[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-devel] udiff with changes close to bof (was Re: Something wron
From: |
Bruce Stephens |
Subject: |
[Monotone-devel] udiff with changes close to bof (was Re: Something wrong with mtn diff, with changes close to beginning of file?) |
Date: |
Sun, 29 Apr 2007 19:33:34 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.95 (gnu/linux) |
OK, I think I understand this a little better.
unidiff_hunk_writer::advance_to() gets called on an empty hunk with 5
(say), and just sticks all the lines on the hunk.
So a correct adjustment is just to catch that case.
(It ought to be unnecessary: I don't see why patch complains about
this.)
I attach the working code and a new test that fails with the existing
code, and passes with the change. (The change also doesn't break any
of the rest of the testsuite.)
#
# old_revision [2ab83f15fbea5442b10bb1a28479f016d91374fa]
#
# add_dir "tests/calculation_of_unidiffs_start_of_file"
#
# add_file "tests/calculation_of_unidiffs_start_of_file/__driver__.lua"
# content [19893c743f1f4a7b948d78db8dd36fccfabc784e]
#
# add_file "tests/calculation_of_unidiffs_start_of_file/firstfile"
# content [4abd1dd737c242fb6007ed4316c57e881ef9c90d]
#
# add_file "tests/calculation_of_unidiffs_start_of_file/secondfile"
# content [067d4428270226627bfd2c7820799fa4495ac4b8]
#
# patch "diff_patch.cc"
# from [5437f74550a59622f0aca36b00dd43f104b7692a]
# to [9956f89495727a934dcb968e746f76dc66f06c08]
#
============================================================
--- tests/calculation_of_unidiffs_start_of_file/__driver__.lua
19893c743f1f4a7b948d78db8dd36fccfabc784e
+++ tests/calculation_of_unidiffs_start_of_file/__driver__.lua
19893c743f1f4a7b948d78db8dd36fccfabc784e
@@ -0,0 +1,27 @@
+
+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
4abd1dd737c242fb6007ed4316c57e881ef9c90d
+++ tests/calculation_of_unidiffs_start_of_file/firstfile
4abd1dd737c242fb6007ed4316c57e881ef9c90d
@@ -0,0 +1,37 @@
+#ifndef __APP_STATE_HH__
+#define __APP_STATE_HH__
+
+// Copyright (C) 2002 Graydon Hoare <address@hidden>
+//
+// 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 <map>
+#include <vector>
+
+#include <boost/shared_ptr.hpp>
+
+#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;
+};
============================================================
--- tests/calculation_of_unidiffs_start_of_file/secondfile
067d4428270226627bfd2c7820799fa4495ac4b8
+++ tests/calculation_of_unidiffs_start_of_file/secondfile
067d4428270226627bfd2c7820799fa4495ac4b8
@@ -0,0 +1,38 @@
+#ifndef __APP_STATE_HH__
+#define __APP_STATE_HH__
+
+// Copyright (C) 2002 Graydon Hoare <address@hidden>
+//
+// 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 <map>
+#include <vector>
+
+#include <boost/shared_ptr.hpp>
+
+#include "database.hh"
+#include "key_store.hh"
+#include "lua_hooks.hh"
+#include "paths.hh"
+#include "project.hh"
+#include "vocab.hh"
+#include "work.hh"
+#include "ssh_agent.hh"
+#include "options.hh"
+
+namespace Botan
+{
+ class PK_Signer;
+ class RSA_PrivateKey;
+ class PK_Verifier;
+ class RSA_PublicKey;
+};
============================================================
--- diff_patch.cc 5437f74550a59622f0aca36b00dd43f104b7692a
+++ diff_patch.cc 9956f89495727a934dcb968e746f76dc66f06c08
@@ -1012,6 +1012,12 @@ void unidiff_hunk_writer::advance_to(siz
}
else
{
+ // At the beginning of a hunk, use at most ctx lines of leading
+ // context (GNU patch appears to prefer this)
+ if (hunk.empty())
+ if (newpos - (a_begin + a_len) > ctx)
+ a_begin = newpos - ctx - a_len;
+
// pad intermediate context
while(a_begin + a_len < newpos)
{